Skip to content

Commit b248bf1

Browse files
authored
gh-162531: clean up stale pyo references in the build and zipimport (#162532)
1 parent 6ffa102 commit b248bf1

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
*.pickle

‎InternalDocs/interpreter.md‎

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

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

‎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
@@ -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
@@ -2891,7 +2891,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
28912891
do \
28922892
case $$i in \
28932893
*CVS) ;; \
2894-
*.py[co]) ;; \
2894+
*.pyc) ;; \
28952895
*.orig) ;; \
28962896
*~) ;; \
28972897
*) \
@@ -3360,7 +3360,7 @@ TAGS::
33603360
.PHONY: pycremoval
33613361
pycremoval:
33623362
-find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';'
3363-
-find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
3363+
-find $(srcdir) -name '*.pyc' -exec rm -f {} ';'
33643364

33653365
.PHONY: rmtestturds
33663366
rmtestturds:
@@ -3388,7 +3388,7 @@ clean-retain-profile: pycremoval
33883388
find . -name '*.lst' -exec rm -f {} ';'
33893389
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
33903390
find build -name '*.py' -exec rm -f {} ';' || true
3391-
find build -name '*.py[co]' -exec rm -f {} ';' || true
3391+
find build -name '*.pyc' -exec rm -f {} ';' || true
33923392
-rm -f pybuilddir.txt
33933393
-rm -f _bootstrap_python
33943394
-rm -rf web_example web_embed_test 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)