]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45020: Do not freeze <pkg>/__init__.py twice. (gh-28635)
authorEric Snow <ericsnowcurrently@gmail.com>
Wed, 29 Sep 2021 18:55:35 +0000 (12:55 -0600)
committerGitHub <noreply@github.com>
Wed, 29 Sep 2021 18:55:35 +0000 (12:55 -0600)
Currently we're freezing the __init__.py twice, duplicating the built data unnecessarily With this change we do it once. There is no change in runtime behavior.

https://bugs.python.org/issue45020

Tools/scripts/freeze_modules.py

index cfc6f7921c974c69bcc6fba6e38df5bb574438ea..f7273915b911e2c9ab5a33795229deb37059132d 100644 (file)
@@ -221,6 +221,7 @@ def _parse_spec(spec, knownids=None, section=None):
         if ispkg:
             pkgid = frozenid
             pkgname = modname
+            pkgfiles = {pyfile: pkgid}
             def iter_subs():
                 for frozenid, pyfile, ispkg in resolved:
                     assert not knownids or frozenid not in knownids, (frozenid, spec)
@@ -228,6 +229,12 @@ def _parse_spec(spec, knownids=None, section=None):
                         modname = frozenid.replace(pkgid, pkgname, 1)
                     else:
                         modname = frozenid
+                    if pyfile:
+                        if pyfile in pkgfiles:
+                            frozenid = pkgfiles[pyfile]
+                            pyfile = None
+                        elif ispkg:
+                            pkgfiles[pyfile] = frozenid
                     yield frozenid, pyfile, modname, ispkg, section
             submodules = iter_subs()