Skip to content

Commit 0a1997e

Browse files
committed
Apply setup.py's modernisation to (unused) linker_tests/link_pre_489
Remove pkg_resources, which is deprecated and slated for removal soon: _get_egg_name() has been unused since 2017 anyway. Take Extension from setuptools instead of distutils. Use sysconfig.get_config_var[s]() instead of distutils's wrappers. Override LDSHARED properly in cy_build_ext.run() instead of attempting to alter sysconfig's own config_vars. This linker_tests/link_pre_489/* test is unused anyway, and is present in the codebase for reference only. All of linker_tests/* deserves an overhaul; see also PR #489 and #503.
1 parent 0e05d94 commit 0a1997e

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

linker_tests/link_pre_489/cy_build.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import os
22
import re
33
import sys
4+
import sysconfig
45

56
try:
67
from Cython.Distutils import build_ext
78
except ImportError:
89
from setuptools.command.build_ext import build_ext
910

10-
from distutils.extension import Extension
11-
from distutils.sysconfig import get_config_var, get_config_vars, get_python_lib, get_python_version
12-
from pkg_resources import Distribution
13-
14-
15-
if sys.platform == 'darwin':
16-
config_vars = get_config_vars()
17-
config_vars['LDSHARED'] = config_vars['LDSHARED'].replace('-bundle', '')
18-
config_vars['SHLIB_EXT'] = '.so'
11+
from setuptools.extension import Extension
1912

2013

2114
def is_pip_install():
@@ -45,11 +38,12 @@ def extend_extra_objects(self, objs):
4538

4639
class cy_build_ext(build_ext):
4740

48-
def _get_egg_name(self):
49-
ei_cmd = self.get_finalized_command("egg_info")
50-
return Distribution(
51-
None, None, ei_cmd.egg_name, ei_cmd.egg_version, get_python_version(),
52-
self.distribution.has_ext_modules() and self.plat_name).egg_name()
41+
def run(self):
42+
if sys.platform == 'darwin':
43+
ldshared = os.environ.get('LDSHARED', sysconfig.get_config_var('LDSHARED'))
44+
os.environ['LDSHARED'] = ldshared.replace('-bundle', '')
45+
46+
super().run()
5347

5448
def build_extension(self, ext):
5549

@@ -65,7 +59,7 @@ def build_extension(self, ext):
6559
# @loader_path. This will allow Python packages to find the library
6660
# in the expected place, while still giving enough flexibility to
6761
# external applications to link against the library.
68-
relative_module_path = ext.name.replace(".", os.sep) + get_config_var('EXT_SUFFIX')
62+
relative_module_path = ext.name.replace(".", os.sep) + sysconfig.get_config_var("EXT_SUFFIX")
6963
library_path = os.path.join(
7064
"@rpath", os.path.basename(relative_module_path)
7165
)

0 commit comments

Comments
 (0)