Injects the current sys.path into lint.py subprocess env

This allows installing pylint in a buildout setup and *see* the eggs in the
buildout.  Since buildout modifies the installed scripts (like epyling) by
prepending and assignment to ``sys.path[0:0]`` all the eggs, we need to make
sure those path are the ones seen by pylint.
This commit is contained in:
Manuel Vázquez Acosta 2014-01-06 15:31:19 -05:00
parent 6560940f32
commit 2da336b446

View File

@ -83,7 +83,18 @@ def lint(filename, options=None):
options = options or ['--disable=C,R,I']
cmd = [sys.executable, lint_path] + options + ['--msg-template',
'{path}:{line}: [{symbol}, {obj}] {msg}', '-r', 'n', child_path]
process = Popen(cmd, stdout=PIPE, cwd=parent_path, universal_newlines=True)
# Extracts the environment PYTHONPATH and appends the current sys.path to
# those.
env = dict(os.environ)
pythonpath = env.get('PYTHONPATH', '')
currentpaths = os.pathsep.join(sys.path)
if pythonpath:
pythonpath += os.pathsep + currentpaths
else:
pythonpath = currentpaths
env['PYTHONPATH'] = pythonpath
process = Popen(cmd, stdout=PIPE, cwd=parent_path, env=env,
universal_newlines=True)
# The parseable line format is '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s'
# NOTE: This would be cleaner if we added an Emacs reporter to pylint.reporters.text ..
@ -157,9 +168,20 @@ def py_run(command_options='', return_std=False, stdout=None, stderr=None,
stderr = PIPE
else:
stderr = sys.stderr
# Extracts the environment PYTHONPATH and appends the current sys.path to
# those.
env = dict(os.environ)
pythonpath = env.get('PYTHONPATH', '')
currentpaths = os.pathsep.join(sys.path)
if pythonpath:
pythonpath += os.pathsep + currentpaths
else:
pythonpath = currentpaths
env['PYTHONPATH'] = pythonpath
# Call pylint in a subprocess
p = Popen(command_line, shell=True, stdout=stdout, stderr=stderr,
universal_newlines=True)
env=env, universal_newlines=True)
p.wait()
# Return standart output and error
if return_std:
@ -179,4 +201,3 @@ def Run():
if __name__ == '__main__':
Run()