Created
July 2, 2015 00:16
-
-
Save rgant/fbab5fe9d6e877d4c68e to your computer and use it in GitHub Desktop.
Shim Replacement for Python and Virtualenvs
This file contains hidden or 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 | |
# This is called when SublimeLinter initalizes the pylint linter: | |
#/Users/rgant/bin/python /Users/rgant/bin/pylint --version | |
# And this is called when linting a python file: | |
#/Users/rgant/bin/python /Users/rgant/bin/pylint --msg-template='{line}:{column}:{msg_id}: {msg}' \ | |
# --module-rgx=.* --reports=n --persistent=n /Users/rgant/projectname/api/models/item.py | |
# Assuming that all of my virtualenvs are located at /Users/rgant/projectname/venv | |
# This this is the version check, just get out of here. | |
if [ "$2" == "--version" ]; then | |
echo "pylint 99.99.99," | |
exit 0; | |
fi; | |
# Location of this script | |
MY_PATH=$(dirname "$0"); | |
PARENT=$(dirname "${MY_PATH}"); | |
# All of the arguments passed to this script | |
CMD="$*"; | |
# Get the path to the root of the project assuming it is relative to the path to this script. | |
FILE_PATH=$(expr "$CMD" : ".*\(${PARENT}/[^/]*\)"); | |
# Assume that the virtualenv folder is here at the root of the project | |
VENV_BIN="${FILE_PATH}/venv/bin"; | |
# Change the first instance of the path, AKA the one to pylint, to a virtualenv path. | |
FIXED_CMD="${CMD/$MY_PATH/$VENV_BIN}"; | |
eval "${FIXED_CMD}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment