Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.7.4: Add support for Poetry 1.2.0+'s dependency groups #584

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/bibliothecary/parsers/pypi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ def self.parse_pyproject(file_contents, options: {})
# Parse poetry [tool.poetry] deps
poetry_manifest = file_contents.fetch('tool', {}).fetch('poetry', {})
deps += map_dependencies(poetry_manifest['dependencies'], 'runtime')
# Poetry 1.0.0-1.2.0 way of defining dev deps
deps += map_dependencies(poetry_manifest['dev-dependencies'], 'develop')
# Poetry's 1.2.0+ of defining dev deps
poetry_manifest
.fetch("group", {})
.each_pair do |group_name, obj|
group_name = "develop" if group_name == "dev"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm familiar with toml and how these are getting parsed. What would the expected group names look like. From the Poetry example what would the group_name for [tool.poetry.group.test.dependencies] resolve to here?

Copy link
Contributor Author

@tiegz tiegz Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT it'll use the name that was parsed, so test would be the group there. The docs say:

use a tool.poetry.group. section where is the name of your dependency group (for instance, test):

There's an implicit main group that is the default, but we've apparently mapped that to runtime until now so I'm setting that as the default in the change below.

Also noteworthy is that anything that's not main is considered development semantically, so there's no real distinction between dev and test to Poetry other than the names:

Dependency groups, other than the implicit main group, must only contain dependencies you need in your development process. Installing them is only possible by using Poetry.

And FWIW, I'd prefer that Bibliothecary return "development" here to be consistent with the other parsers, but there are 3 uses of "develop" in this file so I'm hesitant to break anything for consumers of the gem : \

deps += map_dependencies(obj.fetch("dependencies", {}), group_name)
end

# Parse PEP621 [project] deps
pep621_manifest = file_contents.fetch('project', {})
Expand Down Expand Up @@ -179,10 +187,10 @@ def self.parse_poetry_lock(file_contents, options: {})
manifest["package"].each do |package|
# next if group == "_meta"
group = case package['category']
when 'main'
'runtime'
when 'dev'
'develop'
else
'runtime'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ensures that pypoetry.lock should not get a type: nil back

end

deps << {
Expand Down
2 changes: 1 addition & 1 deletion lib/bibliothecary/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bibliothecary
VERSION = "8.7.3"
VERSION = "8.7.4"
end
8 changes: 8 additions & 0 deletions spec/fixtures/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ authors = ["Tyrel Souza <tyrel@tidelift.com>"]
python = "^3.7"
django = "^3.0.7"

# Old way to define development deps (<1.2.0)
[tool.poetry.dev-dependencies]
pytest = "^5.2"

# New way to define development deps (>=1.2.0)
[tool.poetry.group.dev.dependencies]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add another group here and test that the type works correctly. Something like [tool.poetry.group.test.dependencies].

wcwidth = "*"

[tool.poetry.group.test.dependencies]
sqlparse = "0.3.1"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
4 changes: 3 additions & 1 deletion spec/parsers/pypi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@
dependencies: [
{ name: "python", requirement: "^3.7", type: "runtime" },
{ name: "django", requirement: "^3.0.7", type: "runtime" },
{ name: "pytest", requirement: "^5.2", type: "develop" }
{ name: "pytest", requirement: "^5.2", type: "develop" },
{ name: "wcwidth", requirement: "*", type: "develop" },
{ name: "sqlparse", requirement: "0.3.1", type: "test" },
],
kind: 'manifest',
success: true
Expand Down