Skip to content

Commit

Permalink
fix: Dependency Groups from Poetry do not migrate properly to PDM (#2311
Browse files Browse the repository at this point in the history
)
  • Loading branch information
frostming authored Oct 12, 2023
1 parent a551bde commit bb72bfb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/2285.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that dependency groups from Poetry 1.2+ do not migrate properly to PDM.
1 change: 1 addition & 0 deletions src/pdm/cli/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def do_update(
if not packages:
if prerelease:
raise PdmUsageError("--prerelease must be used with packages given")
selection.validate()
for group in selection:
updated_deps[group] = all_dependencies[group]
else:
Expand Down
14 changes: 11 additions & 3 deletions src/pdm/formats/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ def dependencies(self, source: dict[str, Any]) -> list[str]:

@convert_from("dev-dependencies")
def dev_dependencies(self, value: dict) -> None:
self.settings["dev-dependencies"] = {
"dev": make_array([r for key, req in value.items() for r in _convert_req(key, req)], True),
}
self.settings.setdefault("dev-dependencies", {})["dev"] = make_array(
[r for key, req in value.items() for r in _convert_req(key, req)], True
)
raise Unset()

@convert_from("group")
def group_dependencies(self, value: dict[str, dict[str, Any]]) -> None:
for name, group in value.items():
self.settings.setdefault("dev-dependencies", {})[name] = make_array(
[r for key, req in group.get("dependencies", {}).items() for r in _convert_req(key, req)], True
)
raise Unset()

@convert_from()
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/poetry-new.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "test-poetry"
version = "0.1.0"
description = ""
authors = ["Frost Ming <[email protected]>"]
readme = "README.md"
packages = [{include = "test_poetry"}]

[tool.poetry.dependencies]
python = "^3.8"
httpx = "*"
pendulum = "*"

[tool.poetry.group.test.dependencies]
pytest = "^6.0.0"
pytest-mock = "*"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
9 changes: 9 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def test_convert_poetry(project):
assert build["excludes"] == ["my_package/excluded.py"]


def test_convert_poetry_12(project):
golden_file = FIXTURES / "poetry-new.toml"
with cd(FIXTURES):
result, settings = poetry.convert(project, golden_file, Namespace(dev=False, group=None))

assert result["dependencies"] == ["httpx", "pendulum"]
assert settings["dev-dependencies"]["test"] == ["pytest<7.0.0,>=6.0.0", "pytest-mock"]


def test_convert_flit(project):
golden_file = FIXTURES / "projects/flit-demo/pyproject.toml"
assert flit.check_fingerprint(project, golden_file)
Expand Down

0 comments on commit bb72bfb

Please sign in to comment.