Skip to content

Commit

Permalink
Fix requirement parsing for local dir with extras
Browse files Browse the repository at this point in the history
Fixes #47
  • Loading branch information
arkq committed Mar 14, 2022
1 parent 084927b commit 368d0b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2017-2021 Arkadiusz Bokowy <[email protected]>
Copyright (c) 2017-2022 Arkadiusz Bokowy <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 9 additions & 1 deletion src/flake8_requirements/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .modules import STDLIB_PY3

# NOTE: Changing this number will alter package version as well.
__version__ = "1.5.2"
__version__ = "1.5.3"
__license__ = "MIT"

LOG = getLogger('flake8.plugin.requirements')
Expand Down Expand Up @@ -433,6 +433,9 @@ def discover_project_root_dir(cls):
_requirement_match_option = re.compile(
r"(-[\w-]+)(.*)").match

_requirement_match_extras = re.compile(
r"(.*?)\s*(\[[^]]+\])").match

_requirement_match_spec = re.compile(
r"(.*?)\s+--(global-option|install-option|hash)").match

Expand Down Expand Up @@ -509,6 +512,11 @@ def resolve_requirement(cls, requirement, max_depth=0, path=None):
requirement = os.path.basename(requirement)
if requirement.split()[0] == ".":
requirement = ""
# It seems that the parse_requirements() function does not like
# ".[foo,bar]" syntax (current directory with extras).
extras_match = cls._requirement_match_extras(requirement)
if extras_match is not None and extras_match.group(1) == ".":
requirement = ""

# Extract requirement specifier (skip in-line options).
spec_match = cls._requirement_match_spec(requirement)
Expand Down
1 change: 1 addition & 0 deletions test/test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ git+git://github.com/path/to/package-two@master#egg=package-two&subdirectory=src
--editable /opt/whiteBox # Local proprietary package

###### Install THIS project in a develop mode ######
--editable .[foo,bar]
--editable .

0 comments on commit 368d0b1

Please sign in to comment.