Skip to content

Drop distutils for Python 3.12 compatibility (closes #58)#75

Open
wshlavacek wants to merge 3 commits intoRuleWorld:mainfrom
wshlavacek:py312-compat-distutils
Open

Drop distutils for Python 3.12 compatibility (closes #58)#75
wshlavacek wants to merge 3 commits intoRuleWorld:mainfrom
wshlavacek:py312-compat-distutils

Conversation

@wshlavacek
Copy link
Copy Markdown

Summary

distutils was removed from the stdlib in Python 3.12 (and emits a DeprecationWarning before then). This PR replaces the two remaining usages with stdlib / setuptools equivalents:

  • bionetgen/core/utils/utils.py: distutils.spawn.find_executableshutil.which. Same arg, same return semantics (absolute path or None).
  • bionetgen/simulator/csimulator.py: distutils.ccompiler → lazy setuptools._distutils.ccompiler via a small _new_ccompiler() helper. The import is deferred to CSimulator.__init__, so plain import bionetgen does not require setuptools at runtime — only instantiating CSimulator (the cpy simulator path) does, and that path already requires a local CVODE install. Missing setuptools raises a clear BNGCompileError with install guidance.

Closes #58.

Note on #59 / #61

Both #59 and #61 are about from pkg_resources import packaging failing under newer setuptools / Python. That import was already replaced in c392f2b ("CI fixes") and is in main today (line 21 of bionetgen/main.py). The tickets are still open but the underlying bug is gone — they could be closed at the same time as this PR.

Test plan

  • CI passes on the supported Python versions
  • import bionetgen works on Python 3.12 with no distutils available
  • bionetgen run -i ... (CLI path that uses find_BNG_pathshutil.which) works
  • CSimulator(...) raises a clear BNGCompileError on a system without setuptools, and works normally with setuptools installed

distutils was removed from the stdlib in Python 3.12 and emits a
DeprecationWarning before then. shutil.which is the modern stdlib
equivalent, takes the same argument, and returns the same result
(absolute path or None).
distutils was removed from the stdlib in Python 3.12. setuptools
vendors the same API as setuptools._distutils.

The ccompiler import is wrapped in a lazy _new_ccompiler() helper
called from CSimulator.__init__, so plain 'import bionetgen' does
not require setuptools at runtime — only the cpy simulator path
does, which already requires CVODE installed locally. Missing
setuptools yields a clear BNGCompileError with install guidance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

distutils was deprecated in Python 3.12

1 participant