From 59ff32565008ef712ec7d8f4b51a2b2a98ef1268 Mon Sep 17 00:00:00 2001 From: Nick Presta Date: Wed, 7 Nov 2018 16:09:56 -0500 Subject: [PATCH] Ensure optional dev-depends are written to extras. * Ensures that all requirements, whether from dependencies or dev-dependencies for extra targets are written to the lockfile. * Fixes #426 --- poetry/poetry.py | 2 +- .../project_with_extras/pyproject.toml | 2 ++ tests/test_poetry.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/poetry/poetry.py b/poetry/poetry.py index 407bfccf42c..b76d3f1c6a6 100644 --- a/poetry/poetry.py +++ b/poetry/poetry.py @@ -163,7 +163,7 @@ def create(cls, cwd): # type: (Path) -> Poetry for req in requirements: req = Dependency(req, "*") - for dep in package.requires: + for dep in package.all_requires: if dep.name == req.name: dep.in_extras.append(extra_name) package.extras[extra_name].append(dep) diff --git a/tests/fixtures/project_with_extras/pyproject.toml b/tests/fixtures/project_with_extras/pyproject.toml index e2ad7619069..c555223b105 100644 --- a/tests/fixtures/project_with_extras/pyproject.toml +++ b/tests/fixtures/project_with_extras/pyproject.toml @@ -13,5 +13,7 @@ cachy = { version = ">=0.2.0", optional = true } [tool.poetry.extras] extras_a = [ "pendulum" ] extras_b = [ "cachy" ] +extras_c = [ "black" ] [tool.poetry.dev-dependencies] +black = { version = "18.9b0", optional = true } diff --git a/tests/test_poetry.py b/tests/test_poetry.py index 8d92ee37370..1deb877ba6e 100644 --- a/tests/test_poetry.py +++ b/tests/test_poetry.py @@ -156,3 +156,21 @@ def test_check_fails(): ) assert Poetry.check(content) == {"errors": [expected], "warnings": []} + + +def test_poetry_writes_extras_from_dev_dependencies(): + poetry = Poetry.create(str(fixtures_dir / "project_with_extras")) + + package = poetry.package + + dev_dependencies = {} + for dep in package.dev_requires: + dev_dependencies[dep.name] = dep + + black = dev_dependencies["black"] + assert black.is_optional() + + assert "extras_c" in package.extras + extras_c = package.extras["extras_c"] + assert len(extras_c) == 1 + assert extras_c[0].name == "black"