Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*.orig
*.pyc
*.pyd
*.pyo
*.rej
*.swp
*.pickle
Expand Down
7 changes: 3 additions & 4 deletions InternalDocs/interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
22 changes: 10 additions & 12 deletions Lib/zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert path.endswith('.pyc')
# # strip 'c' from *.pyc
assert path.endswith('.pyc')

path = path[:-1]

try:
Expand Down
2 changes: 1 addition & 1 deletion Mac/BuildScript/build-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion Mac/Extras.install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Mac/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ install_Python:
case $$i in \
*CVS) ;; \
*.svn) ;; \
*.py[co]) ;; \
*.pyc) ;; \
*.orig) ;; \
*~) ;; \
*idx) \
Expand Down
6 changes: 3 additions & 3 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2887,7 +2887,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
do \
case $$i in \
*CVS) ;; \
*.py[co]) ;; \
*.pyc) ;; \
*.orig) ;; \
*~) ;; \
*) \
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``make pycremoval`` no longer removes legacy ``.pyo`` files outside
``__pycache__`` directories.
Comment on lines +1 to +2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``make pycremoval`` no longer removes legacy ``.pyo`` files outside
``__pycache__`` directories.
Remove obsolete references to ``.pyo`` files from the build, install and
clean scripts. Python has not created ``.pyo`` files since 3.5 (:pep:`488`).

3 changes: 1 addition & 2 deletions PCbuild/rmpyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions Tools/buildbot/clean.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading