summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-24 10:55:51 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-24 10:55:51 +0200
commite8cb5a7a24e03c33b6aa6c473fd91eae7daf857d (patch)
tree7acf0e9446e72ff6973e1ad23297d4413b487fbc
parent1e2cbff36d75907b6d8a4c53af040511465793ea (diff)
downloadpylint-e8cb5a7a24e03c33b6aa6c473fd91eae7daf857d.tar.gz
Move the patching of sys.modules in a context manager.
-rw-r--r--pylint/lint.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/pylint/lint.py b/pylint/lint.py
index e10ae56..b0f7cc3 100644
--- a/pylint/lint.py
+++ b/pylint/lint.py
@@ -105,6 +105,24 @@ def _merge_stats(stats):
return merged
+@contextlib.contextmanager
+def _patch_sysmodules():
+ # Context manager that permits running pylint, on Windows, with -m switch
+ # and with --jobs, as in 'python -2 -m pylint .. --jobs'.
+ # For more details why this is needed,
+ # see Python issue http://bugs.python.org/issue10845.
+
+ mock_main = __name__ != '__main__' # -m switch
+ if mock_main:
+ sys.modules['__main__'] = sys.modules[__name__]
+
+ try:
+ yield
+ finally:
+ if mock_main:
+ sys.modules.pop('__main__')
+
+
# Python Linter class #########################################################
MSGS = {
@@ -673,19 +691,10 @@ class PyLinter(configuration.OptionsManagerMixIn,
if self.config.jobs == 1:
self._do_check(files_or_modules)
else:
- # Hack that permits running pylint, on Windows, with -m switch
- # and with --jobs, as in 'python -2 -m pylint .. --jobs'.
- # For more details why this is needed,
- # see Python issue http://bugs.python.org/issue10845.
-
- mock_main = __name__ != '__main__' # -m switch
- if mock_main:
- sys.modules['__main__'] = sys.modules[__name__]
- try:
+
+ with _patch_sysmodules():
self._parallel_check(files_or_modules)
- finally:
- if mock_main:
- sys.modules.pop('__main__')
+
def _parallel_task(self, files_or_modules):
# Prepare configuration for child linters.