-
Notifications
You must be signed in to change notification settings - Fork 261
add support for PEP 639 License Clarity #870
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
base: main
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR implements full support for PEP 639 “License Clarity” by extending the core factory to parse new [project].license-files globs and SPDX license expressions, enhancing strict validation, bumping core metadata to 2.4, updating masonry builders to emit License-Expression and License-File fields and embed license files under dist-info/licenses, and updating/adding tests to cover all new scenarios. Sequence Diagram: PEP 639 License ProcessingsequenceDiagram
actor Developer
participant P as PyProjectTOML
participant F as Factory
participant PP as ProjectPackage
participant M as Metadata
participant B as Builder
Developer->>P: Defines [project].license (SPDX)\nand [project].license-files
F->>P: Reads pyproject.toml data
F->>PP: _configure_package_metadata(package, project_data)
activate F
F->>F: canonicalize_license_expression(project_data["license"])
PP->>PP: set package.license_expression
F->>F: Validate license-files globs
PP->>PP: set package.license_files (globs)
deactivate F
F->>F: validate(toml_data)
activate F
F->>F: _validate_project(project_data, result) // Validates SPDX, warns on legacy
deactivate F
M->>PP: from_package(package)
activate M
M->>M: set meta.metadata_version = "2.4"
M->>M: set meta.license_expression (from package.license_expression)
M->>PP: Processes package.license_files (globs from package.root_dir)
activate PP
PP->>PP: package.root_dir.glob(pattern)
deactivate PP
opt Globs match no files
M->>M: Raise RuntimeError
end
M->>M: set meta.license_files (resolved relative paths)
deactivate M
B->>M: get_metadata_content()
activate B
B->>B: Writes Metadata-Version: 2.4
opt meta.license_expression is set
B->>B: Writes License-Expression: ...
end
loop for each license_file in meta.license_files
B->>B: Writes License-File: ...
end
deactivate B
B->>M: _get_legal_files()
activate B
B->>B: Returns files based on meta.license_files
deactivate B
B->>B: Includes license files (e.g., in dist-info/licenses/)
Class Diagram: PEP 639 License Handling ChangesclassDiagram
direction LR
class Factory {
+String _configure_package_metadata(ProjectPackage package, dict project, dict tool_poetry, Path root)
+None _validate_project(dict project, dict result)
}
class ProjectPackage {
+license_expression: NormalizedLicenseExpression
+license_files: LicenseFileConfig
+List~String~ all_classifiers()
}
class Metadata {
+String metadata_version = "2.4"
+String license_expression
+Tuple~String~ license_files
+Metadata from_package(ProjectPackage package)
}
class Builder {
#Metadata _meta
+String get_metadata_content()
#Set~Path~ _get_legal_files()
}
class WheelBuilder {
+Path prepare_metadata(Path metadata_directory)
}
Factory ..> ProjectPackage : configures
Metadata ..> ProjectPackage : generated from
Builder ..> Metadata : uses
WheelBuilder --|> Builder
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Wow, all this code only for parsing new license fields? |
And we do not even do the SPDX parsing by ourselves but use |
I noticed, thanks for all the work! |
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.
Hey @radoering - I've reviewed your changes - here's some feedback:
- The new license parsing logic in Factory._configure_package_metadata is deeply nested—consider breaking it into smaller helper methods to improve readability and maintainability.
- Metadata.from_package and Builder._get_legal_files share very similar license‐file discovery code—extract that into a common utility to avoid duplication.
- The parameterized license tests are quite verbose and repetitive—introduce helper fixtures or functions to encapsulate common setup and assertions.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Related to: python-poetry/poetry#9670
Downstream tests will be fixed in python-poetry/poetry#10413 after merging this one.
Summary by Sourcery
Implement PEP 639 license clarity support by adding parsing and validation for project.license-files and SPDX license expressions, bump core metadata version to 2.4, include license data in distributions, and deprecate legacy license tables and classifiers.
New Features:
Bug Fixes:
Enhancements:
Tests: