-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: Parse multiple requirements from a poetry dependency #4179
Changes from all commits
c4f64a0
ea1c9de
0ab9fd4
0043c93
5dd5c83
3e38e1a
d6e740e
69e9e86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,28 +43,38 @@ def pyproject_dependencies | |
|
||
deps_hash.each do |name, req| | ||
next if normalise(name) == "python" | ||
next if req.is_a?(Hash) && UNSUPPORTED_DEPENDENCY_TYPES.any? { |t| req.key?(t) } | ||
|
||
check_requirements(req) | ||
|
||
dependencies << | ||
Dependency.new( | ||
name: normalise(name), | ||
version: version_from_lockfile(name), | ||
requirements: [{ | ||
requirement: req.is_a?(String) ? req : req["version"], | ||
file: pyproject.name, | ||
source: nil, | ||
groups: [type] | ||
}], | ||
package_manager: "pip" | ||
) | ||
|
||
requirements = parse_requirements_from(req, type) | ||
next if requirements.empty? | ||
|
||
dependencies << Dependency.new( | ||
name: normalise(name), | ||
version: version_from_lockfile(name), | ||
requirements: requirements, | ||
package_manager: "pip" | ||
) | ||
end | ||
end | ||
|
||
dependencies | ||
end | ||
|
||
# @param req can be an Array, Hash or String that represents the constraints for a dependency | ||
def parse_requirements_from(req, type) | ||
[req].flatten.compact.map do |requirement| | ||
next if requirement.is_a?(Hash) && (UNSUPPORTED_DEPENDENCY_TYPES & requirement.keys).any? | ||
|
||
check_requirements(requirement) | ||
|
||
{ | ||
requirement: requirement.is_a?(String) ? requirement : requirement["version"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly paranoid that we might get something that's not a String but also does not respond to Totally fine to keep as is, just thinking out loud here, but I found the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is a valid concern. Matching on type signature feels icky to me. I feel like there's a missing abstraction/interface here but I'm not sure what that is.
I'm not against this idea. I worked on this issue during my on-call shift last week so I've lost some of the context due to mo's limited memory but I can circle back to this. I think I would prefer to ship this small change as is because there were some jobs failing with this issue so this would at least unblock those. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍 |
||
file: pyproject.name, | ||
source: nil, | ||
groups: [type] | ||
} | ||
end.compact | ||
end | ||
|
||
# Create a DependencySet where each element has no requirement. Any | ||
# requirements will be added when combining the DependencySet with | ||
# other DependencySets. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[tool.poetry] | ||
name = "example" | ||
version = "0.1.0" | ||
description = "" | ||
authors = [] | ||
|
||
[tool.poetry.dependencies] | ||
numpy = [ | ||
{ version = "^1.19", python = "^3.6,<3.7" }, | ||
{ version = "^1.20", python = "^3.7" }] | ||
scipy = [ | ||
{ version = "^1.5", python = "^3.6,<3.7" }, | ||
{ version = "^1.6.0", python = "^3.7" } | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double-checking, this is functionally the same as
next if req.is_a?(Hash) && UNSUPPORTED_DEPENDENCY_TYPES.any? { |t| req.key?(t) }
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. It's a set intersect operation.