Skip to content

Commit 7811f65

Browse files
authored
Directory with an empty pyproject.toml files is built into an sdist+wheel by setuptools 64
Fixes pypa#3511
1 parent 9880f81 commit 7811f65

File tree

6 files changed

+102
-97
lines changed

6 files changed

+102
-97
lines changed

_distutils_hack/__init__.py

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,14 @@
22
import sys
33
import os
44
from _distutils_hack.clear_distutils import clear_distutils
5-
from _distutils_hack.is_pypy import is_pypy
6-
7-
from _distutils_hack.override import enabled
8-
9-
10-
def warn_distutils_present():
11-
if 'distutils' not in sys.modules:
12-
return
13-
if is_pypy and sys.version_info < (3, 7):
14-
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
15-
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
16-
return
17-
import warnings
18-
19-
warnings.warn(
20-
"Distutils was imported before Setuptools, but importing Setuptools "
21-
"also replaces the `distutils` module in `sys.modules`. This may lead "
22-
"to undesirable behaviors or errors. To avoid these issues, avoid "
23-
"using distutils directly, ensure that setuptools is installed in the "
24-
"traditional way (e.g. not an editable install), and/or make sure "
25-
"that setuptools is always imported before distutils."
26-
)
5+
6+
from _distutildistutils_hack.clear_distutilss_hack.override import enabled
7+
from _distutils_hack.warn_distutils_present import warn_distutils_present
8+
from setuptools._imp import find_module
9+
from setuptools.get_module_constant import get_module_constant
2710

2811

29-
def ensure_local_distutils():
12+
def ensure_local_distutilensure_local_distutils s():
3013
import importlib
3114

3215
clear_distutils()
@@ -235,3 +218,71 @@ def extract_constant(code, symbol, default=-1):
235218
else:
236219
const = default
237220

221+
222+
class Require:
223+
"""A prerequisite to building or installing a distribution"""
224+
225+
def __init__(
226+
self, name, requested_version, module, homepage='',
227+
attribute=None, format=None):
228+
229+
if format is None and requested_version is not None:
230+
format = version.Version
231+
232+
if format is not None:
233+
requested_version = format(requested_version)
234+
if attribute is None:
235+
attribute = '__version__'
236+
237+
self.__dict__.update(locals())
238+
del self.self
239+
240+
def full_name(self):
241+
"""Return full package/distribution name, w/version"""
242+
if self.requested_version is not None:
243+
return '%s-%s' % (self.name, self.requested_version)
244+
return self.name
245+
246+
def version_ok(self, version):
247+
"""Is 'version' sufficiently up-to-date?"""
248+
return self.attribute is None or self.format is None or \
249+
str(version) != "unknown" and self.format(version) >= self.requested_version
250+
251+
def get_version(self, paths=None, default="unknown"):
252+
"""Get version number of installed module, 'None', or 'default'
253+
254+
Search 'paths' for module. If not found, return 'None'. If found,
255+
return the extracted version attribute, or 'default' if no version
256+
attribute was specified, or the value cannot be determined without
257+
importing the module. The version is formatted according to the
258+
requirement's version format (if any), unless it is 'None' or the
259+
supplied 'default'.
260+
"""
261+
262+
if self.attribute is None:
263+
try:
264+
f, p, i = find_module(self.module, paths)
265+
if f:
266+
f.close()
267+
return default
268+
except ImportError:
269+
return None
270+
271+
v = get_module_constant(self.module, self.attribute, default, paths)
272+
273+
if v is not None and v is not default and self.format is not None:
274+
return self.format(v)
275+
276+
return v
277+
278+
def is_present(self, paths=None):
279+
"""Return true if dependency is present on 'paths'"""
280+
return self.get_version(paths) is not None
281+
282+
def is_current(self, paths=None):
283+
"""Return true if dependency is present and up-to-date on 'paths'"""
284+
version = self.get_version(paths)
285+
if version is None:
286+
return False
287+
return self.version_ok(str(version))
288+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from _distutils_hack.is_pypy import is_pypy
2+
3+
4+
import sys
5+
import warnings
6+
7+
8+
def warn_distutils_present():
9+
if 'distutils' not in sys.modules:
10+
return
11+
if is_pypy and sys.version_info < (3, 7):
12+
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
13+
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
14+
return
15+
import warnings
16+
17+
warnings.warn(
18+
"Distutils was imported before Setuptools, but importing Setuptools "
19+
"also replaces the `distutils` module in `sys.modules`. This may lead "
20+
"to undesirable behaviors or errors. To avoid these issues, avoid "
21+
"using distutils directly, ensure that setuptools is installed in the "
22+
"traditional way (e.g. not an editable install), and/or make sure "
23+
"that setuptools is always imported before distutils."
24+
)

