From 6a0f8fe195b2f0027b2d86df24d0f8025dfb3587 Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Thu, 24 Oct 2024 13:35:40 -0600 Subject: [PATCH] Fix dll names for FT/debug builds --- .github/workflows/check.yml | 6 ++++-- jpyutil.py | 30 ++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3e07e41..0ca19d6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -34,6 +34,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: + python: ['3.13t'] java: ['8', '11', '17', '21', '23'] steps: - uses: actions/checkout@v4 @@ -45,10 +46,11 @@ jobs: - uses: astral-sh/setup-uv@v3 - run: | - uv python install 3.13t - uv venv --python 3.13t + uv python install ${{ matrix.python }} + uv venv --python ${{ matrix.python }} source .venv/bin/activate uv pip install pip + echo $JAVA_HOME echo PATH=$PATH >> $GITHUB_ENV - run: pip install "setuptools < 72" diff --git a/jpyutil.py b/jpyutil.py index 1f7ede2..ecf008f 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -43,6 +43,7 @@ # This way importing jpyutil does not interfere with logging in other modules logger = logging.getLogger('jpyutil') # Get log level from environment variable JPY_LOG_LEVEL. Default to INFO +os.environ['JPY_LOG_LEVEL'] = 'DEBUG' log_level = os.getenv('JPY_LOG_LEVEL', 'INFO') try: logger.setLevel(getattr(logging, log_level)) @@ -303,18 +304,17 @@ def _find_python_dll_file(fail=False): logger.debug("Searching for Python shared library file") # Prepare list of search directories - search_dirs = [sys.prefix] + installed_base = sysconfig.get_config_var('installed_base') + if installed_base: + search_dirs.append(os.path.join(installed_base, "lib")) + extra_search_dirs = [sysconfig.get_config_var(name) for name in PYTHON_LIB_DIR_CONFIG_VAR_NAMES] for extra_dir in extra_search_dirs: if extra_dir and extra_dir not in search_dirs and os.path.exists(extra_dir): search_dirs.append(extra_dir) - if platform.system() == 'Windows': - extra_search_dirs = _get_existing_subdirs(search_dirs, "DLLs") - search_dirs = extra_search_dirs + search_dirs - multi_arch_sub_dir = sysconfig.get_config_var('multiarchsubdir') if multi_arch_sub_dir: while multi_arch_sub_dir.startswith('/'): @@ -326,18 +326,32 @@ def _find_python_dll_file(fail=False): # Prepare list of possible library file names + # account for Python debug builds + try: + sys.gettotalrefcount() + debug_build = True + except AttributeError: + debug_build = False + + # account for Python 3.13+ with GIL disabled + dll_suffix = '' + if sys.version_info >= (3, 13): + if not sys._is_gil_enabled(): + dll_suffix = 't' + dll_suffix += 'd' if debug_build else '' + vmaj = str(sys.version_info.major) vmin = str(sys.version_info.minor) if platform.system() == 'Windows': - versions = (vmaj + vmin, vmaj, '') + versions = (vmaj + vmin, vmaj, vmaj + vmin + dll_suffix, '') file_names = ['python' + v + '.dll' for v in versions] elif platform.system() == 'Darwin': - versions = (vmaj + "." + vmin, vmaj, '') + versions = (vmaj + "." + vmin, vmaj, vmaj + "." + vmin + dll_suffix, '') file_names = ['libpython' + v + '.dylib' for v in versions] + \ ['libpython' + v + '.so' for v in versions] else: - versions = (vmaj + "." + vmin, vmaj, '') + versions = (vmaj + "." + vmin, vmaj, vmaj + "." + vmin + dll_suffix, '') file_names = ['libpython' + v + '.so' for v in versions] logger.debug("Potential Python shared library file names: %s" % repr(file_names))