Skip to content

Commit 6339339

Browse files
committed
[3.14] gh-162531: clean up stale pyo references in the build and zipimport (GH-162532)
(cherry picked from commit b248bf1)
1 parent 13b1302 commit 6339339

10 files changed

Lines changed: 22 additions & 26 deletions

File tree

‎.gitignore‎

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

‎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: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ def __repr__(self):
288288

289289
# _zip_searchorder defines how we search for a module in the Zip
290290
# archive: we first search for a package __init__, then for
291-
# non-package .pyc, and .py entries. The .pyc entries
292-
# are swapped by initzipimport() if we run in optimized mode. Also,
293-
# '/' is replaced by path_sep there.
291+
# non-package .pyc, and .py entries.
294292
_zip_searchorder = (
295293
(path_sep + '__init__.pyc', True, True),
296294
(path_sep + '__init__.py', False, True),
@@ -616,7 +614,7 @@ def _read_directory(archive):
616614
def _get_decompress_func():
617615
global _importing_zlib
618616
if _importing_zlib:
619-
# Someone has a zlib.py[co] in their Zip file
617+
# Someone has a zlib.pyc in their Zip file
620618
# let's avoid a stack overflow.
621619
_bootstrap._verbose_message('zipimport: zlib UNAVAILABLE')
622620
raise ZipImportError("can't decompress data; zlib not available")
@@ -685,9 +683,9 @@ def _eq_mtime(t1, t2):
685683
return abs(t1 - t2) <= 1
686684

687685

688-
# Given the contents of a .py[co] file, unmarshal the data
689-
# and return the code object. Raises ImportError it the magic word doesn't
690-
# match, or if the recorded .py[co] metadata does not match the source.
686+
# Given the contents of a .pyc file, unmarshal the data
687+
# and return the code object. Raises ImportError if the magic word doesn't
688+
# match, or if the recorded .pyc hash fails validation.
691689
def _unmarshal_code(self, pathname, fullpath, fullname, data):
692690
exc_details = {
693691
'name': fullname,
@@ -761,8 +759,8 @@ def _parse_dostime(d, t):
761759
# or (0, 0) if no source is available.
762760
def _get_mtime_and_size_of_source(self, path):
763761
try:
764-
# strip 'c' or 'o' from *.py[co]
765-
assert path[-1:] in ('c', 'o')
762+
# strip 'c' from *.pyc
763+
assert path.endswith('.pyc')
766764
path = path[:-1]
767765
toc_entry = self._get_files()[path]
768766
# fetch the time stamp of the .py file for comparison
@@ -779,8 +777,8 @@ def _get_mtime_and_size_of_source(self, path):
779777
# contents of the matching .py file, or None if no source
780778
# is available.
781779
def _get_pyc_source(self, path):
782-
# strip 'c' or 'o' from *.py[co]
783-
assert path[-1:] in ('c', 'o')
780+
# strip 'c' from *.pyc
781+
assert path.endswith('.pyc')
784782
path = path[:-1]
785783

786784
try:

‎Mac/BuildScript/build-installer.py‎

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

15591559
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
@@ -2804,7 +2804,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
28042804
do \
28052805
case $$i in \
28062806
*CVS) ;; \
2807-
*.py[co]) ;; \
2807+
*.pyc) ;; \
28082808
*.orig) ;; \
28092809
*~) ;; \
28102810
*) \
@@ -3214,7 +3214,7 @@ TAGS::
32143214
.PHONY: pycremoval
32153215
pycremoval:
32163216
-find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';'
3217-
-find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
3217+
-find $(srcdir) -name '*.pyc' -exec rm -f {} ';'
32183218

32193219
.PHONY: rmtestturds
32203220
rmtestturds:
@@ -3240,7 +3240,7 @@ clean-retain-profile: pycremoval
32403240
find . -name '*.lst' -exec rm -f {} ';'
32413241
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
32423242
find build -name '*.py' -exec rm -f {} ';' || true
3243-
find build -name '*.py[co]' -exec rm -f {} ';' || true
3243+
find build -name '*.pyc' -exec rm -f {} ';' || true
32443244
-rm -f pybuilddir.txt
32453245
-rm -f _bootstrap_python
32463246
-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)