Skip to content

Commit e2e8ac2

Browse files
authored
Merge branch 'main' into importlib_machinery
2 parents 1186a45 + 2c28939 commit e2e8ac2

38 files changed

+180
-148
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
merge_group:
55
push:
66
branches-ignore:
7-
- gh-readonly-queue/** # Temporary merge queue-related GH-made branches
7+
# disabled for jaraco/skeleton#103
8+
# - gh-readonly-queue/** # Temporary merge queue-related GH-made branches
89
pull_request:
910
workflow_dispatch:
1011

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
:target: https://discord.com/channels/803025117553754132/815945031150993468
2828
:alt: Discord
2929

30-
See the `Installation Instructions
31-
<https://packaging.python.org/installing/>`_ in the Python Packaging
32-
User's Guide for instructions on installing, upgrading, and uninstalling
33-
Setuptools.
30+
See the `Quickstart <https://setuptools.pypa.io/en/latest/userguide/quickstart.html>`_
31+
and the `User's Guide <https://setuptools.pypa.io/en/latest/userguide/>`_ for
32+
instructions on how to use Setuptools.
3433

3534
Questions and comments should be directed to `GitHub Discussions
3635
<https://github.com/pypa/setuptools/discussions>`_.

docs/userguide/miscellaneous.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Please note that the list above is guaranteed to work with the last stable versi
3535
of ``setuptools``. The behavior of older versions might differ.
3636

3737
.. note::
38-
.. versionadded:: v68.3.0
38+
.. versionadded:: v69.0.0
3939
``setuptools`` will attempt to include type information files
4040
by default in the distribution
4141
(``.pyi`` and ``py.typed``, as specified in :pep:`561`).

newsfragments/4182.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed ``versionadded`` for "Type information included by default" feature from ``v68.3.0`` to ``v69.0.0`` -- by :user:Avasam`

pkg_resources/__init__.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,18 @@ def get_provider(moduleOrReq):
400400
return _find_adapter(_provider_factories, loader)(module)
401401

402402

403-
def _macos_vers(_cache=[]):
404-
if not _cache:
405-
version = platform.mac_ver()[0]
406-
# fallback for MacPorts
407-
if version == '':
408-
plist = '/System/Library/CoreServices/SystemVersion.plist'
409-
if os.path.exists(plist):
410-
if hasattr(plistlib, 'readPlist'):
411-
plist_content = plistlib.readPlist(plist)
412-
if 'ProductVersion' in plist_content:
413-
version = plist_content['ProductVersion']
414-
415-
_cache.append(version.split('.'))
416-
return _cache[0]
403+
@functools.lru_cache(maxsize=None)
404+
def _macos_vers():
405+
version = platform.mac_ver()[0]
406+
# fallback for MacPorts
407+
if version == '':
408+
plist = '/System/Library/CoreServices/SystemVersion.plist'
409+
if os.path.exists(plist):
410+
with open(plist, 'rb') as fh:
411+
plist_content = plistlib.load(fh)
412+
if 'ProductVersion' in plist_content:
413+
version = plist_content['ProductVersion']
414+
return version.split('.')
417415

418416

419417
def _macos_arch(machine):
@@ -1888,7 +1886,7 @@ def _extract_resource(self, manager, zip_path): # noqa: C901
18881886
try:
18891887
rename(tmpnam, real_path)
18901888

1891-
except os.error:
1889+
except OSError:
18921890
if os.path.isfile(real_path):
18931891
if self._is_current(real_path, zip_path):
18941892
# the file became current since it was checked above,
@@ -1901,7 +1899,7 @@ def _extract_resource(self, manager, zip_path): # noqa: C901
19011899
return real_path
19021900
raise
19031901

1904-
except os.error:
1902+
except OSError:
19051903
# report a user-friendly error
19061904
manager.extraction_error()
19071905

@@ -2415,12 +2413,9 @@ def _cygwin_patch(filename): # pragma: nocover
24152413
return os.path.abspath(filename) if sys.platform == 'cygwin' else filename
24162414

24172415

2418-
def _normalize_cached(filename, _cache={}):
2419-
try:
2420-
return _cache[filename]
2421-
except KeyError:
2422-
_cache[filename] = result = normalize_path(filename)
2423-
return result
2416+
@functools.lru_cache(maxsize=None)
2417+
def _normalize_cached(filename):
2418+
return normalize_path(filename)
24242419

24252420

24262421
def _is_egg_path(path):
@@ -2894,7 +2889,7 @@ def __getattr__(self, attr):
28942889

28952890
def __dir__(self):
28962891
return list(
2897-
set(super(Distribution, self).__dir__())
2892+
set(super().__dir__())
28982893
| set(attr for attr in self._provider.__dir__() if not attr.startswith('_'))
28992894
)
29002895

@@ -3161,7 +3156,7 @@ class RequirementParseError(packaging.requirements.InvalidRequirement):
31613156
class Requirement(packaging.requirements.Requirement):
31623157
def __init__(self, requirement_string):
31633158
"""DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
3164-
super(Requirement, self).__init__(requirement_string)
3159+
super().__init__(requirement_string)
31653160
self.unsafe_name = self.name
31663161
project_name = safe_name(self.name)
31673162
self.project_name, self.key = project_name, project_name.lower()

pkg_resources/tests/test_pkg_resources.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import builtins
12
import sys
23
import tempfile
34
import os
45
import zipfile
56
import datetime
67
import time
8+
import plistlib
79
import subprocess
810
import stat
911
import distutils.dist
@@ -323,6 +325,32 @@ def test_dist_info_is_not_dir(tmp_path, only):
323325
assert not pkg_resources.dist_factory(str(tmp_path), str(dist_info), only)
324326

325327

328+
def test_macos_vers_fallback(monkeypatch, tmp_path):
329+
"""Regression test for pkg_resources._macos_vers"""
330+
orig_open = builtins.open
331+
332+
# Pretend we need to use the plist file
333+
monkeypatch.setattr('platform.mac_ver', mock.Mock(return_value=('', (), '')))
334+
335+
# Create fake content for the fake plist file
336+
with open(tmp_path / 'fake.plist', 'wb') as fake_file:
337+
plistlib.dump({"ProductVersion": "11.4"}, fake_file)
338+
339+
# Pretend the fake file exists
340+
monkeypatch.setattr('os.path.exists', mock.Mock(return_value=True))
341+
342+
def fake_open(file, *args, **kwargs):
343+
return orig_open(tmp_path / 'fake.plist', *args, **kwargs)
344+
345+
# Ensure that the _macos_vers works correctly
346+
with mock.patch('builtins.open', mock.Mock(side_effect=fake_open)) as m:
347+
pkg_resources._macos_vers.cache_clear()
348+
assert pkg_resources._macos_vers() == ["11", "4"]
349+
pkg_resources._macos_vers.cache_clear()
350+
351+
m.assert_called()
352+
353+
326354
class TestDeepVersionLookupDistutils:
327355
@pytest.fixture
328356
def env(self, tmpdir):

pkg_resources/tests/test_working_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def parametrize_test_working_set_resolve(*test_list):
7676
requirements,
7777
expected1,
7878
expected2,
79-
) = [
79+
) = (
8080
strip_comments(s.lstrip())
8181
for s in textwrap.dedent(test).lstrip().split('\n\n', 5)
82-
]
82+
)
8383
installed_dists = list(parse_distributions(installed_dists))
8484
installable_dists = list(parse_distributions(installable_dists))
8585
requirements = list(pkg_resources.parse_requirements(requirements))

ruff.toml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[lint]
2-
extend-ignore = [
2+
ignore = [
33
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
44
"W191",
55
"E111",
@@ -16,7 +16,27 @@ extend-ignore = [
1616
"ISC001",
1717
"ISC002",
1818
]
19+
extend-select = [
20+
"UP", # pyupgrade
21+
]
22+
extend-ignore = [
23+
"UP015", # redundant-open-modes, explicit is prefered
24+
"UP030", # temporarily disabled
25+
"UP031", # temporarily disabled
26+
"UP032", # temporarily disabled
27+
"UP036", # temporarily disabled
28+
]
29+
exclude = [
30+
"**/_vendor",
31+
"setuptools/_distutils",
32+
"setuptools/config/_validate_pyproject",
33+
]
1934

