Skip to content

Commit 65e1bb7

Browse files
committed
Merge https://github.com/pypa/distutils into distutils-02e9f65ab0
2 parents 0168ac6 + 02e9f65 commit 65e1bb7

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

setuptools/_distutils/command/build_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def finalize_options(self):
220220
# For extensions under Cygwin, Python's library directory must be
221221
# appended to library_dirs
222222
if sys.platform[:6] == 'cygwin':
223-
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
223+
if not sysconfig.python_build:
224224
# building third party extensions
225225
self.library_dirs.append(os.path.join(sys.prefix, "lib",
226226
"python" + get_python_version(),

setuptools/_distutils/command/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def select_scheme(self, name):
470470
"""Sets the install directories by applying the install schemes."""
471471
# it's the caller's problem if they supply a bad name!
472472
if (hasattr(sys, 'pypy_version_info') and
473+
sys.version_info < (3, 8) and
473474
not name.endswith(('_user', '_home'))):
474475
if os.name == 'nt':
475476
name = 'pypy_nt'

setuptools/_distutils/sysconfig.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ def get_python_inc(plat_specific=0, prefix=None):
9999
"""
100100
if prefix is None:
101101
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
102-
if IS_PYPY:
103-
return os.path.join(prefix, 'include')
104-
elif os.name == "posix":
102+
if os.name == "posix":
103+
if IS_PYPY and sys.version_info < (3, 8):
104+
return os.path.join(prefix, 'include')
105105
if python_build:
106106
# Assume the executable is in the build directory. The
107107
# pyconfig.h file should be in the same directory. Since
@@ -113,7 +113,8 @@ def get_python_inc(plat_specific=0, prefix=None):
113113
else:
114114
incdir = os.path.join(get_config_var('srcdir'), 'Include')
115115
return os.path.normpath(incdir)
116-
python_dir = 'python' + get_python_version() + build_flags
116+
implementation = 'pypy' if IS_PYPY else 'python'
117+
python_dir = implementation + get_python_version() + build_flags
117118
return os.path.join(prefix, "include", python_dir)
118119
elif os.name == "nt":
119120
if python_build:
@@ -142,7 +143,8 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
142143
If 'prefix' is supplied, use it instead of sys.base_prefix or
143144
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
144145
"""
145-
if IS_PYPY:
146+
147+
if IS_PYPY and sys.version_info < (3, 8):
146148
# PyPy-specific schema
147149
if prefix is None:
148150
prefix = PREFIX
@@ -164,8 +166,9 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
164166
else:
165167
# Pure Python
166168
libdir = "lib"
169+
implementation = 'pypy' if IS_PYPY else 'python'
167170
libpython = os.path.join(prefix, libdir,
168-
"python" + get_python_version())
171+
implementation + get_python_version())
169172
if standard_lib:
170173
return libpython
171174
else:
@@ -211,10 +214,9 @@ def customize_compiler(compiler):
211214

212215
if 'CC' in os.environ:
213216
newcc = os.environ['CC']
214-
if (sys.platform == 'darwin'
215-
and 'LDSHARED' not in os.environ
217+
if('LDSHARED' not in os.environ
216218
and ldshared.startswith(cc)):
217-
# On OS X, if CC is overridden, use that as the default
219+
# If CC is overridden, use that as the default
218220
# command for LDSHARED as well
219221
ldshared = newcc + ldshared[len(cc):]
220222
cc = newcc
@@ -252,6 +254,9 @@ def customize_compiler(compiler):
252254
linker_exe=cc,
253255
archiver=archiver)
254256

257+
if 'RANLIB' in os.environ and compiler.executables.get('ranlib', None):
258+
compiler.set_executables(ranlib=os.environ['RANLIB'])
259+
255260
compiler.shared_lib_extension = shlib_suffix
256261

257262

setuptools/_distutils/tests/test_sysconfig.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from distutils import sysconfig
1111
from distutils.ccompiler import get_default_compiler
12+
from distutils.unixccompiler import UnixCCompiler
1213
from distutils.tests import support
1314
from test.support import run_unittest, swap_item
1415

@@ -84,9 +85,14 @@ def customize_compiler(self):
8485
# make sure AR gets caught
8586
class compiler:
8687
compiler_type = 'unix'
88+
executables = UnixCCompiler.executables
89+
90+
def __init__(self):
91+
self.exes = {}
8792

8893
def set_executables(self, **kw):
89-
self.exes = kw
94+
for k, v in kw.items():
95+
self.exes[k] = v
9096

9197
sysconfig_vars = {
9298
'AR': 'sc_ar',
@@ -125,6 +131,7 @@ def test_customize_compiler(self):
125131
os.environ['ARFLAGS'] = '--env-arflags'
126132
os.environ['CFLAGS'] = '--env-cflags'
127133
os.environ['CPPFLAGS'] = '--env-cppflags'
134+
os.environ['RANLIB'] = 'env_ranlib'
128135

129136
comp = self.customize_compiler()
130137
self.assertEqual(comp.exes['archiver'],
@@ -145,6 +152,12 @@ def test_customize_compiler(self):
145152
' --env-cppflags'))
146153
self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')
147154

155+
if sys.platform == "darwin":
156+
self.assertEqual(comp.exes['ranlib'],
157+
'env_ranlib')
158+
else:
159+
self.assertTrue('ranlib' not in comp.exes)
160+
148161
del os.environ['AR']
149162
del os.environ['CC']
150163
del os.environ['CPP']
@@ -154,6 +167,7 @@ def test_customize_compiler(self):
154167
del os.environ['ARFLAGS']
155168
del os.environ['CFLAGS']
156169
del os.environ['CPPFLAGS']
170+
del os.environ['RANLIB']
157171

158172
comp = self.customize_compiler()
159173
self.assertEqual(comp.exes['archiver'],
@@ -171,6 +185,7 @@ def test_customize_compiler(self):
171185
self.assertEqual(comp.exes['linker_so'],
172186
'sc_ldshared')
173187
self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')
188+
self.assertTrue('ranlib' not in comp.exes)
174189

175190
def test_parse_makefile_base(self):
176191
self.makefile = TESTFN

setuptools/_distutils/tests/test_unixccompiler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ def gcv(v):
140140
sysconfig.get_config_var = gcv
141141
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
142142

143+
def gcv(v):
144+
if v == 'CC':
145+
return 'gcc -pthread -B /bar'
146+
elif v == 'GNULD':
147+
return 'yes'
148+
sysconfig.get_config_var = gcv
149+
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
150+
143151
# GCC non-GNULD
144152
sys.platform = 'bar'
145153
def gcv(v):
@@ -181,8 +189,8 @@ def gcv(v):
181189
sysconfig.get_config_var = gcv
182190
self.assertEqual(self.cc.rpath_foo(), '-R/foo')
183191

184-
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
185-
def test_osx_cc_overrides_ldshared(self):
192+
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
193+
def test_cc_overrides_ldshared(self):
186194
# Issue #18080:
187195
# ensure that setting CC env variable also changes default linker
188196
def gcv(v):
@@ -202,8 +210,8 @@ def gcvs(*args, _orig=sysconfig.get_config_vars):
202210
sysconfig.customize_compiler(self.cc)
203211
self.assertEqual(self.cc.linker_so[0], 'my_cc')
204212

205-
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
206-
def test_osx_explicit_ldshared(self):
213+
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
214+
def test_explicit_ldshared(self):
207215
# Issue #18080:
208216
# ensure that setting CC env variable does not change
209217
# explicit LDSHARED setting for linker

setuptools/_distutils/unixccompiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* link shared library handled by 'cc -shared'
1414
"""
1515

16-
import os, sys, re
16+
import os, sys, re, shlex
1717

1818
from distutils import sysconfig
1919
from distutils.dep_util import newer
@@ -231,7 +231,7 @@ def runtime_library_dir_option(self, dir):
231231
# this time, there's no way to determine this information from
232232
# the configuration data stored in the Python installation, so
233233
# we use this hack.
234-
compiler = os.path.basename(sysconfig.get_config_var("CC"))
234+
compiler = os.path.basename(shlex.split(sysconfig.get_config_var("CC"))[0])
235235
if sys.platform[:6] == "darwin":
236236
from distutils.util import get_macosx_target_ver, split_version
237237
macosx_target_ver = get_macosx_target_ver()

0 commit comments

Comments
 (0)