Skip to content

Commit 99bede7

Browse files
committed
2 parents 62d4512 + 8b94447 commit 99bede7

File tree

11 files changed

+54
-46
lines changed

11 files changed

+54
-46
lines changed

newsfragments/4876.bugfix.2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore `distutils.ccompiler._default_compilers` -- by :user:`ManiacDC`

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ core = [
101101
"platformdirs >= 4.2.2", # Made ctypes optional (see #4461)
102102

103103
# for distutils
104-
"jaraco.collections",
105104
"jaraco.functools >= 4",
106105
"packaging",
107106
"more_itertools",

setuptools/_distutils/ccompiler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from .compat.numpy import ( # noqa: F401
2+
_default_compilers,
3+
compiler_class,
4+
)
15
from .compilers.C import base
26
from .compilers.C.base import (
3-
compiler_class,
47
gen_lib_options,
58
gen_preprocess_options,
69
get_default_compiler,
@@ -12,7 +15,6 @@
1215
__all__ = [
1316
'CompileError',
1417
'LinkError',
15-
'compiler_class',
1618
'gen_lib_options',
1719
'gen_preprocess_options',
1820
'get_default_compiler',

setuptools/_distutils/command/__init__.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,40 @@
33
Package containing implementation of all the standard Distutils
44
commands."""
55

6+
from . import (
7+
bdist,
8+
bdist_dumb,
9+
bdist_rpm,
10+
build,
11+
build_clib,
12+
build_ext,
13+
build_py,
14+
build_scripts,
15+
check,
16+
clean,
17+
install,
18+
install_data,
19+
install_headers,
20+
install_lib,
21+
install_scripts,
22+
sdist,
23+
)
24+
625
__all__ = [
26+
'bdist',
27+
'bdist_dumb',
28+
'bdist_rpm',
729
'build',
8-
'build_py',
9-
'build_ext',
1030
'build_clib',
31+
'build_ext',
32+
'build_py',
1133
'build_scripts',
34+
'check',
1235
'clean',
1336
'install',
14-
'install_lib',
37+
'install_data',
1538
'install_headers',
39+
'install_lib',
1640
'install_scripts',
17-
'install_data',
1841
'sdist',
19-
'bdist',
20-
'bdist_dumb',
21-
'bdist_rpm',
22-
'check',
2342
]

setuptools/_distutils/command/install.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import collections
78
import contextlib
89
import itertools
910
import os
@@ -13,8 +14,6 @@
1314
from site import USER_BASE, USER_SITE
1415
from typing import ClassVar
1516

16-
import jaraco.collections
17-
1817
from ..core import Command
1918
from ..debug import DEBUG
2019
from ..errors import DistutilsOptionError, DistutilsPlatformError
@@ -145,7 +144,7 @@ def _resolve_scheme(name):
145144
try:
146145
resolved = sysconfig.get_preferred_scheme(key)
147146
except Exception:
148-
resolved = fw.scheme(_pypy_hack(name))
147+
resolved = fw.scheme(name)
149148
return resolved
150149

151150

@@ -162,7 +161,7 @@ def _inject_headers(name, scheme):
162161
"""
163162
# Bypass the preferred scheme, which may not
164163
# have defined headers.
165-
fallback = _load_scheme(_pypy_hack(name))
164+
fallback = _load_scheme(name)
166165
scheme.setdefault('headers', fallback['headers'])
167166
return scheme
168167

@@ -172,14 +171,6 @@ def _scheme_attrs(scheme):
172171
return {f'install_{key}': scheme[key] for key in SCHEME_KEYS}
173172

174173

175-
def _pypy_hack(name):
176-
PY37 = sys.version_info < (3, 8)
177-
old_pypy = hasattr(sys, 'pypy_version_info') and PY37
178-
prefix = not name.endswith(('_user', '_home'))
179-
pypy_name = 'pypy' + '_nt' * (os.name == 'nt')
180-
return pypy_name if old_pypy and prefix else name
181-
182-
183174
class install(Command):
184175
description = "install everything from build directory"
185176

@@ -432,12 +423,12 @@ def finalize_options(self) -> None: # noqa: C901
432423
local_vars['userbase'] = self.install_userbase
433424
local_vars['usersite'] = self.install_usersite
434425

435-
self.config_vars = jaraco.collections.DictStack([
436-
fw.vars(),
437-
compat_vars,
438-
sysconfig.get_config_vars(),
426+
self.config_vars = collections.ChainMap(
439427
local_vars,
440-
])
428+
sysconfig.get_config_vars(),
429+
compat_vars,
430+
fw.vars(),
431+
)
441432

442433
self.expand_basedirs()
443434

setuptools/_distutils/compat/numpy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# required for older numpy versions on Pythons prior to 3.12; see pypa/setuptools#4876
2+
from ..compilers.C.base import _default_compilers, compiler_class # noqa: F401

setuptools/_distutils/compilers/C/base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ class Compiler:
120120
}
121121
language_order: ClassVar[list[str]] = ["c++", "objc", "c"]
122122

123-
include_dirs = []
123+
include_dirs: list[str] = []
124124
"""
125125
include dirs specific to this compiler class
126126
"""
127127

128-
library_dirs = []
128+
library_dirs: list[str] = []
129129
"""
130130
library dirs specific to this compiler class
131131
"""
@@ -148,14 +148,14 @@ def __init__(
148148
self.macros: list[_Macro] = []
149149

150150
# 'include_dirs': a list of directories to search for include files
151-
self.include_dirs: list[str] = []
151+
self.include_dirs = []
152152

153153
# 'libraries': a list of libraries to include in any link
154154
# (library names, not filenames: eg. "foo" not "libfoo.a")
155155
self.libraries: list[str] = []
156156

157157
# 'library_dirs': a list of directories to search for libraries
158-
self.library_dirs: list[str] = []
158+
self.library_dirs = []
159159

160160
# 'runtime_library_dirs': a list of directories to search for
161161
# shared libraries/objects at runtime
@@ -236,8 +236,11 @@ def _check_macro_definition(self, defn):
236236
def _is_valid_macro(name, value=None):
237237
"""
238238
A valid macro is a ``name : str`` and a ``value : str | None``.
239+
240+
>>> Compiler._is_valid_macro('foo', None)
241+
True
239242
"""
240-
return isinstance(name, str) and isinstance(value, (str, None))
243+
return isinstance(name, str) and isinstance(value, (str, type(None)))
241244

242245
# -- Bookkeeping methods -------------------------------------------
243246

setuptools/_distutils/compilers/C/unix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def _is_gcc(self):
323323
compiler = os.path.basename(shlex.split(cc_var)[0])
324324
return "gcc" in compiler or "g++" in compiler
325325

326-
def runtime_library_dir_option(self, dir: str) -> str | list[str]:
326+
def runtime_library_dir_option(self, dir: str) -> str | list[str]: # type: ignore[override] # Fixed in pypa/distutils#339
327327
# XXX Hackish, at the very least. See Python bug #445902:
328328
# https://bugs.python.org/issue445902
329329
# Linkers on different platforms need different options to

setuptools/_distutils/dist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(self, attrs: MutableMapping[str, Any] | None = None) -> None: # no
183183
# can 1) quickly figure out which class to instantiate when
184184
# we need to create a new command object, and 2) have a way
185185
# for the setup script to override command classes
186-
self.cmdclass = {}
186+
self.cmdclass: dict[str, type[Command]] = {}
187187

188188
# 'command_packages' is a list of packages in which commands
189189
# are searched for. The factory for command 'foo' is expected
@@ -1168,6 +1168,7 @@ def _read_field(name: str) -> str | None:
11681168
value = msg[name]
11691169
if value and value != "UNKNOWN":
11701170
return value
1171+
return None
11711172

11721173
def _read_list(name):
11731174
values = msg.get_all(name, None)

setuptools/_distutils/sysconfig.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ def _extant(path):
156156

157157

158158
def _get_python_inc_posix(prefix, spec_prefix, plat_specific):
159-
if IS_PYPY and sys.version_info < (3, 8):
160-
return os.path.join(prefix, 'include')
161159
return (
162160
_get_python_inc_posix_python(plat_specific)
163161
or _extant(_get_python_inc_from_config(plat_specific, spec_prefix))
@@ -246,14 +244,6 @@ def get_python_lib(
246244
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
247245
"""
248246

249-
if IS_PYPY and sys.version_info < (3, 8):
250-
# PyPy-specific schema
251-
if prefix is None:
252-
prefix = PREFIX
253-
if standard_lib:
254-
return os.path.join(prefix, "lib-python", sys.version_info.major)
255-
return os.path.join(prefix, 'site-packages')
256-
257247
early_prefix = prefix
258248

259249
if prefix is None:

0 commit comments

Comments
 (0)