Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Releases before 0.2.0 kept no changelog.
Unreleased
0.2.1 - 2026-10-19
Fixed
- A patcher for a submodule (
urllib.request) could not reach it as an attribute of its package: the import system binds it only after the loader returns, soimport urllib.request; urllib.request.Xin the patcher's module failed ("cannot access submodule ... most likely due to a circular import") and the patch was skipped. The submodule is now bound on its package before its patchers run.
0.2.0 - 2026-10-19
Added
- Hooks registered by entry point: a distribution declares
[project.entry-points.importpatch]with<module> = "<dotted.patcher>". A function is called with the module right after it is imported; a module is called through itsimportpatch(name, module). - The wheel ships
importpatch.pth: installing the package activates the hook in every interpreter of the environment, and uninstalling removes it.IMPORTPATCH_DISABLE=1turns it off. - A module already imported when its hook is registered is patched at once.
importpatch.patches()lists the registry;importpatch.__version__.- Configuration files named
pyimportpatch.cfg: a[module]section per module to patch, one patcher per line,patcher = falseto disable one (an entry point's included). A system file (/etc/pyimportpatch.cfg,%PROGRAMDATA%on Windows, or$IMPORTPATCH_SYSTEM_CONFIG) and then the user's ($XDG_CONFIG_HOME,%APPDATA%on Windows, or$IMPORTPATCH_CONFIG) are applied over the entry points. Each variable may list several files separated byos.pathsep. - MIT license.
Changed
- Modules are found by Python's own finders and their loader is wrapped, so packages,
zip archives and other importable modules are patched; 0.1 found only
.pyfiles and package directories onsys.path. - A patcher that is missing or raises is logged on the
importpatchlogger and skipped; it no longer fails the import of the module it patches (a missing package did) and is no longer ignored silently. A configuration line that cannot be read is logged with the file and line number. .pymodpatch.json(in the working directory, site-packages or~) is no longer read;pyimportpatch.cfgreplaces it, and the user file is not read underpython -Ior-s.rm(target, patcher)isremove(target, patcher=None);remove(target)removes every patcher (in 0.1,rm(target, None)raisedKeyError).- Packaged with
pyproject.toml; the source distribution builds (0.1.3's lacked theVERSIONfile it read). Requires Python 3.9 or later.
Removed
python -m importpatch enable/disable: installing and uninstalling do this.MODULES_TO_PATCH: usepatches(),add()andremove().
Fixed
- After
enable, every interpreter printedNameError: name 'file' is not definedat exit.