Drop distutils for Python 3.12 compatibility (closes #58)#75
Open
wshlavacek wants to merge 3 commits intoRuleWorld:mainfrom
Open
Drop distutils for Python 3.12 compatibility (closes #58)#75wshlavacek wants to merge 3 commits intoRuleWorld:mainfrom
wshlavacek wants to merge 3 commits intoRuleWorld:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
distutilswas removed from the stdlib in Python 3.12 (and emits aDeprecationWarningbefore then). This PR replaces the two remaining usages with stdlib / setuptools equivalents:bionetgen/core/utils/utils.py:distutils.spawn.find_executable→shutil.which. Same arg, same return semantics (absolute path orNone).bionetgen/simulator/csimulator.py:distutils.ccompiler→ lazysetuptools._distutils.ccompilervia a small_new_ccompiler()helper. The import is deferred toCSimulator.__init__, so plainimport bionetgendoes not requiresetuptoolsat runtime — only instantiatingCSimulator(thecpysimulator path) does, and that path already requires a local CVODE install. Missingsetuptoolsraises a clearBNGCompileErrorwith install guidance.Closes #58.
Note on #59 / #61
Both #59 and #61 are about
from pkg_resources import packagingfailing under newer setuptools / Python. That import was already replaced inc392f2b("CI fixes") and is inmaintoday (line 21 ofbionetgen/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
import bionetgenworks on Python 3.12 with nodistutilsavailablebionetgen run -i ...(CLI path that usesfind_BNG_path→shutil.which) worksCSimulator(...)raises a clearBNGCompileErroron a system without setuptools, and works normally with setuptools installed