Skip to content

Commit ea43811

Browse files
[3.15] gh-162531: clean up stale pyo references in the build and zipimport (GH-162532) (#162862)
gh-162531: clean up stale pyo references in the build and zipimport (GH-162532) (cherry picked from commit b248bf1) Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
1 parent a5ba97d commit ea43811

10 files changed

Lines changed: 23 additions & 27 deletions

File tree

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*.orig
1818
*.pyc
1919
*.pyd
20-
*.pyo
2120
*.rej
2221
*.swp
2322
*~

‎InternalDocs/interpreter.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,13 @@ argument in a special way (like `FORMAT_VALUE` or `MAKE_FUNCTION`).
334334

335335
If you make a change here that can affect the output of bytecode that
336336
is already in existence and you do not change the magic number, make
337-
sure to delete your old .py(c|o) files! Even though you will end up changing
337+
sure to delete your old .pyc files! Even though you will end up changing
338338
the magic number if you change the bytecode, while you are debugging your work
339339
you may be changing the bytecode output without constantly bumping up the
340340
magic number. This can leave you with stale .pyc files that will not be
341341
recreated.
342-
Running `find . -name '*.py[co]' -exec rm -f '{}' +` should delete all .pyc
343-
files you have, forcing new ones to be created and thus allow you test out your
344-
new bytecode properly. Run `make regen-importlib` for updating the
342+
Run `make pycremoval` to delete the .pyc files in your source tree before
343+
testing your new bytecode. Run `make regen-importlib` for updating the
345344
bytecode of frozen importlib files. You have to run `make` again after this
346345
to recompile the generated C files.
347346

‎Lib/zipimport.py‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def __repr__(self):
237237

238238
# _zip_searchorder defines how we search for a module in the Zip
239239
# archive: we first search for a package __init__, then for
240-
# non-package .pyc, and .py entries. The .pyc entries
241-
# are swapped by initzipimport() if we run in optimized mode. Also,
242-
# '/' is replaced by path_sep there.
240+
# non-package .pyc, and .py entries.
243241
_zip_searchorder = (
244242
(path_sep + '__init__.pyc', True, True),
245243
(path_sep + '__init__.py', False, True),
@@ -570,7 +568,7 @@ def _get_zlib_decompress_func():
570568

571569
global _importing_zlib
572570
if _importing_zlib:
573-
# Someone has a zlib.py[co] in their Zip file
571+
# Someone has a zlib.pyc in their Zip file
574572
# let's avoid a stack overflow.
575573
_bootstrap._verbose_message('zipimport: zlib UNAVAILABLE')
576574
raise ZipImportError("can't decompress data; zlib not available")
@@ -601,7 +599,7 @@ def _get_zstd_decompressor_class():
601599

602600
global _importing_zstd
603601
if _importing_zstd:
604-
# Someone has a _zstd.py[co] in their Zip file
602+
# Someone has a _zstd.pyc in their Zip file
605603
# let's avoid a stack overflow.
606604
_bootstrap._verbose_message("zipimport: zstd UNAVAILABLE")
607605
raise ZipImportError("can't decompress data; zstd not available")
@@ -705,9 +703,9 @@ def _eq_mtime(t1, t2):
705703
return abs(t1 - t2) <= 1
706704

707705

708-
# Given the contents of a .py[co] file, unmarshal the data
709-
# and return the code object. Raises ImportError it the magic word doesn't
710-
# match, or if the recorded .py[co] metadata does not match the source.
706+
# Given the contents of a .pyc file, unmarshal the data
707+
# and return the code object. Raises ImportError if the magic word doesn't
708+
# match, or if the recorded .pyc hash fails validation.
711709
def _unmarshal_code(self, pathname, fullpath, fullname, data):
712710
exc_details = {
713711
'name': fullname,
@@ -781,8 +779,8 @@ def _parse_dostime(d, t):
781779
# or (0, 0) if no source is available.
782780
def _get_mtime_and_size_of_source(self, path):
783781
try:
784-
# strip 'c' or 'o' from *.py[co]
785-
assert path[-1:] in ('c', 'o')
782+
# strip 'c' from *.pyc
783+
assert path.endswith('.pyc')
786784
path = path[:-1]
787785
toc_entry = self._get_files()[path]
788786
# fetch the time stamp of the .py file for comparison
@@ -799,8 +797,8 @@ def _get_mtime_and_size_of_source(self, path):
799797
# contents of the matching .py file, or None if no source
800798
# is available.
801799
def _get_pyc_source(self, path):
802-
# strip 'c' or 'o' from *.py[co]
803-
assert path[-1:] in ('c', 'o')
800+
# strip 'c' from *.pyc
801+
assert path.endswith('.pyc')
804802
path = path[:-1]
805803

806804
try:

‎Mac/BuildScript/build-installer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ def buildInstaller():
15541554
# Zap all compiled files
15551555
for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')):
15561556
for fn in filenames:
1557-
if fn.endswith('.pyc') or fn.endswith('.pyo'):
1557+
if fn.endswith('.pyc'):
15581558
os.unlink(os.path.join(dirpath, fn))
15591559

15601560
outdir = os.path.join(WORKDIR, 'installer')

‎Mac/Extras.install.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def isclean(name):
1515
if name.endswith('~'): return 0
1616
if name.endswith('.BAK'): return 0
1717
if name.endswith('.pyc'): return 0
18-
if name.endswith('.pyo'): return 0
1918
if name.endswith('.orig'): return 0
2019
return 1
2120

‎Mac/Makefile.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ install_Python:
204204
case $$i in \
205205
*CVS) ;; \
206206
*.svn) ;; \
207-
*.py[co]) ;; \
207+
*.pyc) ;; \
208208
*.orig) ;; \
209209
*~) ;; \
210210
*idx) \

