Skip to content

Commit

Permalink
Collect dependencies from Poetry groups
Browse files Browse the repository at this point in the history
Fixes arkq#55
  • Loading branch information
arkq authored Sep 4, 2022
1 parent 54c3f55 commit e7690eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 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.6.1"
__version__ = "1.6.2"
__license__ = "MIT"

LOG = getLogger('flake8.plugin.requirements')
Expand Down Expand Up @@ -566,6 +566,10 @@ def get_pyproject_toml_poetry_requirements(self):
poetry.get('dependencies', ())))
requirements.extend(parse_requirements(
poetry.get('dev-dependencies', ())))
# Collect dependencies from groups (since poetry-1.2).
for _, group in poetry.get('group', {}).items():
requirements.extend(parse_requirements(
group.get('dependencies', ())))
return requirements

@classmethod
Expand Down
15 changes: 15 additions & 0 deletions test/test_poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ def test_3rd_party(self):
checker = Flake8Checker(None, None)
mods = checker.get_mods_3rd_party()
self.assertEqual(mods, ModuleSet({"tools": {}, "dev_tools": {}}))

def test_3rd_party_groups(self):
content = "[tool.poetry.dependencies]\ntools='1.0'\n"
content += "[tool.poetry.group.dev.dependencies]\ndev-tools='1.0'\n"

with mock.patch(builtins_open, mock.mock_open()) as m:
m.side_effect = (
IOError("No such file or directory: 'setup.py'"),
IOError("No such file or directory: 'setup.cfg'"),
mock.mock_open(read_data=content).return_value,
)

checker = Flake8Checker(None, None)
mods = checker.get_mods_3rd_party()
self.assertEqual(mods, ModuleSet({"tools": {}, "dev_tools": {}}))

0 comments on commit e7690eb

Please sign in to comment.