Fix ImportError on Python 3.12+ from removed distutils module#85
Open
BHAitken wants to merge 1 commit into
Open
Fix ImportError on Python 3.12+ from removed distutils module#85BHAitken wants to merge 1 commit into
BHAitken wants to merge 1 commit into
Conversation
distutils was removed from the standard library in Python 3.12. This
broke importing pyffi.utils (and everything that depends on it, e.g.
pyffi.formats.nif) with:
ModuleNotFoundError: No module named 'distutils'
BuildDoc is only used by setup.py's Sphinx documentation build command
and is never touched during normal (non-packaging) use of the library,
so this wraps the import in a try/except and falls back to a plain
object base class when distutils isn't available, rather than failing
the whole module import.
Verified: pyffi.formats.nif.NifFormat imports and parses a real .nif
file cleanly on Python 3.12 with this change, with no workarounds
needed on the caller's side.
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 Python standard library in 3.12, which breaks importingpyffi.utils(and everything that depends on it, e.g.pyffi.formats.nif) with:BuildDocis only used bysetup.py's Sphinx documentation build command and is never touched during normal (non-packaging) use of the library — parsing a NIF/KFM/etc file never needs it. This wraps the import in atry/exceptand falls back to a plainobjectbase class whendistutilsisn't available, rather than failing the whole module import for every user on 3.12+.Test plan
pyffi.formats.nif.NifFormatimports cleanly on Python 3.12 with this change (previously failed at import time).niffile end-to-end afterward (reads header, walks the full block tree, extracts extra-data values) with no workarounds needed on the caller's sidedistutilsis the only remaining Python-3.12-incompatible stdlib reference in the codebase (thetime.clock()issue inobject_models/xml/__init__.pyis already fixed ondevelop, just not yet released to PyPI)