diff options
author | Steve Dower <steve.dower@microsoft.com> | 2021-07-09 22:45:51 +0100 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2021-07-10 00:55:20 +0100 |
commit | 1eb36f2c1ee3bc42aa386291518bf62a97276155 (patch) | |
tree | c21423c2b84663bccbbf2bd3c0986568fa0712cf | |
parent | 4b64119ab29b1418dc4975ea4212ab38f112c2ab (diff) | |
download | python-setuptools-git-1eb36f2c1ee3bc42aa386291518bf62a97276155.tar.gz |
Fixes #2722: Adds an environment variable SETUPTOOLS_EXT_SUFFIX to override the suffix inferred from the host Python runtime.
-rw-r--r-- | changelog.d/2722.change.rst | 1 | ||||
-rw-r--r-- | setuptools/command/build_ext.py | 12 | ||||
-rw-r--r-- | setuptools/tests/test_build_ext.py | 26 |
3 files changed, 36 insertions, 3 deletions
diff --git a/changelog.d/2722.change.rst b/changelog.d/2722.change.rst new file mode 100644 index 00000000..20bbb66f --- /dev/null +++ b/changelog.d/2722.change.rst @@ -0,0 +1 @@ +Added support for ``SETUPTOOLS_EXT_SUFFIX`` environment variable to override the suffix normally detected from the ``sysconfig`` module. diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 03a72b4f..c59eff8b 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -104,14 +104,20 @@ class build_ext(_build_ext): self.write_stub(package_dir or os.curdir, ext, True) def get_ext_filename(self, fullname): - filename = _build_ext.get_ext_filename(self, fullname) + so_ext = os.getenv('SETUPTOOLS_EXT_SUFFIX') + if so_ext: + filename = os.path.join(*fullname.split('.')) + so_ext + else: + filename = _build_ext.get_ext_filename(self, fullname) + so_ext = get_config_var('EXT_SUFFIX') + if fullname in self.ext_map: ext = self.ext_map[fullname] use_abi3 = getattr(ext, 'py_limited_api') and get_abi3_suffix() if use_abi3: - so_ext = get_config_var('EXT_SUFFIX') filename = filename[:-len(so_ext)] - filename = filename + get_abi3_suffix() + so_ext = get_abi3_suffix() + filename = filename + so_ext if isinstance(ext, Library): fn, ext = os.path.splitext(filename) return self.shlib_compiler.library_filename(fn, libtype) diff --git a/setuptools/tests/test_build_ext.py b/setuptools/tests/test_build_ext.py index b6deebe4..5286358e 100644 --- a/setuptools/tests/test_build_ext.py +++ b/setuptools/tests/test_build_ext.py @@ -1,3 +1,4 @@ +import os import sys import distutils.command.build_ext as orig from distutils.sysconfig import get_config_var @@ -47,6 +48,31 @@ class TestBuildExt: else: assert 'abi3' in res + def test_ext_suffix_override(self): + """ + SETUPTOOLS_EXT_SUFFIX variable always overrides + default extension options. + """ + dist = Distribution() + cmd = build_ext(dist) + cmd.ext_map['for_abi3'] = ext = Extension( + 'for_abi3', + ['s.c'], + # Override shouldn't affect abi3 modules + py_limited_api=True, + ) + # Mock value needed to pass tests + ext._links_to_dynamic = False + expect = cmd.get_ext_filename('for_abi3') + try: + os.environ['SETUPTOOLS_EXT_SUFFIX'] = '.test-suffix' + res = cmd.get_ext_filename('normal') + assert 'normal.test-suffix' == res + res = cmd.get_ext_filename('for_abi3') + assert expect == res + finally: + del os.environ['SETUPTOOLS_EXT_SUFFIX'] + def test_build_ext_config_handling(tmpdir_cwd): files = { |