-
Notifications
You must be signed in to change notification settings - Fork 36
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
pyproject.toml: support PEP621 projects too #568
Changes from 4 commits
e64592d
c70de85
b0f97af
827329e
315fce2
91b517a
bcaffbc
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 |
---|---|---|
|
@@ -14,6 +14,9 @@ class Pypi | |
MANIFEST_REGEXP = /.*require[^\/]*(\/)?[^\/]*\.(txt|pip|in)$/ | ||
PIP_COMPILE_REGEXP = /.*require.*$/ | ||
|
||
# Adapted from https://peps.python.org/pep-0508/#names | ||
PEP_508_NAME_REGEX = /^([A-Z0-9][A-Z0-9._-]*[A-Z0-9]|[A-Z0-9])/i | ||
|
||
def self.mapping | ||
{ | ||
match_filenames('requirements-dev.txt', 'requirements/dev.txt', | ||
|
@@ -56,7 +59,7 @@ def self.mapping | |
}, | ||
match_filename("pyproject.toml") => { | ||
kind: 'manifest', | ||
parser: :parse_poetry | ||
parser: :parse_pyproject | ||
}, | ||
match_filename("poetry.lock") => { | ||
kind: 'lockfile', | ||
|
@@ -90,9 +93,28 @@ def self.parse_pipfile(file_contents, options: {}) | |
map_dependencies(manifest['packages'], 'runtime') + map_dependencies(manifest['dev-packages'], 'develop') | ||
end | ||
|
||
def self.parse_pyproject(file_contents, options: {}) | ||
deps = [] | ||
|
||
file_contents = Tomlrb.parse(file_contents) | ||
|
||
# Parse poetry [tool.poetry] deps | ||
poetry_manifest = file_contents.fetch('tool', {}).fetch('poetry', {}) | ||
deps += map_dependencies(poetry_manifest['dependencies'], 'runtime') | ||
deps += map_dependencies(poetry_manifest['dev-dependencies'], 'develop') | ||
|
||
# Parse PEP621 [project] deps | ||
pep621_manifest = file_contents.fetch('project', {}) | ||
pep621_deps = pep621_manifest.fetch('dependencies', []).map { |d| parse_pep_508_dep_spec(d) } | ||
deps += map_dependencies(pep621_deps, 'runtime') | ||
Comment on lines
+101
to
+109
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. should these be mutually excluded or is it possible for a single manifest to specify both of these dependencies? 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. PEP621 is the "tool-agnostic" way to declare build system requirements in pyproject.toml, and from what I understand Poetry is the only build system that doesn't support it yet. They're discussing it tho, and it looks like one of the examples includes both the "tool.poetry" And "project" namespaces for declaring deps: python-poetry/roadmap#3 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. ah yeah, just found an example here. The deps are the same in both sections, but still seems safer to combine them both until we have a reason not to: https://sourcegraph.com/github.com/IceTiki/ruoli-sign-optimization/-/blob/pyproject.toml?subtree=true 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. In that case, does 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. ah yes! Good call, I think we do that higher up in |
||
|
||
deps | ||
end | ||
|
||
# TODO: this was deprecated in 8.5.2. Remove this in any major version bump >= 9.* | ||
mpace965 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def self.parse_poetry(file_contents, options: {}) | ||
manifest = Tomlrb.parse(file_contents).fetch('tool', {}).fetch('poetry', {}) | ||
map_dependencies(manifest['dependencies'], 'runtime') + map_dependencies(manifest['dev-dependencies'], 'develop') | ||
puts "Warning: parse_poetry() is deprecated, use parse_pyproject() instead." | ||
parse_pyproject(file_contents, options) | ||
end | ||
|
||
def self.parse_conda(file_contents, options: {}) | ||
|
@@ -252,6 +274,15 @@ def self.pip_compile?(file_contents) | |
# parsing after we match. | ||
false | ||
end | ||
|
||
# Simply parses out the name of a PEP 508 Dependency specification: https://peps.python.org/pep-0508/ | ||
# Leaves the rest as-is with any leading semicolons or spaces stripped | ||
def self.parse_pep_508_dep_spec(dep) | ||
name, requirement = dep.split(PEP_508_NAME_REGEX, 2).last(2).map(&:strip) | ||
requirement = requirement.sub(/^[\s;]*/, "") | ||
requirement = "*" if requirement == "" | ||
return name, requirement | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Bibliothecary | ||
VERSION = "8.5.1" | ||
VERSION = "8.6.0" | ||
end |
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.
cc @papiro @mpace965