-
Notifications
You must be signed in to change notification settings - Fork 280
feat: support writing metadata #846
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb90ac0
feat: support writing metadata
henryiii 515171d
refactor: remove JSON output option
henryiii 6e5f0eb
tests: add a few more tests from pyproject-metadata
henryiii f892651
Apply suggestions from code review
henryiii d7d3687
chore: apply pre-commit changes
henryiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: support writing metadata
Signed-off-by: Henry Schreiner <[email protected]>
- Loading branch information
commit eb90ac0b32638c2f57cf28e9e19ea5fcc59da8f7
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -772,3 +772,169 @@ def test_invalid_license_files(self, license_files): | |
|
|
||
| with pytest.raises(metadata.InvalidMetadata): | ||
| meta.license_files # noqa: B018 | ||
|
|
||
|
|
||
| class TestMetadataWriting: | ||
| def test_write_metadata(self): | ||
| meta = metadata.Metadata.from_raw(_RAW_EXAMPLE) | ||
| written = meta.as_rfc822().as_string() | ||
| assert ( | ||
| written == "metadata-version: 2.3\nname: packaging\nversion: 2023.0.0\n\n" | ||
| ) | ||
|
|
||
| def test_write_metadata_with_description(self): | ||
| # Intentionally out of order to make sure it is written in order | ||
| meta = metadata.Metadata.from_raw( | ||
| { | ||
| "version": "1.2.3", | ||
| "name": "Hello", | ||
| "description": "Hello\n\nWorld👋", | ||
| "metadata_version": "2.3", | ||
| } | ||
| ) | ||
| written = meta.as_rfc822().as_string() | ||
| assert ( | ||
| written == "metadata-version: 2.3\nname: Hello\n" | ||
| "version: 1.2.3\n\nHello\n\nWorld👋" | ||
| ) | ||
| written = meta.as_rfc822().as_bytes() | ||
| assert ( | ||
| written | ||
| == "metadata-version: 2.3\nname: Hello\n" | ||
| "version: 1.2.3\n\nHello\n\nWorld👋".encode() | ||
| ) | ||
|
|
||
| def test_multiline_license(self): | ||
| meta = metadata.Metadata.from_raw( | ||
| { | ||
| "version": "1.2.3", | ||
| "name": "packaging", | ||
| "license": "Hello\nWorld🐍", | ||
| "metadata_version": "2.3", | ||
| } | ||
| ) | ||
| written = meta.as_rfc822().as_string() | ||
| assert ( | ||
| written == "metadata-version: 2.3\nname: packaging\nversion: 1.2.3" | ||
| "\nlicense: Hello\n World🐍\n\n" | ||
| ) | ||
| written = meta.as_rfc822().as_bytes() | ||
| assert ( | ||
| written | ||
| == "metadata-version: 2.3\nname: packaging\nversion: 1.2.3" | ||
| "\nlicense: Hello\n World🐍\n\n".encode() | ||
| ) | ||
|
|
||
| def test_large(self): | ||
| meta = metadata.Metadata.from_raw( | ||
| { | ||
| "author": "Example!", | ||
| "author_email": "Unknown <[email protected]>", | ||
| "classifiers": [ | ||
| "Development Status :: 4 - Beta", | ||
| "Programming Language :: Python", | ||
| ], | ||
| "description": "some readme 👋\n", | ||
| "description_content_type": "text/markdown", | ||
| "keywords": ["trampolim", "is", "interesting"], | ||
| "license": "some license text", | ||
| "maintainer_email": "Other Example <[email protected]>", | ||
| "metadata_version": "2.1", | ||
| "name": "full_metadata", | ||
| "project_urls": { | ||
| "homepage": "example.com", | ||
| "documentation": "readthedocs.org", | ||
| "repository": "github.com/some/repo", | ||
| "changelog": "github.com/some/repo/blob/master/CHANGELOG.rst", | ||
| }, | ||
| "provides_extra": ["test"], | ||
| "requires_dist": [ | ||
| "dependency1", | ||
| "dependency2>1.0.0", | ||
| "dependency3[extra]", | ||
| 'dependency4; os_name != "nt"', | ||
| 'dependency5[other-extra]>1.0; os_name == "nt"', | ||
| 'test_dependency; extra == "test"', | ||
| 'test_dependency[test_extra]; extra == "test"', | ||
| "test_dependency[test_extra2]>3.0; " | ||
| 'os_name == "nt" and extra == "test"', | ||
| ], | ||
| "requires_python": ">=3.8", | ||
| "summary": "A package with all the metadata :)", | ||
| "version": "3.2.1", | ||
| } | ||
| ) | ||
|
|
||
| assert meta.as_json() == { | ||
| "author": "Example!", | ||
| "author_email": "Unknown <[email protected]>", | ||
| "classifier": [ | ||
| "Development Status :: 4 - Beta", | ||
| "Programming Language :: Python", | ||
| ], | ||
| "description": "some readme 👋\n", | ||
| "description_content_type": "text/markdown", | ||
| "keywords": ["trampolim", "is", "interesting"], | ||
| "license": "some license text", | ||
| "maintainer_email": "Other Example <[email protected]>", | ||
| "metadata_version": "2.1", | ||
| "name": "full_metadata", | ||
| "project_url": [ | ||
| "homepage, example.com", | ||
| "documentation, readthedocs.org", | ||
| "repository, github.com/some/repo", | ||
| "changelog, github.com/some/repo/blob/master/CHANGELOG.rst", | ||
| ], | ||
| "provides_extra": ["test"], | ||
| "requires_dist": [ | ||
| "dependency1", | ||
| "dependency2>1.0.0", | ||
| "dependency3[extra]", | ||
| 'dependency4; os_name != "nt"', | ||
| 'dependency5[other-extra]>1.0; os_name == "nt"', | ||
| 'test_dependency; extra == "test"', | ||
| 'test_dependency[test_extra]; extra == "test"', | ||
| 'test_dependency[test_extra2]>3.0; os_name == "nt" and extra == "test"', | ||
| ], | ||
| "requires_python": ">=3.8", | ||
| "summary": "A package with all the metadata :)", | ||
| "version": "3.2.1", | ||
| } | ||
|
|
||
| core_metadata = meta.as_rfc822() | ||
| assert core_metadata.items() == [ | ||
| ("metadata-version", "2.1"), | ||
| ("name", "full_metadata"), | ||
| ("version", "3.2.1"), | ||
| ("summary", "A package with all the metadata :)"), | ||
| ("description-content-type", "text/markdown"), | ||
| ("keywords", "trampolim,is,interesting"), | ||
| ("author", "Example!"), | ||
| ("author-email", "Unknown <[email protected]>"), | ||
| ("maintainer-email", "Other Example <[email protected]>"), | ||
| ("license", "some license text"), | ||
| ("classifier", "Development Status :: 4 - Beta"), | ||
| ("classifier", "Programming Language :: Python"), | ||
| ("requires-dist", "dependency1"), | ||
| ("requires-dist", "dependency2>1.0.0"), | ||
| ("requires-dist", "dependency3[extra]"), | ||
| ("requires-dist", 'dependency4; os_name != "nt"'), | ||
| ("requires-dist", 'dependency5[other-extra]>1.0; os_name == "nt"'), | ||
| ("requires-dist", 'test_dependency; extra == "test"'), | ||
| ("requires-dist", 'test_dependency[test_extra]; extra == "test"'), | ||
| ( | ||
| "requires-dist", | ||
| 'test_dependency[test_extra2]>3.0; os_name == "nt" and extra == "test"', | ||
| ), | ||
| ("requires-python", ">=3.8"), | ||
| ("project-url", "homepage, example.com"), | ||
| ("project-url", "documentation, readthedocs.org"), | ||
| ("project-url", "repository, github.com/some/repo"), | ||
| ( | ||
| "project-url", | ||
| "changelog, github.com/some/repo/blob/master/CHANGELOG.rst", | ||
| ), | ||
| ("provides-extra", "test"), | ||
| ] | ||
|
|
||
| assert core_metadata.get_payload() == "some readme 👋\n" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.