[Python-checkins] closes bpo-40385: Remove Tools/scripts/checkpyc.py (GH-19709)

Ammar Askar webhook-mailer at python.org
Sat Apr 25 00:34:07 EDT 2020


https://github.com/python/cpython/commit/f82807746d26b4c047f7f3115065f20bb63fb5ff
commit: f82807746d26b4c047f7f3115065f20bb63fb5ff
branch: master
author: Ammar Askar <ammar at ammaraskar.com>
committer: GitHub <noreply at github.com>
date: 2020-04-24T23:33:59-05:00
summary:

closes bpo-40385: Remove Tools/scripts/checkpyc.py (GH-19709)

This is one of the few files that has intimate knowledge of the pyc file
format. Since it lacks tests it tends to become outdated fairly quickly.
At present it has been broken since the introduction of PEP 552.

files:
A Misc/NEWS.d/next/Tools-Demos/2020-04-24-21-08-19.bpo-40385.nWIQdq.rst
D Tools/scripts/checkpyc.py
M Tools/scripts/README

diff --git a/Misc/NEWS.d/next/Tools-Demos/2020-04-24-21-08-19.bpo-40385.nWIQdq.rst b/Misc/NEWS.d/next/Tools-Demos/2020-04-24-21-08-19.bpo-40385.nWIQdq.rst
new file mode 100644
index 0000000000000..07d48fd17779e
--- /dev/null
+++ b/Misc/NEWS.d/next/Tools-Demos/2020-04-24-21-08-19.bpo-40385.nWIQdq.rst
@@ -0,0 +1,2 @@
+Removed the checkpyc.py tool. Please see compileall without force mode as a
+potential alternative.
diff --git a/Tools/scripts/README b/Tools/scripts/README
index bee5b0bd9b200..7fc51a10ee902 100644
--- a/Tools/scripts/README
+++ b/Tools/scripts/README
@@ -7,7 +7,6 @@ abitype.py                Converts a C file to use the PEP 384 type definition A
 analyze_dxp.py            Analyzes the result of sys.getdxp()
 byext.py                  Print lines/words/chars stats of files by extension
 byteyears.py              Print product of a file's size and age
-checkpyc.py               Check presence and validity of ".pyc" files
 cleanfuture.py            Fix redundant Python __future__ statements
 combinerefs.py            A helper for analyzing PYTHONDUMPREFS output
 copytime.py               Copy one file's atime and mtime to another
diff --git a/Tools/scripts/checkpyc.py b/Tools/scripts/checkpyc.py
deleted file mode 100755
index bbaa3d1328fe5..0000000000000
--- a/Tools/scripts/checkpyc.py
+++ /dev/null
@@ -1,69 +0,0 @@
-#! /usr/bin/env python3
-# Check that all ".pyc" files exist and are up-to-date
-# Uses module 'os'
-
-import sys
-import os
-from stat import ST_MTIME
-import importlib.util
-
-# PEP 3147 compatibility (PYC Repository Directories)
-cache_from_source = (importlib.util.cache_from_source if sys.implementation.cache_tag
-                     else lambda path: path + 'c')
-
-
-def main():
-    if len(sys.argv) > 1:
-        verbose = (sys.argv[1] == '-v')
-        silent = (sys.argv[1] == '-s')
-    else:
-        verbose = silent = False
-    MAGIC = importlib.util.MAGIC_NUMBER
-    if not silent:
-        print('Using MAGIC word', repr(MAGIC))
-    for dirname in sys.path:
-        try:
-            names = os.listdir(dirname)
-        except OSError:
-            print('Cannot list directory', repr(dirname))
-            continue
-        if not silent:
-            print('Checking ', repr(dirname), '...')
-        for name in sorted(names):
-            if name.endswith('.py'):
-                name = os.path.join(dirname, name)
-                try:
-                    st = os.stat(name)
-                except OSError:
-                    print('Cannot stat', repr(name))
-                    continue
-                if verbose:
-                    print('Check', repr(name), '...')
-                name_c = cache_from_source(name)
-                try:
-                    with open(name_c, 'rb') as f:
-                        magic_str = f.read(4)
-                        mtime_str = f.read(4)
-                except IOError:
-                    print('Cannot open', repr(name_c))
-                    continue
-                if magic_str != MAGIC:
-                    print('Bad MAGIC word in ".pyc" file', end=' ')
-                    print(repr(name_c))
-                    continue
-                mtime = get_long(mtime_str)
-                if mtime in {0, -1}:
-                    print('Bad ".pyc" file', repr(name_c))
-                elif mtime != st[ST_MTIME]:
-                    print('Out-of-date ".pyc" file', end=' ')
-                    print(repr(name_c))
-
-
-def get_long(s):
-    if len(s) != 4:
-        return -1
-    return s[0] + (s[1] << 8) + (s[2] << 16) + (s[3] << 24)
-
-
-if __name__ == '__main__':
-    main()



More information about the Python-checkins mailing list