diff options
author | tmarek <tmarek@google.com> | 2012-11-07 11:25:15 +0100 |
---|---|---|
committer | tmarek <tmarek@google.com> | 2012-11-07 11:25:15 +0100 |
commit | 6214805cb19dae4fee64fcda1435ac5a441fc24f (patch) | |
tree | 06c5d26d2236a0a9c68694f97bf9f7a002263e2c /lint.py | |
parent | 02ef6bb39eba069d585654f30f6196ca0a0863d8 (diff) | |
download | pylint-6214805cb19dae4fee64fcda1435ac5a441fc24f.tar.gz |
Add hooks for import path setup and move pylint's sys.path
modifications into them. These hooks can be overridden by other implementations.
Diffstat (limited to 'lint.py')
-rw-r--r-- | lint.py | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -330,6 +330,17 @@ This is used by the global evaluation report (RP0004).'}), from pylint import checkers checkers.initialize(self) + def prepare_import_path(self, args): + """Prepare sys.path for running the linter checks.""" + if len(args) == 1: + sys.path.insert(0, _get_python_path(args[0])) + else: + sys.path.insert(0, os.getcwd()) + + def cleanup_import_path(self): + """Revert any changes made to sys.path in prepare_import_path.""" + sys.path.pop(0) + def load_plugin_modules(self, modnames): """take a list of module names which are pylint plugins and load and register them @@ -965,10 +976,7 @@ are done by default'''}), sys.exit(32) # insert current working directory to the python path to have a correct # behaviour - if len(args) == 1: - sys.path.insert(0, _get_python_path(args[0])) - else: - sys.path.insert(0, os.getcwd()) + linter.prepare_import_path(args) if self.linter.config.profile: print >> sys.stderr, '** profiled run' import cProfile, pstats @@ -979,7 +987,7 @@ are done by default'''}), data.print_stats(30) else: linter.check(args) - sys.path.pop(0) + linter.cleanup_import_path() if exit: sys.exit(self.linter.msg_status) |