summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-09-25 15:22:59 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-09-25 15:22:59 (GMT)
commitfeaa54f537cf36ca47cefd934a568ff92fe3aa43 (patch)
treee8bfff59c765831dfc151e97dbc068d46e279f80 /Lib/importlib
parentd79ac0fad7d125d081194981e8bd17b1528a8bfc (diff)
downloadcpython-feaa54f537cf36ca47cefd934a568ff92fe3aa43.zip
cpython-feaa54f537cf36ca47cefd934a568ff92fe3aa43.tar.gz
cpython-feaa54f537cf36ca47cefd934a568ff92fe3aa43.tar.bz2
don't depend on __debug__ because it's baked in at freeze time (issue #16046)
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 6697b2b..5c4d2c6 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -411,25 +411,21 @@ SOURCE_SUFFIXES = ['.py'] # _setup() adds .pyw as needed.
DEBUG_BYTECODE_SUFFIXES = ['.pyc']
OPTIMIZED_BYTECODE_SUFFIXES = ['.pyo']
-if __debug__:
- BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
-else:
- BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
def cache_from_source(path, debug_override=None):
"""Given the path to a .py file, return the path to its .pyc/.pyo file.
The .py file does not need to exist; this simply returns the path to the
.pyc/.pyo file calculated as if the .py file were imported. The extension
- will be .pyc unless __debug__ is not defined, then it will be .pyo.
+ will be .pyc unless sys.flags.optimize is non-zero, then it will be .pyo.
If debug_override is not None, then it must be a boolean and is taken as
- the value of __debug__ instead.
+ the value of bool(sys.flags.optimize) instead.
If sys.implementation.cache_tag is None then NotImplementedError is raised.
"""
- debug = __debug__ if debug_override is None else debug_override
+ debug = not sys.flags.optimize if debug_override is None else debug_override
if debug:
suffixes = DEBUG_BYTECODE_SUFFIXES
else:
@@ -1688,10 +1684,15 @@ def _setup(sys_module, _imp_module):
modules, those two modules must be explicitly passed in.
"""
- global _imp, sys
+ global _imp, sys, BYTECODE_SUFFIXES
_imp = _imp_module
sys = sys_module
+ if sys.flags.optimize:
+ BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
+ else:
+ BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
+
for module in (_imp, sys):
if not hasattr(module, '__loader__'):
module.__loader__ = BuiltinImporter