Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Next release

- Improve copyright detection for statements with parens or trailing "authors"

- Fix ``python_version`` environment markers using ``>``, ``!=`` or ``~=`` being
silently dropped from the dependency ``extra_data``.
https://github.com/aboutcode-org/scancode-toolkit/issues/5309


v33.0.0rc1 - 2026-05-14
------------------------
Expand Down
5 changes: 4 additions & 1 deletion src/packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,10 @@ def get_python_version_os(marker):
requirement Marker or None.
"""
platform_data = {}
python_version_operators = ['<', '>=', '==', '<=', '<']
# all comparison operators allowed for a marker in PEP 508
python_version_operators = [
'<', '<=', '!=', '==', '>=', '>', '~=', '===',
]

if not marker or not isinstance(marker, markers.Marker):
return platform_data
Expand Down
18 changes: 18 additions & 0 deletions tests/packagedcode/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,21 @@ def test_parse_setup_py(test_loc):
def test_parse_more_setup_py(test_loc):
check_setup_py_parsing(test_loc)


@pytest.mark.parametrize(
('requirement', 'expected'),
[
('requests; python_version < "3.8"', {'python_version': '< 3.8'}),
('requests; python_version <= "3.8"', {'python_version': '<= 3.8'}),
('requests; python_version != "3.8"', {'python_version': '!= 3.8'}),
('requests; python_version == "3.8"', {'python_version': '== 3.8'}),
('requests; python_version >= "3.8"', {'python_version': '>= 3.8'}),
('requests; python_version > "3.8"', {'python_version': '> 3.8'}),
('requests; python_version ~= "3.8"', {'python_version': '~= 3.8'}),
],
)
def test_get_python_version_os_handles_all_comparison_operators(requirement, expected):
from packvers.requirements import Requirement

marker = Requirement(requirement).marker
assert pypi.get_python_version_os(marker) == expected