Skip to content

Commit 7010070

Browse files
committed
Merge main into modelapi-centralize-action-validation
Resolved conflict by combining: - Updated import style (separate lines, shutil instead of distutils) - Added BNGParseError import needed for validate_action method
2 parents fe8a01e + ea60e0a commit 7010070

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

bionetgen/core/utils/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import os, subprocess
2-
from bionetgen.core.exc import BNGParseError, BNGPerlError
3-
from distutils import spawn
1+
import os
2+
import shutil
3+
import subprocess
44

5+
from bionetgen.core.exc import BNGParseError, BNGPerlError
56
from bionetgen.core.utils.logging import BNGLogger
67

78

@@ -679,7 +680,7 @@ def _try_path(candidate_path):
679680
return hit
680681

681682
# 3) On PATH
682-
bng_on_path = spawn.find_executable("BNG2.pl")
683+
bng_on_path = shutil.which("BNG2.pl")
683684
if bng_on_path:
684685
tried.append(bng_on_path)
685686
hit = _try_path(bng_on_path)
@@ -706,7 +707,7 @@ def test_perl(app=None, perl_path=None):
706707
logger.debug("Checking if perl is installed.", loc=f"{__file__} : test_perl()")
707708
# find path to perl binary
708709
if perl_path is None:
709-
perl_path = spawn.find_executable("perl")
710+
perl_path = shutil.which("perl")
710711
if perl_path is None:
711712
raise BNGPerlError
712713
# check if perl is actually working

bionetgen/simulator/csimulator.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
import ctypes, os, tempfile, bionetgen
22
import numpy as np
33

4-
from distutils import ccompiler
54
from .bngsimulator import BNGSimulator
65
from bionetgen.main import BioNetGen
76
from bionetgen.core.exc import BNGCompileError
87

8+
9+
def _new_ccompiler():
10+
"""Return a distutils ccompiler instance, sourced from setuptools.
11+
12+
distutils was removed from the stdlib in Python 3.12; setuptools vendors
13+
the same API as ``setuptools._distutils``. Imported lazily so that
14+
``import bionetgen`` does not require setuptools at runtime — only
15+
instantiating ``CSimulator`` does.
16+
"""
17+
try:
18+
from setuptools._distutils import ccompiler
19+
except ImportError as exc:
20+
raise BNGCompileError(
21+
None,
22+
"CSimulator requires the distutils ccompiler API, which was "
23+
"removed from the stdlib in Python 3.12. Install setuptools "
24+
"(pip install setuptools) to provide it.",
25+
) from exc
26+
return ccompiler.new_compiler()
27+
28+
929
# This allows access to the CLIs config setup
1030
app = BioNetGen()
1131
app.setup()
@@ -164,7 +184,7 @@ def __init__(self, model_file, generate_network=False):
164184
else:
165185
print(f"model format not recognized: {model_file}")
166186
# set compiler
167-
self.compiler = ccompiler.new_compiler()
187+
self.compiler = _new_ccompiler()
168188
self.compiler.add_include_dir(conf.get("cvode_include"))
169189
self.compiler.add_library_dir(conf.get("cvode_lib"))
170190
# compile shared library

0 commit comments

Comments
 (0)