‎Makefile.pre.in‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
28992899
do \
29002900
case $$i in \
29012901
*CVS) ;; \
2902-
*.py[co]) ;; \
2902+
*.pyc) ;; \
29032903
*.orig) ;; \
29042904
*~) ;; \
29052905
*) \
@@ -3329,7 +3329,7 @@ TAGS::
33293329
.PHONY: pycremoval
33303330
pycremoval:
33313331
-find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';'
3332-
-find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
3332+
-find $(srcdir) -name '*.pyc' -exec rm -f {} ';'
33333333

33343334
.PHONY: rmtestturds
33353335
rmtestturds:
@@ -3357,7 +3357,7 @@ clean-retain-profile: pycremoval
33573357
find . -name '*.lst' -exec rm -f {} ';'
33583358
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
33593359
find build -name '*.py' -exec rm -f {} ';' || true
3360-
find build -name '*.py[co]' -exec rm -f {} ';' || true
3360+
find build -name '*.pyc' -exec rm -f {} ';' || true
33613361
-rm -f pybuilddir.txt
33623362
-rm -f _bootstrap_python
33633363
-rm -rf web_example python.mjs python.wasm python*.symbols python*.map
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove obsolete references to ``.pyo`` files from the build, install and
2+
clean scripts. Python has not created ``.pyo`` files since 3.5 (:pep:`488`).

‎PCbuild/rmpyc.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ def deltree(root):
88
npyc = 0
99
for root, dirs, files in os.walk(root):
1010
for name in files:
11-
# to be thorough
12-
if name.endswith(('.pyc', '.pyo')):
11+
if name.endswith('.pyc'):
1312
npyc += 1
1413
os.remove(join(root, name))
1514

‎Tools/buildbot/clean.bat‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ echo Deleting build
99
call "%pcbuild%\build.bat" -t Clean -k %*
1010
call "%pcbuild%\build.bat" -t Clean -k -d %*
1111

12-
echo Deleting .pyc/.pyo files ...
13-
del /s "%root%\Lib\*.pyc" "%root%\Lib\*.pyo"
12+
echo Deleting .pyc files ...
13+
del /s "%root%\Lib\*.pyc"
1414

1515
echo Deleting test leftovers ...
1616
rmdir /s /q "%root%\build"

0 commit comments

Comments
 (0)