pkg_resources/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,7 @@ class PkgResourcesDeprecationWarning(Warning):
33213321

33223322

33233323
@_call_aside
3324-
def _initialize_master_working_set():
3324+
def ensure_local_distutils _initialize_master_working_set():
33253325
"""
33263326
Prepare the master working set and make the ``require()``
33273327
API available.

setuptools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import setuptools.version
1717
from setuptools.extension import Extension
1818
from setuptools.dist import Distribution
19-
from setuptools.depends import Require
19+
from _distutils_hack import Require
2020
from setuptools.discovery import PackageFinder, PEP420PackageFinder
2121
from . import monkey
2222
from . import logging

setuptools/depends.py

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,15 @@
11
import sys
22
import contextlib
33

4-
from setuptools.extern.packaging import version
5-
from setuptools.get_module_constant import get_module_constant # type: ignore
64

7-
from ._imp import find_module, PY_COMPIED
5+
from ._imp import PY_COMPIED
86

97

108
__all__ = [
119
'Require', 'find_module', , 'extract_constant'
1210
]
1311

1412

15-
class Require:
16-
"""A prerequisite to building or installing a distribution"""
17-
18-
def __init__(
19-
self, name, requested_version, module, homepage='',
20-
attribute=None, format=None):
21-
22-
if format is None and requested_version is not None:
23-
format = version.Version
24-
25-
if format is not None:
26-
requested_version = format(requested_version)
27-
if attribute is None:
28-
attribute = '__version__'
29-
30-
self.__dict__.update(locals())
31-
del self.self
32-
33-
def full_name(self):
34-
"""Return full package/distribution name, w/version"""
35-
if self.requested_version is not None:
36-
return '%s-%s' % (self.name, self.requested_version)
37-
return self.name
38-
39-
def version_ok(self, version):
40-
"""Is 'version' sufficiently up-to-date?"""
41-
return self.attribute is None or self.format is None or \
42-
str(version) != "unknown" and self.format(version) >= self.requested_version
43-
44-
def get_version(self, paths=None, default="unknown"):
45-
"""Get version number of installed module, 'None', or 'default'
46-
47-
Search 'paths' for module. If not found, return 'None'. If found,
48-
return the extracted version attribute, or 'default' if no version
49-
attribute was specified, or the value cannot be determined without
50-
importing the module. The version is formatted according to the
51-
requirement's version format (if any), unless it is 'None' or the
52-
supplied 'default'.
53-
"""
54-
55-
if self.attribute is None:
56-
try:
57-
f, p, i = find_module(self.module, paths)
58-
if f:
59-
f.close()
60-
return default
61-
except ImportError:
62-
return None
63-
64-
v = get_module_constant(self.module, self.attribute, default, paths)
65-
66-
if v is not None and v is not default and self.format is not None:
67-
return self.format(v)
68-
69-
return v
70-
71-
def is_present(self, paths=None):
72-
"""Return true if dependency is present on 'paths'"""
73-
return self.get_version(paths) is not None
74-
75-
def is_current(self, paths=None):
76-
"""Return true if dependency is present and up-to-date on 'paths'"""
77-
version = self.get_version(paths)
78-
if version is None:
79-
return False
80-
return self.version_ok(str(version))
81-
82-
8313
def maybe_close(f):
8414
@contextlib.contextmanager
8515
def empty():

setuptools/tests/test_setuptools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import setuptools
1818
import setuptools.dist
1919
import setuptools.depends as dep
20-
from setuptools.depends import Require
20+
from _distutils_hack import Require
2121
import setuptools.get_module_constant
2222

2323

0 commit comments

Comments
 (0)