Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c00d39e

Browse files
committed
Issue #16047: Fix module exception list and __file__ handling in freeze.
Patch by Meador Inge.
1 parent 3a43403 commit c00d39e

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lib/site.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,17 @@ def setcopyright():
364364
builtins.credits = _sitebuiltins._Printer("credits", """\
365365
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
366366
for supporting Python development. See www.python.org for more information.""")
367-
here = os.path.dirname(os.__file__)
367+
files, dirs = [], []
368+
# Not all modules are required to have a __file__ attribute. See
369+
# PEP 420 for more details.
370+
if hasattr(os, '__file__'):
371+
here = os.path.dirname(os.__file__)
372+
files.extend(["LICENSE.txt", "LICENSE"])
373+
dirs.extend([os.path.join(here, os.pardir), here, os.curdir])
368374
builtins.license = _sitebuiltins._Printer(
369375
"license",
370376
"See http://www.python.org/download/releases/%.5s/license" % sys.version,
371-
["LICENSE.txt", "LICENSE"],
372-
[os.path.join(here, os.pardir), here, os.curdir])
377+
files, dirs)
373378

374379

375380
def sethelper():

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ Tests
137137
Tools/Demos
138138
-----------
139139

140+
- Issue #16047: Fix module exception list and __file__ handling in freeze.
141+
Patch by Meador Inge.
142+
140143
- Issue #11824: Consider ABI tags in freeze. Patch by Meador Inge.
141144

142145
- Issue #20535: PYTHONWARNING no longer affects the run_tests.py script.

Tools/freeze/freeze.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ def main():
365365
else:
366366
mf.load_file(mod)
367367

368+
# Alias "importlib._bootstrap" to "_frozen_importlib" so that the
369+
# import machinery can bootstrap.
370+
mf.modules["_frozen_importlib"] = mf.modules["importlib._bootstrap"]
371+
368372
# Add the main script as either __main__, or the actual module name.
369373
if python_entry_is_main:
370374
mf.run_script(scriptfile)

Tools/freeze/makeconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Write the config.c file
55

6-
never = ['marshal', 'imp', '_ast', '__main__', 'builtins',
6+
never = ['marshal', '_imp', '_ast', '__main__', 'builtins',
77
'sys', 'gc', '_warnings']
88

99
def makeconfig(infp, outfp, modules, with_ifdef=0):

0 commit comments

Comments
 (0)