From 8e219e2505b8fc6d244965efc68c3adc58839919 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Tue, 4 Feb 2020 07:58:13 +0100 Subject: [PATCH] Preprocess known 3rd party mapping before usage Fixes #10 --- src/flake8_requirements/checker.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/flake8_requirements/checker.py b/src/flake8_requirements/checker.py index 9d533f6..ba4a66c 100644 --- a/src/flake8_requirements/checker.py +++ b/src/flake8_requirements/checker.py @@ -276,10 +276,16 @@ class Flake8Checker(object): name = "flake8-requirements" version = __version__ + # Build-in mapping for known 3rd party modules. + known_3rd_parties = { + project2module(k): v + for k, v in KNOWN_3RD_PARTIES.items() + } + # User defined project->modules mapping. known_modules = {} - # max depth to resolve recursive requirements + # Max depth to resolve recursive requirements. requirements_max_depth = 1 def __init__(self, tree, filename, lines=None): @@ -446,8 +452,8 @@ def get_mods_3rd_party(self): # Get 3rd party module names based on requirements. for requirement in self.get_mods_3rd_party_requirements(): modules = [project2module(requirement.project_name)] - if modules[0] in KNOWN_3RD_PARTIES: - modules = KNOWN_3RD_PARTIES[modules[0]] + if modules[0] in self.known_3rd_parties: + modules = self.known_3rd_parties[modules[0]] if modules[0] in self.known_modules: modules = self.known_modules[modules[0]] mods_3rd_party.update(modsplit(x) for x in modules)