summaryrefslogtreecommitdiff
path: root/flake8/engine.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2015-09-27 14:11:17 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2015-09-27 14:11:17 -0500
commit0c0eadc0a042f12c43cb17ede5367b66335dbbc3 (patch)
tree22dd1f86823802ee0bdfc121b06326dea7ce0507 /flake8/engine.py
parentb8457ebb24c9a71a63fec5ac28501995ba8134bb (diff)
downloadflake8-bug/90.tar.gz
Add better logic for loading entry pointsbug/90
As noted in the code, setuptools 11.3 deprecated EntryPoint.load and its require parameter. Starting with 11.3 the preferred way is use EntryPoint.require and EntryPoint.resolve as necessary. Unfortunately, those methods do not exist in all versions of setuptools. So we have to check for them and use them when they're available. Otherwise, we fallback to using EntryPoint.load with the require parameter. Closes #59 Closes #90
Diffstat (limited to 'flake8/engine.py')
-rw-r--r--flake8/engine.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/flake8/engine.py b/flake8/engine.py
index 0f440c1..6587667 100644
--- a/flake8/engine.py
+++ b/flake8/engine.py
@@ -17,6 +17,26 @@ _flake8_noqa = re.compile(r'\s*# flake8[:=]\s*noqa', re.I).search
EXTRA_EXCLUDE = ['.tox', '.eggs', '*.egg']
+def _load_entry_point(entry_point, verify_requirements):
+ """Based on the version of setuptools load an entry-point correctly.
+
+ setuptools 11.3 deprecated `require=False` in the call to EntryPoint.load.
+ To load entry points correctly after that without requiring all
+ dependencies be present, the proper way is to call EntryPoint.resolve.
+
+ This function will provide backwards compatibility for older versions of
+ setuptools while also ensuring we do the right thing for the future.
+ """
+ if hasattr(entry_point, 'resolve') and hasattr(entry_point, 'require'):
+ if verify_requirements:
+ entry_point.require()
+ plugin = entry_point.resolve()
+ else:
+ plugin = entry_point.load(require=verify_requirements)
+
+ return plugin
+
+
def _register_extensions():
"""Register all the extensions."""
extensions = util.OrderedSet()
@@ -31,7 +51,7 @@ def _register_extensions():
else:
for entry in iter_entry_points('flake8.extension'):
# Do not verify that the requirements versions are valid
- checker = entry.load(require=False)
+ checker = _load_entry_point(entry, verify_requirements=False)
pep8.register_check(checker, codes=[entry.name])
extensions.add((checker.name, checker.version))
if hasattr(checker, 'add_options'):