Skip to content

Instantly share code, notes, and snippets.

@tysm
Created October 16, 2019 03:20
Show Gist options
  • Save tysm/249c43935b424536d267605f8662b37e to your computer and use it in GitHub Desktop.
Save tysm/249c43935b424536d267605f8662b37e to your computer and use it in GitHub Desktop.
A simple project path to PYTHONPATH exporter.
#!/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