You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update zipimport to support importlib.invalidate_caches() #58883
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-03-08.20:06:43.292>created_at=<Date2012-04-26.17:41:49.735>labels= ['easy', 'type-feature', 'library', '3.10']
title='Update zipimport to support importlib.invalidate_caches()'updated_at=<Date2021-03-08.20:06:46.608>user='https://github.com/brettcannon'
zipimport's finders that get cached in sys.path_importer_cache should probably be updated to support importlib.invalidate_caches() (else the module should get re-implemented in pure Python in importlib and then be tossed).
Moving zipimporter to Python code is harder than it sounds: we don't want to break the ability to ship the standard library itself inside a zipfile.
If you try to move zipimporter to pure Python, you could easily end up with a *very* ugly bootstrapping problem, on par with that already encountered when hacking on importlib._bootstrap.
In fact, the path of least resistance here might actually be to implement zipimporter directly *in* importlib._bootstrap.
The real problem becomes the issue of what zipfile depends on, which complicates bootstrapping. I mean things could go as far as to write a script that takes in anchor points in the stdlib and freezes all code they depend on, but that seems like potential overkill and executable bloat.
But something needs to happen as zipimporter has major shortcomings thanks to to its re-implementation of zip handling (e.g. no ZIP64 support, etc.). Plus no one ever wants to touch that code.
FWIW, the zipimport.c implementation (in 2.7) causes us serious pain when we've got the stdlib in a .zip file and need to update that while there are running python processes (which have cached the central directory of that .zip file but do not also keep a fd to the zip file open or even attempt to stat the file to see if it has changed [racy but it'd still be better than the nothing that is done now]).
@crwilcox Don't know what's left. That's probably part of the work that's left. ;) This issue is so old that it's possibly out-of-date since zipimport got rewritten in pure Python.
crwilcox commented on Feb 28, 2020
crwilcoxmannequin
Mannequin
More actions
That is my thinking as well after rooting around a bit. I unfortunately am not knowledgable enough here to be 100% sure it is complete.
Activity
brettcannon commentedon Apr 26, 2012
zipimport's finders that get cached in sys.path_importer_cache should probably be updated to support importlib.invalidate_caches() (else the module should get re-implemented in pure Python in importlib and then be tossed).
merwok commentedon Apr 26, 2012
zipimport in Python sounds good to me.
brettcannon commentedon May 4, 2012
I should mention I have a version from importers that is probably out-of-date: http://code.google.com/p/importers/source/browse/importers/zip.py
ncoghlan commentedon May 5, 2012
Moving zipimporter to Python code is harder than it sounds: we don't want to break the ability to ship the standard library itself inside a zipfile.
If you try to move zipimporter to pure Python, you could easily end up with a *very* ugly bootstrapping problem, on par with that already encountered when hacking on importlib._bootstrap.
In fact, the path of least resistance here might actually be to implement zipimporter directly *in* importlib._bootstrap.
brettcannon commentedon May 5, 2012
The real problem becomes the issue of what zipfile depends on, which complicates bootstrapping. I mean things could go as far as to write a script that takes in anchor points in the stdlib and freezes all code they depend on, but that seems like potential overkill and executable bloat.
But something needs to happen as zipimporter has major shortcomings thanks to to its re-implementation of zip handling (e.g. no ZIP64 support, etc.). Plus no one ever wants to touch that code.
gpshead commentedon Sep 13, 2013
Brett wrote a pure python zipimporter in http://bugs.python.org/issue17630 :)
FWIW, the zipimport.c implementation (in 2.7) causes us serious pain when we've got the stdlib in a .zip file and need to update that while there are running python processes (which have cached the central directory of that .zip file but do not also keep a fd to the zip file open or even attempt to stat the file to see if it has changed [racy but it'd still be better than the nothing that is done now]).
serhiy-storchaka commentedon Sep 19, 2018
zipimport have been rewritten in pure Python (bpo-25711).
crwilcox commentedon Feb 10, 2020
What work remains to be done for this issue?
brettcannon commentedon Feb 27, 2020
@crwilcox Don't know what's left. That's probably part of the work that's left. ;) This issue is so old that it's possibly out-of-date since zipimport got rewritten in pure Python.
crwilcox commentedon Feb 28, 2020
That is my thinking as well after rooting around a bit. I unfortunately am not knowledgable enough here to be 100% sure it is complete.
brettcannon commentedon Feb 28, 2020
It looks like it hasn't been done, else https://github.com/python/cpython/blob/master/Lib/zipimport.py would have some definition of a invalidate_caches() method. And specifically the finder lacks that method so it can be called by
cpython/Lib/importlib/_bootstrap_external.py
Lines 1245 to 1257 in c705fd1
miss-islington commentedon Mar 8, 2021
New changeset 3abf6f0 by Desmond Cheong in branch 'master':
bpo-14678: Update zipimport to support importlib.invalidate_caches() (GH-24159)
3abf6f0