From 368d0b190ae563b668f3e16c447f5b555a6602a1 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Mon, 14 Mar 2022 21:11:30 +0100 Subject: [PATCH] Fix requirement parsing for local dir with extras Fixes #47 --- LICENSE.txt | 2 +- src/flake8_requirements/checker.py | 10 +++++++++- test/test_requirements.txt | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 8c49e7c..7869d6c 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2017-2021 Arkadiusz Bokowy +Copyright (c) 2017-2022 Arkadiusz Bokowy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/flake8_requirements/checker.py b/src/flake8_requirements/checker.py index 881e4c4..3c40ece 100644 --- a/src/flake8_requirements/checker.py +++ b/src/flake8_requirements/checker.py @@ -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') @@ -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 @@ -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) diff --git a/test/test_requirements.txt b/test/test_requirements.txt index 6258a55..07e5fba 100644 --- a/test/test_requirements.txt +++ b/test/test_requirements.txt @@ -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 .