diff options
author | Manuel V?zquez Acosta <mva.led@gmail.com> | 2014-01-06 16:07:33 -0500 |
---|---|---|
committer | Manuel V?zquez Acosta <mva.led@gmail.com> | 2014-01-06 16:07:33 -0500 |
commit | 6e843239561b38b2bcbe4f5390a08d020cf10b13 (patch) | |
tree | cfcae1548e0f53f01b82adcb19531b914fc1f53c /epylint.py | |
parent | 507d900bf09f718907cfafb0c7703a777b7f79c2 (diff) | |
download | pylint-6e843239561b38b2bcbe4f5390a08d020cf10b13.tar.gz |
Refactors the PYTHONPATH detector into a function
Diffstat (limited to 'epylint.py')
-rwxr-xr-x | epylint.py | 37 |
1 files changed, 14 insertions, 23 deletions
@@ -50,6 +50,18 @@ import sys, os, re import os.path as osp from subprocess import Popen, PIPE +def _get_env(): + '''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 + return env def lint(filename, options=None): """Pylint the given file. @@ -83,17 +95,7 @@ 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] - # 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, + process = Popen(cmd, stdout=PIPE, cwd=parent_path, env=_get_env(), universal_newlines=True) # The parseable line format is '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s' @@ -168,20 +170,9 @@ 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, - env=env, universal_newlines=True) + env=_get_env(), universal_newlines=True) p.wait() # Return standart output and error if return_std: |