cpython: 406529adf156 (original) (raw)
Mercurial > cpython
changeset 86213:406529adf156
Issue #19205: Don't import the 're' module in site and sysconfig module to to speed up interpreter start. [#19205]
Christian Heimes christian@cheimes.de | |
---|---|
date | Sat, 12 Oct 2013 00:24:55 +0200 |
parents | fbbf8b160e8d |
children | 2cd1b28d1666 |
files | Lib/site.py Lib/sysconfig.py Lib/test/test_site.py Misc/NEWS |
diffstat | 4 files changed, 24 insertions(+), 4 deletions(-)[+] [-] Lib/site.py 6 Lib/sysconfig.py 4 Lib/test/test_site.py 15 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/site.py +++ b/Lib/site.py @@ -70,7 +70,6 @@ ImportError exception, it is silently ig import sys import os -import re import builtins import _sitebuiltins @@ -436,8 +435,7 @@ def aliasmbcs(): encodings.cache[enc] = encodings.unknown encodings.aliases.aliases[enc] = 'mbcs' - -CONFIG_LINE = re.compile(r'^(?P(\w|[-])+)\s*=\s*(?P.)\s$') +CONFIG_LINE = r'^(?P(\w|[-])+)\s*=\s*(?P.)\s$' def venv(known_paths): global PREFIXES, ENABLE_USER_SITE @@ -460,6 +458,8 @@ def venv(known_paths): ] if candidate_confs:
import re[](#l1.25)
config_line = re.compile(CONFIG_LINE)[](#l1.26) virtual_conf = candidate_confs[0][](#l1.27) system_site = "true"[](#l1.28) with open(virtual_conf) as f:[](#l1.29)
--- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -1,7 +1,6 @@ """Access to Python's configuration information.""" import os -import re import sys from os.path import pardir, realpath @@ -222,6 +221,7 @@ def _parse_makefile(filename, vars=None) """ # Regexes needed for parsing Makefile (and similar syntaxes, # like old-style Setup files).
- import re variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9]+)\s*=\s*(.)") findvar1_rx = re.compile(r"$(([A-Za-z][A-Za-z0-9]))") findvar2_rx = re.compile(r"${([A-Za-z][A-Za-z0-9]*)}") @@ -435,6 +435,7 @@ def parse_config_h(fp, vars=None): """ if vars is None: vars = {}
- import re define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.)\n") undef_rx = re.compile("/[] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n") @@ -658,6 +659,7 @@ def get_platform(): return "%s-%s.%s" % (osname, version, release) elif osname[:6] == "cygwin": osname = "cygwin"
import re[](#l2.31) rel_re = re.compile(r'[\d.]+')[](#l2.32) m = rel_re.match(release)[](#l2.33) if m:[](#l2.34)
--- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -420,5 +420,20 @@ class ImportSideEffectTests(unittest.Tes self.assertEqual(code, 200, msg="Can't find " + url) +class StartupImportTests(unittest.TestCase): +
- def test_startup_imports(self):
# This tests checks which modules are loaded by Python when it[](#l3.10)
# initially starts upon startup.[](#l3.11)
args = [sys.executable, '-I', '-c',[](#l3.12)
'import sys; print(set(sys.modules))'][](#l3.13)
stdout = subprocess.check_output(args)[](#l3.14)
modules = eval(stdout.decode('utf-8'))[](#l3.15)
self.assertIn('site', modules)[](#l3.16)
re_mods = {'re', '_sre', 'sre_compile', 'sre_constants', 'sre_parse'}[](#l3.18)
self.assertFalse(modules.intersection(re_mods))[](#l3.19)
+ + if name == "main": unittest.main()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -36,6 +36,9 @@ Core and Builtins Library ------- +- Issue #19205: Don't import the 're' module in site and sysconfig module to