Skip to content

Commit

Permalink
Replace OrderedSet with dict
Browse files Browse the repository at this point in the history
Since Python 3.7, ``dict`` preserve insertion order.
This means that ``dict`` is a capable implementation of an ordered set,
despite the method names not lining up completely.
  • Loading branch information
abravalheri committed Aug 16, 2024
1 parent 8bd9308 commit 49d7438
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import TYPE_CHECKING, MutableMapping

from more_itertools import partition, unique_everseen
from ordered_set import OrderedSet
from packaging.markers import InvalidMarker, Marker
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import Version
Expand Down Expand Up @@ -251,7 +250,7 @@ class Distribution(_Distribution):
_DISTUTILS_UNSUPPORTED_METADATA = {
'long_description_content_type': lambda: None,
'project_urls': dict,
'provides_extras': OrderedSet,
'provides_extras': dict, # behaves like an ordered set
'license_file': lambda: None,
'license_files': lambda: None,
'install_requires': list,
Expand Down Expand Up @@ -349,7 +348,7 @@ def _finalize_requires(self):
# Setuptools allows a weird "<name>:<env markers> syntax for extras
extra = extra.split(':')[0]
if extra:
self.metadata.provides_extras.add(extra)
self.metadata.provides_extras.setdefault(extra)

def _normalize_requires(self):
"""Make sure requirement-related attributes exist and are normalized"""
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def test_extras_require(self, tmpdir):
'pdf': ['ReportLab>=1.2', 'RXP'],
'rest': ['docutils>=0.3', 'pack==1.1,==1.3'],
}
assert dist.metadata.provides_extras == set(['pdf', 'rest'])
assert set(dist.metadata.provides_extras) == {'pdf', 'rest'}

@pytest.mark.parametrize(
"config",
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_read_metadata(name, attrs):
('requires', dist_class.get_requires),
('classifiers', dist_class.get_classifiers),
('project_urls', lambda s: getattr(s, 'project_urls', {})),
('provides_extras', lambda s: getattr(s, 'provides_extras', set())),
('provides_extras', lambda s: getattr(s, 'provides_extras', {})),
]

for attr, getter in tested_attrs:
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def test_provides_extras_deterministic_order():
extras['b'] = ['bar']
attrs = dict(extras_require=extras)
dist = Distribution(attrs)
assert dist.metadata.provides_extras == ['a', 'b']
assert list(dist.metadata.provides_extras) == ['a', 'b']
attrs['extras_require'] = collections.OrderedDict(
reversed(list(attrs['extras_require'].items()))
)
dist = Distribution(attrs)
assert dist.metadata.provides_extras == ['b', 'a']
assert list(dist.metadata.provides_extras) == ['b', 'a']


CHECK_PACKAGE_DATA_TESTS = (
Expand Down

0 comments on commit 49d7438

Please sign in to comment.