-
-
Save tysm/249c43935b424536d267605f8662b37e to your computer and use it in GitHub Desktop.
A simple project path to PYTHONPATH exporter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SCRIPT_PATH="${BASH_SOURCE[0]#./}" | |
if [[ ! ${0#./} != $SCRIPT_PATH ]]; then | |
echo "You cannot run it directly. This file must be sourced *from bash*: source $SCRIPT_PATH PYTHON" | |
exit 1 | |
fi | |
PROJECT_PATH="$(cd "$(dirname "$SCRIPT_PATH")"/.. && pwd)" | |
if [[ -z $PYTHONPATH ]]; then | |
export PYTHONPATH="$PROJECT_PATH" | |
elif [[ ! $PYTHONPATH =~ (^|:)$PROJECT_PATH(:|$) ]]; then | |
export PYTHONPATH="$PYTHONPATH:$PROJECT_PATH" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment