Skip to content

Commit 1b89812

Browse files
committed
Merge branch 'main' into feature/pep-621
2 parents 3dad80a + 7208628 commit 1b89812

File tree

6 files changed

+50
-32
lines changed

6 files changed

+50
-32
lines changed

newsfragments/4136.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In install command, use super to call the superclass methods. Avoids race conditions when monkeypatching from _distutils_system_mod occurs late.

newsfragments/4267.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Typed the dynamically defined variables from `pkg_resources` -- by :user:`Avasam`

pkg_resources/__init__.py

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@
2727
import time
2828
import re
2929
import types
30-
from typing import Callable, Dict, Iterable, List, Protocol, Optional, TypeVar
30+
from typing import (
31+
TYPE_CHECKING,
32+
List,
33+
Protocol,
34+
Callable,
35+
Dict,
36+
Iterable,
37+
Optional,
38+
TypeVar,
39+
)
3140
import zipfile
3241
import zipimport
3342
import warnings
@@ -76,21 +85,6 @@
7685
from pkg_resources.extern.packaging import version as _packaging_version
7786
from pkg_resources.extern.platformdirs import user_cache_dir as _user_cache_dir
7887

79-
# declare some globals that will be defined later to
80-
# satisfy the linters.
81-
require = None
82-
working_set = None
83-
add_activation_listener = None
84-
cleanup_resources = None
85-
resource_stream = None
86-
set_extraction_path = None
87-
resource_isdir = None
88-
resource_string = None
89-
iter_entry_points = None
90-
resource_listdir = None
91-
resource_filename = None
92-
resource_exists = None
93-
9488

9589
warnings.warn(
9690
"pkg_resources is deprecated as an API. "
@@ -1610,14 +1604,15 @@ def _validate_resource_path(path):
16101604
os.path.pardir in path.split(posixpath.sep)
16111605
or posixpath.isabs(path)
16121606
or ntpath.isabs(path)
1607+
or path.startswith("\\")
16131608
)
16141609
if not invalid:
16151610
return
16161611

16171612
msg = "Use of .. or absolute path in a resource path is not allowed."
16181613

16191614
# Aggressively disallow Windows absolute paths
1620-
if ntpath.isabs(path) and not posixpath.isabs(path):
1615+
if (path.startswith("\\") or ntpath.isabs(path)) and not posixpath.isabs(path):
16211616
raise ValueError(msg)
16221617

16231618
# for compatibility, warn; in future
@@ -3257,6 +3252,15 @@ def _mkstemp(*args, **kw):
32573252
warnings.filterwarnings("ignore", category=PEP440Warning, append=True)
32583253

32593254

3255+
class PkgResourcesDeprecationWarning(Warning):
3256+
"""
3257+
Base class for warning about deprecations in ``pkg_resources``
3258+
3259+
This class is not derived from ``DeprecationWarning``, and as such is
3260+
visible by default.
3261+
"""
3262+
3263+
32603264
# from jaraco.functools 1.3
32613265
def _call_aside(f, *args, **kwargs):
32623266
f(*args, **kwargs)
@@ -3275,15 +3279,6 @@ def _initialize(g=globals()):
32753279
)
32763280

32773281

3278-
class PkgResourcesDeprecationWarning(Warning):
3279-
"""
3280-
Base class for warning about deprecations in ``pkg_resources``
3281-
3282-
This class is not derived from ``DeprecationWarning``, and as such is
3283-
visible by default.
3284-
"""
3285-
3286-
32873282
@_call_aside
32883283
def _initialize_master_working_set():
32893284
"""
@@ -3320,6 +3315,26 @@ def _initialize_master_working_set():
33203315
globals().update(locals())
33213316

33223317

3318+
if TYPE_CHECKING:
3319+
# All of these are set by the @_call_aside methods above
3320+
__resource_manager = ResourceManager() # Won't exist at runtime
3321+
resource_exists = __resource_manager.resource_exists
3322+
resource_isdir = __resource_manager.resource_isdir
3323+
resource_filename = __resource_manager.resource_filename
3324+
resource_stream = __resource_manager.resource_stream
3325+
resource_string = __resource_manager.resource_string
3326+
resource_listdir = __resource_manager.resource_listdir
3327+
set_extraction_path = __resource_manager.set_extraction_path
3328+
cleanup_resources = __resource_manager.cleanup_resources
3329+
3330+
working_set = WorkingSet()
3331+
require = working_set.require
3332+
iter_entry_points = working_set.iter_entry_points
3333+
add_activation_listener = working_set.subscribe
3334+
run_script = working_set.run_script
3335+
run_main = run_script
3336+
3337+
33233338
# ---- Ported from ``setuptools`` to avoid introducing an import inter-dependency ----
33243339
LOCALE_ENCODING = "locale" if sys.version_info >= (3, 10) else None
33253340

setuptools/_entry_points.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def ensure_valid(ep):
1717
"""
1818
try:
1919
ep.extras
20-
except AttributeError as ex:
20+
except (AttributeError, AssertionError) as ex:
21+
# Why both? See https://github.com/python/importlib_metadata/issues/488
2122
msg = (
2223
f"Problems to parse {ep}.\nPlease ensure entry-point follows the spec: "
2324
"https://packaging.python.org/en/latest/specifications/entry-points/"

setuptools/command/install.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def initialize_options(self):
4949
# and then add a due_date to this warning.
5050
)
5151

52-
orig.install.initialize_options(self)
52+
super().initialize_options()
5353
self.old_and_unmanageable = None
5454
self.single_version_externally_managed = None
5555

5656
def finalize_options(self):
57-
orig.install.finalize_options(self)
57+
super().finalize_options()
5858
if self.root:
5959
self.single_version_externally_managed = True
6060
elif self.single_version_externally_managed:
@@ -78,11 +78,11 @@ def handle_extra_path(self):
7878
def run(self):
7979
# Explicit request for old-style install? Just do it
8080
if self.old_and_unmanageable or self.single_version_externally_managed:
81-
return orig.install.run(self)
81+
return super().run()
8282

8383
if not self._called_from_setup(inspect.currentframe()):
8484
# Run in backward-compatibility mode to support bdist_* commands.
85-
orig.install.run(self)
85+
super().run()
8686
else:
8787
self.do_egg_install()
8888

tools/generate_validation_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def generate_pyproject_validation(dest: Union[str, PathLike]):
1414
cmd = [
1515
sys.executable,
1616
"-m",
17-
"validate_pyproject.vendoring",
17+
"validate_pyproject.pre_compile",
1818
f"--output-dir={dest}",
1919
"--enable-plugins",
2020
"setuptools",

0 commit comments

Comments
 (0)