From 2da336b446b6bf7410527c9a16531a0defb27845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=A1zquez=20Acosta?= Date: Mon, 6 Jan 2014 15:31:19 -0500 Subject: [PATCH] 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. --- epylint.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/epylint.py b/epylint.py index 24baa61e9..13449b2e4 100755 --- a/epylint.py +++ b/epylint.py @@ -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() -