From e15fcbdb0b6c5fde2d71c7edb667a72e04be2f5c Mon Sep 17 00:00:00 2001 From: Anil Tuncel Date: Fri, 15 Mar 2024 10:32:03 +0100 Subject: [PATCH 1/3] update pkg_resources with importlib.metadata --- share/lib/python/scripts/_binwrapper.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/share/lib/python/scripts/_binwrapper.py b/share/lib/python/scripts/_binwrapper.py index 5fd1ca16d1..7c94a58fc1 100755 --- a/share/lib/python/scripts/_binwrapper.py +++ b/share/lib/python/scripts/_binwrapper.py @@ -7,7 +7,7 @@ import shutil import subprocess import sys -from pkg_resources import working_set +from importlib.metadata import distributions from setuptools.command.build_ext import new_compiler from packaging.version import Version from sysconfig import get_config_vars, get_config_var @@ -63,22 +63,20 @@ def _check_cpp_compiler_version(): def _config_exe(exe_name): """Sets the environment to run the real executable (returned)""" + NRN_PREFIX = None + package_names = ["neuron", "neuron-nightly"] - package_name = "neuron" + # Search for NEURON package installation location using importlib.metadata + for dist in distributions(): + if dist.metadata['Name'] in package_names: + NRN_PREFIX = dist.locate_file('neuron', '.data') + print(f"INFO : Using {dist.metadata['Name']} Package") + break - # determine package to find the install location - if "neuron-nightly" in working_set.by_key: - print("INFO : Using neuron-nightly Package (Developer Version)") - package_name = "neuron-nightly" - elif "neuron" in working_set.by_key: - package_name = "neuron" - else: + if NRN_PREFIX is None: raise RuntimeError("NEURON package not found! Verify PYTHONPATH") - NRN_PREFIX = os.path.join( - working_set.by_key[package_name].location, "neuron", ".data" - ) - os.environ["NEURONHOME"] = os.path.join(NRN_PREFIX, "share/nrn") + os.environ["NEURONHOME"] = os.path.join(NRN_PREFIX, "share", "nrn") os.environ["NRNHOME"] = NRN_PREFIX os.environ["CORENRNHOME"] = NRN_PREFIX os.environ["NRN_PYTHONEXE"] = sys.executable From fa3018756facb4fdf757893d95f3b4f965b80ccc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 09:34:08 +0000 Subject: [PATCH 2/3] Fix formatting --- share/lib/python/scripts/_binwrapper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/lib/python/scripts/_binwrapper.py b/share/lib/python/scripts/_binwrapper.py index 7c94a58fc1..0d3306d652 100755 --- a/share/lib/python/scripts/_binwrapper.py +++ b/share/lib/python/scripts/_binwrapper.py @@ -68,8 +68,8 @@ def _config_exe(exe_name): # Search for NEURON package installation location using importlib.metadata for dist in distributions(): - if dist.metadata['Name'] in package_names: - NRN_PREFIX = dist.locate_file('neuron', '.data') + if dist.metadata["Name"] in package_names: + NRN_PREFIX = dist.locate_file("neuron", ".data") print(f"INFO : Using {dist.metadata['Name']} Package") break From f7ed7b34edea2e113591d3d5cbc5afd6dbc289fa Mon Sep 17 00:00:00 2001 From: Anil Tuncel Date: Fri, 15 Mar 2024 15:04:36 +0100 Subject: [PATCH 3/3] use importlib_metadata backport --- nrn_requirements.txt | 1 + share/lib/python/scripts/_binwrapper.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nrn_requirements.txt b/nrn_requirements.txt index 77ccb32ddc..3f717d108c 100644 --- a/nrn_requirements.txt +++ b/nrn_requirements.txt @@ -1,4 +1,5 @@ wheel +importlib_metadata setuptools setuptools_scm scikit-build diff --git a/share/lib/python/scripts/_binwrapper.py b/share/lib/python/scripts/_binwrapper.py index 0d3306d652..b65db90284 100755 --- a/share/lib/python/scripts/_binwrapper.py +++ b/share/lib/python/scripts/_binwrapper.py @@ -7,7 +7,7 @@ import shutil import subprocess import sys -from importlib.metadata import distributions +from importlib_metadata import distributions from setuptools.command.build_ext import new_compiler from packaging.version import Version from sysconfig import get_config_vars, get_config_var