Skip to content

Commit

Permalink
Fix compatibility with poetry 1.5+
Browse files Browse the repository at this point in the history
Poetry 1.5 no longer provides category info in poetry.lock.

Fixes: thoth-station#280
  • Loading branch information
frenzymadness committed Aug 14, 2023
1 parent 591a71f commit d06c134
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 7 deletions.
23 changes: 16 additions & 7 deletions micropipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,20 @@ def _poetry2pipfile_lock(

for entry in poetry_lock["package"]:

if entry["category"] not in ("dev", "main"):
entry_category = entry.get("category")

# Poetry 1.5+ no longer provides category in poetry.lock so we have to
# guess it from the content of pyproject.toml.
# All deps in groups are considered dev dependencies.
if entry_category is None:
if entry["name"] in pyproject_poetry_section.get("dependencies", ()):
entry_category = "main"
else:
entry_category = "dev"

if entry_category not in ("dev", "main"):
message = ("Unknown category for package '{}': '{}'. Supported categories are 'dev' and 'main'.").format(
entry["name"], entry["category"]
entry["name"], entry_category
)
raise PoetryError(message)

Expand Down Expand Up @@ -879,7 +890,7 @@ def _poetry2pipfile_lock(
# So, if a package is in dev and has a dependency in main, add the dependency also to dev or
# if a package is already in "add_to_dev", add there also all its dependencies.
if (
entry["category"] == "dev" and dependency_name in pyproject_poetry_section.get("dependencies", ())
entry_category == "dev" and dependency_name in pyproject_poetry_section.get("dependencies", ())
) or entry["name"] in add_to_dev:
add_to_dev.append(dependency_name)

Expand All @@ -896,12 +907,10 @@ def _poetry2pipfile_lock(
if "extras" in requirement:
requirement["extras"] = sorted(requirement["extras"])

if entry["category"] == "main" and not no_default:
if entry_category == "main" and not no_default:
default[entry["name"]] = requirement

if (entry["category"] == "dev" and not no_dev) or (
entry["name"] in add_to_dev and entry["name"] not in default
):
if (entry_category == "dev" and not no_dev) or (entry["name"] in add_to_dev and entry["name"] not in default):
develop[entry["name"]] = requirement

for dependency_name, markers in additional_markers.items():
Expand Down
44 changes: 44 additions & 0 deletions tests/data/parse/poetry_1_5/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests/data/parse/poetry_1_5/Pipfile_no_default.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"_meta": {
"hash": {
"sha256": "d3213b26a683ac3ef9b891ad700f40a2e768a20e637e6bb1e8b7cd858903102f"
},
"pipfile-spec": 6,
"sources": [
{
"url": "https://pypi.org/simple",
"name": "5a06749b2297be54ac5699f6f2761716adc5001a2d5f8b915ab2172922dd5706",
"verify_ssl": true
}
],
"requires": {
"python_version": "3.11"
}
},
"default": {},
"develop": {
"flexmock": {
"version": "==0.10.10",
"hashes": [
"sha256:8bb073f4b7b590672e8c312e73d6a14f88ae624a867b691462f9e8c24b9f19d1"
],
"index": "5a06749b2297be54ac5699f6f2761716adc5001a2d5f8b915ab2172922dd5706"
},
"python-json-logger": {
"version": "==0.1.11",
"hashes": [
"sha256:b7a31162f2a01965a5efb94453ce69230ed208468b0bbc7fdfc56e6d8df2e281"
],
"index": "5a06749b2297be54ac5699f6f2761716adc5001a2d5f8b915ab2172922dd5706"
}
}
}
29 changes: 29 additions & 0 deletions tests/data/parse/poetry_1_5/Pipfile_no_dev.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"_meta": {
"hash": {
"sha256": "d3213b26a683ac3ef9b891ad700f40a2e768a20e637e6bb1e8b7cd858903102f"
},
"pipfile-spec": 6,
"sources": [
{
"url": "https://pypi.org/simple",
"name": "5a06749b2297be54ac5699f6f2761716adc5001a2d5f8b915ab2172922dd5706",
"verify_ssl": true
}
],
"requires": {
"python_version": "3.11"
}
},
"default": {
"daiquiri": {
"version": "==2.0.0",
"hashes": [
"sha256:d57b9fd5432933c6e899054eb62cee22eab89f560c8493254d327ec27893c866",
"sha256:6b235ed15b73b87fd3cc2521aacbb727bf8443a0896dc534b07503841d03cfdb"
],
"index": "5a06749b2297be54ac5699f6f2761716adc5001a2d5f8b915ab2172922dd5706"
}
},
"develop": {}
}
44 changes: 44 additions & 0 deletions tests/data/parse/poetry_1_5/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/data/parse/poetry_1_5/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "aaa"
version = "0.1.0"
description = ""
authors = ["Fridolin Pokorny <[email protected]>"]

[tool.poetry.dependencies]
daiquiri = "2.0.0"

[tool.poetry.group.test.dependencies]
flexmock = "^0.10.4"

[build-system]
requires = ["poetry>=1.5.0"]
build-backend = "poetry.masonry.api"
1 change: 1 addition & 0 deletions tests/test_micropipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ def test_parse_requirements2pipfile_lock_not_locked():
"directory",
(
"poetry",
"poetry_1_5",
"poetry_default_dev_diff",
"poetry_default_source_legacy",
"poetry_legacy_source_and_groups",
Expand Down

0 comments on commit d06c134

Please sign in to comment.