pathtools uses imp to get its internal version into setup.py (which seems like a kinda crazy approach to me, but hey). imp was retired in Python 3.12. There's a formula to replace the bit of it pathtools uses:
import importlib.util
import importlib.machinery
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
which seems like a lot of boilerplate just to get a version number, but hey, you can do that if you like. If it was my project I'd just use some different approach to the version number issue (my own projects have a script for doing version bumps which does this, but I've seen lots of different approaches).
For downstream (we ran into this in Fedora) I've just used a dumb non-upstreamable patch to replace the use of imp to set the version in setup.py with a marker string which we replace with the correct version in the package spec file (since we know what the version is, there).
pathtools uses
imp
to get its internal version intosetup.py
(which seems like a kinda crazy approach to me, but hey).imp
was retired in Python 3.12. There's a formula to replace the bit of it pathtools uses:which seems like a lot of boilerplate just to get a version number, but hey, you can do that if you like. If it was my project I'd just use some different approach to the version number issue (my own projects have a script for doing version bumps which does this, but I've seen lots of different approaches).
For downstream (we ran into this in Fedora) I've just used a dumb non-upstreamable patch to replace the use of
imp
to set theversion
insetup.py
with a marker string which we replace with the correct version in the package spec file (since we know what the version is, there).