From 9d3d8a32db7bd252cdf4179364f92f1bb33b5904 Mon Sep 17 00:00:00 2001 From: Arcadiy Ivanov Date: Thu, 19 Sep 2024 19:45:44 -0400 Subject: [PATCH] a --- .../python/require_libpython_axle_tests.py | 12 ++++++++---- src/main/python/wheel_axle/runtime/_libpython.py | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/integrationtest/python/require_libpython_axle_tests.py b/src/integrationtest/python/require_libpython_axle_tests.py index 6f751fc..af860d8 100644 --- a/src/integrationtest/python/require_libpython_axle_tests.py +++ b/src/integrationtest/python/require_libpython_axle_tests.py @@ -28,6 +28,11 @@ from wheel_axle.runtime._common import PLATLIBDIR +def is_enabled_shared(): + enable_shared = sysconfig.get_config_var("PY_ENABLE_SHARED") or sysconfig.get_config_var("Py_ENABLE_SHARED") + return enable_shared and int(enable_shared) + + class RequireLibPythonAxleTest(InstrumentedAxleTest): def setUp(self) -> None: super().setUp() @@ -35,20 +40,18 @@ def setUp(self) -> None: self.wheel_file = jp(self.test_dir, "test_axle_2_libpython-0.0.1-py3-none-any.whl") def check_libpython_present(self, lib_dir): - enable_shared = sysconfig.get_config_var("PY_ENABLE_SHARED") or sysconfig.get_config_var("Py_ENABLE_SHARED") - if not enable_shared or not int(enable_shared): - return - in_venv = sys.base_exec_prefix != sys.exec_prefix is_user_site = lib_dir.startswith(site.USER_SITE) if in_venv or is_user_site: self.assertTrue(islink(jp(lib_dir, sysconfig.get_config_var("LDLIBRARY")))) self.assertTrue(islink(jp(lib_dir, sysconfig.get_config_var("INSTSONAME")))) + @unittest.skipIf(not is_enabled_shared(), "Python isn't compiled with --enable-shared") def test_install_uninstall(self): self.install(self.wheel_file) self.uninstall(self.wheel_file) + @unittest.skipIf(not is_enabled_shared(), "Python isn't compiled with --enable-shared") def test_verify_install(self): self.install(self.wheel_file) @@ -78,6 +81,7 @@ def test_verify_install(self): self.assertFalse(exists(dist_info)) + @unittest.skipIf(not is_enabled_shared(), "Python isn't compiled with --enable-shared") @unittest.skipIf(sys.base_prefix != sys.prefix, "no user site available under virtualenv") def test_verify_user_install(self): self.install(self.wheel_file, True) diff --git a/src/main/python/wheel_axle/runtime/_libpython.py b/src/main/python/wheel_axle/runtime/_libpython.py index 91df94d..db1d9ea 100644 --- a/src/main/python/wheel_axle/runtime/_libpython.py +++ b/src/main/python/wheel_axle/runtime/_libpython.py @@ -40,7 +40,7 @@ def _install_libpython(self): if not enable_shared or not int(enable_shared): message = ( "The distribution {!r} requires dynamic linking to the `libpython` " - "but current instance of CPython was built without `--shared` enabled." + "but current instance of CPython was built without `--enable-shared`." ) raise InstallationError( message.format(self.dist_meta.project_name) @@ -51,15 +51,15 @@ def _install_libpython(self): # Find libpython library names and locations shared_library_path = LIBDIR - all_ld_library_names = list(n for n in (sysconfig.get_config_var("LDLIBRARY"), - sysconfig.get_config_var("INSTSONAME")) if n) + all_ld_library_names = list(set(n for n in (sysconfig.get_config_var("LDLIBRARY"), + sysconfig.get_config_var("INSTSONAME")) if n)) # There are no libraries to link to if not all_ld_library_names: message = ( "The distribution {!r} requires dynamic linking to the `libpython` " "but was unable to find any libraries declared available in the current installation of CPython, " - "even though it was compiled with '--shared'" + "even though it was compiled with '--enable-shared'" ) raise InstallationError( message.format(self.dist_meta.project_name)