Skip to content

Commit

Permalink
fix: concatenate the markers with extra marker (#83)
Browse files Browse the repository at this point in the history
* fix: concatenate the markers with extra marker

Signed-off-by: Frost Ming <[email protected]>

* fix quotes

Signed-off-by: Frost Ming <[email protected]>

---------

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Jan 26, 2024
1 parent 42304c4 commit 603f288
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,17 @@ def _build_extra_req(
) -> packaging.requirements.Requirement:
# append or add our extra marker
requirement = copy.copy(requirement)
requirement.marker = packaging.markers.Marker(
f'{requirement.marker} and extra == "{extra}"' if requirement.marker else f'extra == "{extra}"',
)
if requirement.marker:
if 'or' in requirement.marker._markers:
requirement.marker = packaging.markers.Marker(
f'({requirement.marker}) and extra == "{extra}"'
)
else:
requirement.marker = packaging.markers.Marker(
f'{requirement.marker} and extra == "{extra}"'
)
else:
requirement.marker = packaging.markers.Marker(f'extra == "{extra}"')
return requirement

@staticmethod
Expand Down
23 changes: 23 additions & 0 deletions tests/test_rfc822.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,26 @@ def test_body():
finibus nulla. Donec sit amet ante in neque pulvinar faucibus sed nec justo.
Fusce hendrerit massa libero, sit amet pulvinar magna tempor quis.
''')


def test_convert_optional_dependencies():
metadata = pyproject_metadata.StandardMetadata.from_pyproject(
{
'project': {
'name': 'example',
'version': '0.1.0',
'optional-dependencies': {
'test': [
'foo; os_name == "nt" or sys_platform == "win32"',
'bar; os_name == "posix" and sys_platform == "linux"',
],
},
},
}
)
message = metadata.as_rfc822()
requires = message.headers['Requires-Dist']
assert requires == [
'foo; (os_name == "nt" or sys_platform == "win32") and extra == "test"',
'bar; os_name == "posix" and sys_platform == "linux" and extra == "test"',
]

0 comments on commit 603f288

Please sign in to comment.