diff --git a/.gitignore b/.gitignore index 91659803f5faf2e..d68162ed78dde09 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ *.orig *.pyc *.pyd -*.pyo *.rej *.swp *.pickle diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index fa89996aa654291..936a3848d68aa82 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -332,14 +332,13 @@ argument in a special way (like `FORMAT_VALUE` or `MAKE_FUNCTION`). If you make a change here that can affect the output of bytecode that is already in existence and you do not change the magic number, make -sure to delete your old .py(c|o) files! Even though you will end up changing +sure to delete your old .pyc files! Even though you will end up changing the magic number if you change the bytecode, while you are debugging your work you may be changing the bytecode output without constantly bumping up the magic number. This can leave you with stale .pyc files that will not be recreated. -Running `find . -name '*.py[co]' -exec rm -f '{}' +` should delete all .pyc -files you have, forcing new ones to be created and thus allow you test out your -new bytecode properly. Run `make regen-importlib` for updating the +Run `make pycremoval` to delete the .pyc files in your source tree before +testing your new bytecode. Run `make regen-importlib` for updating the bytecode of frozen importlib files. You have to run `make` again after this to recompile the generated C files. diff --git a/Lib/zipimport.py b/Lib/zipimport.py index 09a85f6d7f58e86..28df28433440747 100644 --- a/Lib/zipimport.py +++ b/Lib/zipimport.py @@ -237,9 +237,7 @@ def __repr__(self): # _zip_searchorder defines how we search for a module in the Zip # archive: we first search for a package __init__, then for -# non-package .pyc, and .py entries. The .pyc entries -# are swapped by initzipimport() if we run in optimized mode. Also, -# '/' is replaced by path_sep there. +# non-package .pyc, and .py entries. _zip_searchorder = ( (path_sep + '__init__.pyc', True, True), (path_sep + '__init__.py', False, True), @@ -570,7 +568,7 @@ def _get_zlib_decompress_func(): global _importing_zlib if _importing_zlib: - # Someone has a zlib.py[co] in their Zip file + # Someone has a zlib.pyc in their Zip file # let's avoid a stack overflow. _bootstrap._verbose_message('zipimport: zlib UNAVAILABLE') raise ZipImportError("can't decompress data; zlib not available") @@ -601,7 +599,7 @@ def _get_zstd_decompressor_class(): global _importing_zstd if _importing_zstd: - # Someone has a _zstd.py[co] in their Zip file + # Someone has a _zstd.pyc in their Zip file # let's avoid a stack overflow. _bootstrap._verbose_message("zipimport: zstd UNAVAILABLE") raise ZipImportError("can't decompress data; zstd not available") @@ -705,9 +703,9 @@ def _eq_mtime(t1, t2): return abs(t1 - t2) <= 1 -# Given the contents of a .py[co] file, unmarshal the data -# and return the code object. Raises ImportError it the magic word doesn't -# match, or if the recorded .py[co] metadata does not match the source. +# Given the contents of a .pyc file, unmarshal the data +# and return the code object. Raises ImportError if the magic word doesn't +# match, or if the recorded .pyc hash fails validation. def _unmarshal_code(self, pathname, fullpath, fullname, data): exc_details = { 'name': fullname, @@ -781,8 +779,8 @@ def _parse_dostime(d, t): # or (0, 0) if no source is available. def _get_mtime_and_size_of_source(self, path): try: - # strip 'c' or 'o' from *.py[co] - assert path[-1:] in ('c', 'o') + # strip 'c' from *.pyc + assert path.endswith('.pyc') path = path[:-1] toc_entry = self._get_files()[path] # fetch the time stamp of the .py file for comparison @@ -799,8 +797,8 @@ def _get_mtime_and_size_of_source(self, path): # contents of the matching .py file, or None if no source # is available. def _get_pyc_source(self, path): - # strip 'c' or 'o' from *.py[co] - assert path[-1:] in ('c', 'o') + # strip 'c' from *.pyc + assert path.endswith('.pyc') path = path[:-1] try: diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index c45430243343cc7..1dfa5175cf09e41 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -1553,7 +1553,7 @@ def buildInstaller(): # Zap all compiled files for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): for fn in filenames: - if fn.endswith('.pyc') or fn.endswith('.pyo'): + if fn.endswith('.pyc'): os.unlink(os.path.join(dirpath, fn)) outdir = os.path.join(WORKDIR, 'installer') diff --git a/Mac/Extras.install.py b/Mac/Extras.install.py index 41bfa53d6163079..227aa11cd3dc414 100644 --- a/Mac/Extras.install.py +++ b/Mac/Extras.install.py @@ -15,7 +15,6 @@ def isclean(name): if name.endswith('~'): return 0 if name.endswith('.BAK'): return 0 if name.endswith('.pyc'): return 0 - if name.endswith('.pyo'): return 0 if name.endswith('.orig'): return 0 return 1 diff --git a/Mac/Makefile.in b/Mac/Makefile.in index 32e3a0f55c5d717..dfeafc04ff3bd06 100644 --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -204,7 +204,7 @@ install_Python: case $$i in \ *CVS) ;; \ *.svn) ;; \ - *.py[co]) ;; \ + *.pyc) ;; \ *.orig) ;; \ *~) ;; \ *idx) \ diff --git a/Makefile.pre.in b/Makefile.pre.in index 650838d68286c73..4d0b92e88690e88 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -2887,7 +2887,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c do \ case $$i in \ *CVS) ;; \ - *.py[co]) ;; \ + *.pyc) ;; \ *.orig) ;; \ *~) ;; \ *) \ @@ -3334,7 +3334,7 @@ TAGS:: .PHONY: pycremoval pycremoval: -find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';' - -find $(srcdir) -name '*.py[co]' -exec rm -f {} ';' + -find $(srcdir) -name '*.pyc' -exec rm -f {} ';' .PHONY: rmtestturds rmtestturds: @@ -3362,7 +3362,7 @@ clean-retain-profile: pycremoval find . -name '*.lst' -exec rm -f {} ';' find build -name 'fficonfig.h' -exec rm -f {} ';' || true find build -name '*.py' -exec rm -f {} ';' || true - find build -name '*.py[co]' -exec rm -f {} ';' || true + find build -name '*.pyc' -exec rm -f {} ';' || true -rm -f pybuilddir.txt -rm -f _bootstrap_python -rm -rf web_example web_embed_test python.mjs python.wasm python*.symbols python*.map diff --git a/Misc/NEWS.d/next/Build/2026-11-24-12-10-57.gh-issue-162531.Gw3bY8.rst b/Misc/NEWS.d/next/Build/2026-11-24-12-10-57.gh-issue-162531.Gw3bY8.rst new file mode 100644 index 000000000000000..f8c3c59a7a8f545 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-11-24-12-10-57.gh-issue-162531.Gw3bY8.rst @@ -0,0 +1,2 @@ +``make pycremoval`` no longer removes legacy ``.pyo`` files outside +``__pycache__`` directories. diff --git a/PCbuild/rmpyc.py b/PCbuild/rmpyc.py index 0b58f687729f7e7..410b01220f6e0bd 100644 --- a/PCbuild/rmpyc.py +++ b/PCbuild/rmpyc.py @@ -8,8 +8,7 @@ def deltree(root): npyc = 0 for root, dirs, files in os.walk(root): for name in files: - # to be thorough - if name.endswith(('.pyc', '.pyo')): + if name.endswith('.pyc'): npyc += 1 os.remove(join(root, name)) diff --git a/Tools/buildbot/clean.bat b/Tools/buildbot/clean.bat index fe252a916b1c244..02368a779a2122d 100644 --- a/Tools/buildbot/clean.bat +++ b/Tools/buildbot/clean.bat @@ -9,8 +9,8 @@ echo Deleting build call "%pcbuild%\build.bat" -t Clean -k %* call "%pcbuild%\build.bat" -t Clean -k -d %* -echo Deleting .pyc/.pyo files ... -del /s "%root%\Lib\*.pyc" "%root%\Lib\*.pyo" +echo Deleting .pyc files ... +del /s "%root%\Lib\*.pyc" echo Deleting test leftovers ... rmdir /s /q "%root%\build"