2035
[format]
36+
exclude = [
37+
"**/_vendor",
38+
"setuptools/_distutils",
39+
"setuptools/config/_validate_pyproject",
40+
]
2141
# https://docs.astral.sh/ruff/settings/#format-quote-style
2242
quote-style = "preserve"

setuptools/build_meta.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _file_with_extension(directory, extension):
121121
raise ValueError(
122122
'No distribution was found. Ensure that `setup.py` '
123123
'is not empty and that it calls `setup()`.'
124-
)
124+
) from None
125125
return file
126126

127127

@@ -130,7 +130,7 @@ def _open_setup_script(setup_script):
130130
# Supply a default setup.py
131131
return io.StringIO("from setuptools import setup; setup()")
132132

133-
return getattr(tokenize, 'open', open)(setup_script)
133+
return tokenize.open(setup_script)
134134

135135

136136
@contextlib.contextmanager
@@ -477,7 +477,7 @@ def run_setup(self, setup_script='setup.py'):
477477
sys.argv[0] = setup_script
478478

479479
try:
480-
super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
480+
super().run_setup(setup_script=setup_script)
481481
finally:
482482
# While PEP 517 frontends should be calling each hook in a fresh
483483
# subprocess according to the standard (and thus it should not be

setuptools/command/bdist_egg.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ def walk_egg(egg_dir):
321321
if 'EGG-INFO' in dirs:
322322
dirs.remove('EGG-INFO')
323323
yield base, dirs, files
324-
for bdf in walker:
325-
yield bdf
324+
yield from walker
326325

327326

328327
def analyze_egg(egg_dir, stubs):
@@ -406,14 +405,12 @@ def scan_module(egg_dir, base, name, stubs):
406405

407406
def iter_symbols(code):
408407
"""Yield names and strings used by `code` and its nested code objects"""
409-
for name in code.co_names:
410-
yield name
408+
yield from code.co_names
411409
for const in code.co_consts:
412410
if isinstance(const, str):
413411
yield const
414412
elif isinstance(const, CodeType):
415-
for name in iter_symbols(const):
416-
yield name
413+
yield from iter_symbols(const)
417414

418415

419416
def can_scan():

0 commit comments

Comments
 (0)