[Python-checkins] bpo-45020: Do not freeze <pkg>/__init__.py twice. (gh-28635)

ericsnowcurrently webhook-mailer at python.org
Wed Sep 29 14:55:40 EDT 2021

commit: 45ca1c04139300ec0289a32f78c7ac922a4f7b07
branch: main
author: Eric Snow <ericsnowcurrently at gmail.com>
committer: ericsnowcurrently <ericsnowcurrently at gmail.com>
date: 2021-09-29T12:55:35-06:00

bpo-45020: Do not freeze <pkg>/__init__.py twice. (gh-28635)

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.


M Tools/scripts/freeze_modules.py

diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py
index cfc6f7921c974..f7273915b911e 100644
--- a/Tools/scripts/freeze_modules.py
+++ b/Tools/scripts/freeze_modules.py
@@ -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 iter_subs():
                         modname = frozenid.replace(pkgid, pkgname, 1)
                         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()

More information about the Python-checkins mailing list