Skip to content

Commit

Permalink
Back-populate string license fields (#1805)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Nov 12, 2024
1 parent c1a3c6b commit fc25690
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
22 changes: 8 additions & 14 deletions backend/src/hatchling/metadata/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def construct_metadata_file_1_2(metadata: ProjectMetadata, extra_dependencies: t
metadata_file += f'{line}\n'
else:
metadata_file += f'{indent}{line}\n'
elif metadata.core.license_expression:
metadata_file += f'License: {metadata.core.license_expression}\n'

if metadata.core.keywords:
metadata_file += f"Keywords: {','.join(metadata.core.keywords)}\n"
Expand Down Expand Up @@ -293,13 +295,8 @@ def construct_metadata_file_2_1(metadata: ProjectMetadata, extra_dependencies: t
metadata_file += f'{line}\n'
else:
metadata_file += f'{indent}{line}\n'

if metadata.core.license_expression:
metadata_file += f'License-Expression: {metadata.core.license_expression}\n'

if metadata.core.license_files:
for license_file in metadata.core.license_files:
metadata_file += f'License-File: {license_file}\n'
elif metadata.core.license_expression:
metadata_file += f'License: {metadata.core.license_expression}\n'

if metadata.core.keywords:
metadata_file += f"Keywords: {','.join(metadata.core.keywords)}\n"
Expand Down Expand Up @@ -384,13 +381,8 @@ def construct_metadata_file_2_2(metadata: ProjectMetadata, extra_dependencies: t
metadata_file += f'{line}\n'
else:
metadata_file += f'{indent}{line}\n'

if metadata.core.license_expression:
metadata_file += f'License-Expression: {metadata.core.license_expression}\n'

if metadata.core.license_files:
for license_file in metadata.core.license_files:
metadata_file += f'License-File: {license_file}\n'
elif metadata.core.license_expression:
metadata_file += f'License: {metadata.core.license_expression}\n'

if metadata.core.keywords:
metadata_file += f"Keywords: {','.join(metadata.core.keywords)}\n"
Expand Down Expand Up @@ -475,6 +467,8 @@ def construct_metadata_file_2_3(metadata: ProjectMetadata, extra_dependencies: t
metadata_file += f'{line}\n'
else:
metadata_file += f'{indent}{line}\n'
elif metadata.core.license_expression:
metadata_file += f'License: {metadata.core.license_expression}\n'

if metadata.core.keywords:
metadata_file += f"Keywords: {','.join(metadata.core.keywords)}\n"
Expand Down
5 changes: 5 additions & 0 deletions docs/history/hatchling.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

***Fixed:***

- Back-populate string `license` fields (`License-Expression`) for core metadata versions prior to 2.4
- Remove the `License-Expression` and `License-Files` core metadata from version 2.2 that was missed in the previous minor release

## [1.26.1](https://github.com/pypa/hatch/releases/tag/hatchling-v1.26.1) - 2024-11-10 ## {: #hatchling-v1.26.1 }

***Fixed:***
Expand Down
38 changes: 34 additions & 4 deletions tests/backend/metadata/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,22 @@ def test_license(self, constructor, isolation, helpers):
"""
)

def test_license_expression(self, constructor, isolation, helpers):
metadata = ProjectMetadata(
str(isolation),
None,
{'project': {'name': 'My.App', 'version': '0.1.0', 'license': 'mit'}},
)

assert constructor(metadata) == helpers.dedent(
"""
Metadata-Version: 1.2
Name: My.App
Version: 0.1.0
License: MIT
"""
)

def test_keywords_single(self, constructor, isolation, helpers):
metadata = ProjectMetadata(
str(isolation), None, {'project': {'name': 'My.App', 'version': '0.1.0', 'keywords': ['foo']}}
Expand Down Expand Up @@ -762,7 +778,7 @@ def test_license_expression(self, constructor, isolation, helpers):
Metadata-Version: 2.1
Name: My.App
Version: 0.1.0
License-Expression: MIT
License: MIT
"""
)

Expand Down Expand Up @@ -961,7 +977,6 @@ def test_all(self, constructor, helpers, temp_dir):
Maintainer-email: foo <bar@domain>
License: foo
bar
License-File: LICENSE.txt
Keywords: bar,foo
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.11
Expand Down Expand Up @@ -1202,7 +1217,7 @@ def test_license_expression(self, constructor, isolation, helpers):
Metadata-Version: 2.2
Name: My.App
Version: 0.1.0
License-Expression: MIT
License: MIT
"""
)

Expand Down Expand Up @@ -1431,7 +1446,6 @@ def test_all(self, constructor, helpers, temp_dir):
Maintainer-email: foo <bar@domain>
License: foo
bar
License-File: LICENSE.txt
Keywords: bar,foo
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.11
Expand Down Expand Up @@ -1660,6 +1674,22 @@ def test_license(self, constructor, isolation, helpers):
"""
)

def test_license_expression(self, constructor, isolation, helpers):
metadata = ProjectMetadata(
str(isolation),
None,
{'project': {'name': 'My.App', 'version': '0.1.0', 'license': 'mit'}},
)

assert constructor(metadata) == helpers.dedent(
"""
Metadata-Version: 2.3
Name: My.App
Version: 0.1.0
License: MIT
"""
)

def test_keywords_single(self, constructor, isolation, helpers):
metadata = ProjectMetadata(
str(isolation), None, {'project': {'name': 'My.App', 'version': '0.1.0', 'keywords': ['foo']}}
Expand Down

0 comments on commit fc25690

Please sign in to comment.