Skip to content

Commit

Permalink
Ensure optional dev-depends are written to extras.
Browse files Browse the repository at this point in the history
* Ensures that all requirements, whether from dependencies or
  dev-dependencies for extra targets are written to the lockfile.
* Fixes python-poetry#426
  • Loading branch information
nickpresta committed Nov 7, 2018
1 parent 62fc038 commit 3599cff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/project_with_extras/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
21 changes: 19 additions & 2 deletions tests/test_poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def test_poetry():
assert package.authors == ["Sébastien Eustace <[email protected]>"]
assert package.license.id == "MIT"
assert (
package.readme.relative_to(fixtures_dir).as_posix()
== "sample_project/README.rst"
package.readme.relative_to(fixtures_dir).as_posix() == "sample_project/README.rst"
)
assert package.homepage == "https://poetry.eustace.io"
assert package.repository_url == "https://github.com/sdispater/poetry"
Expand Down Expand Up @@ -156,3 +155,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"

0 comments on commit 3599cff

Please sign in to comment.