Skip to content

Instantly share code, notes, and snippets.

@brandones
Created May 9, 2017 23:04
Show Gist options
  • Save brandones/f86f2d511033c7f4ea55a917a7ae031d to your computer and use it in GitHub Desktop.
Save brandones/f86f2d511033c7f4ea55a917a7ae031d to your computer and use it in GitHub Desktop.
Run pylint using first virtualenv named 'env' in a parent directory
#!/usr/bin/python
#
# Placed at /usr/local/bin/python
# Expects pylint executable at /usr/bin/pylint
#
import os
import sys
def get_python_exec():
if len(sys.argv) < 2:
return ""
filepath = sys.argv[1]
dirname = os.path.realpath(os.path.expanduser(filepath))
if not os.path.isdir(dirname):
dirname = os.path.dirname(dirname)
while True:
env_path = os.path.join(dirname, "env", "bin", "python")
if os.path.exists(env_path):
return env_path
old_dirname = dirname
dirname = os.path.dirname(dirname)
if old_dirname == dirname:
return ""
os.system(get_python_exec() + ' /usr/bin/pylint ' + ' '.join(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment