From bedd1a31ce6434141b3e1cfe4ca824da188cce88 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Mon, 5 Apr 2021 21:10:00 +0200 Subject: [PATCH] Handle requirement local path in editable mode Fixes #36 --- src/flake8_requirements/checker.py | 12 +++++++++++- test/test_requirements.py | 1 + test/test_requirements.txt | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/flake8_requirements/checker.py b/src/flake8_requirements/checker.py index 8519b14..901244f 100644 --- a/src/flake8_requirements/checker.py +++ b/src/flake8_requirements/checker.py @@ -445,7 +445,9 @@ def resolve_requirement(cls, requirement, max_depth=0, path=None): option = option_match.group(1) requirement = option_match.group(2).lstrip() + editable = False if option in ("-e", "--editable"): + editable = True # We do not care about installation mode. option = None @@ -466,7 +468,7 @@ def resolve_requirement(cls, requirement, max_depth=0, path=None): # Skip whole line if option was not processed earlier. return [] - # Check for a requirement given as a VSC link. + # Check for a requirement given as a VCS link. vcs_match = cls._requirement_match_vcs(requirement) vcs_spec_match = cls._requirement_match_vcs_spec( vcs_match.group(2) if vcs_match is not None else "") @@ -485,6 +487,14 @@ def resolve_requirement(cls, requirement, max_depth=0, path=None): "{} == {}".format(name, version[1:]) ] + # Editable installation is made either from local path or from VCS + # URL. In case of VCS, the URL should be already handled in the if + # block above. Here we shall get a local project path. + if editable: + requirement = os.path.basename(requirement) + if requirement.split()[0] == ".": + requirement = "" + # Extract requirement specifier (skip in-line options). spec_match = cls._requirement_match_spec(requirement) if spec_match is not None: diff --git a/test/test_requirements.py b/test/test_requirements.py index 013c943..99a3094 100644 --- a/test/test_requirements.py +++ b/test/test_requirements.py @@ -223,5 +223,6 @@ def test_init_misc(self): "exPackage_paint == 1.4.8.dev1984+49a8814", "package-one", "package-two", + "whiteBox", ])), ) diff --git a/test/test_requirements.txt b/test/test_requirements.txt index 3de30a8..6258a55 100644 --- a/test/test_requirements.txt +++ b/test/test_requirements.txt @@ -25,3 +25,9 @@ http://example.com/snapshot-builds/exPackage_paint-1.4.8.dev1984+49a8814-cp34-no ###### Requirements from a VCS ###### git+git://github.com/path/to/package-one@releases/tag/v3.1.4#egg=package-one git+git://github.com/path/to/package-two@master#egg=package-two&subdirectory=src + +###### Install local project in a develop mode ###### +--editable /opt/whiteBox # Local proprietary package + +###### Install THIS project in a develop mode ###### +--editable .