mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #28637: No longer use re in site.py.
This makes Python startup from a virtual environment a little faster.
This commit is contained in:
commit
b5c349d5ae
1 changed files with 4 additions and 9 deletions
13
Lib/site.py
13
Lib/site.py
|
@ -422,8 +422,6 @@ def enablerlcompleter():
|
||||||
|
|
||||||
sys.__interactivehook__ = register_readline
|
sys.__interactivehook__ = register_readline
|
||||||
|
|
||||||
CONFIG_LINE = r'^(?P<key>(\w|[-_])+)\s*=\s*(?P<value>.*)\s*$'
|
|
||||||
|
|
||||||
def venv(known_paths):
|
def venv(known_paths):
|
||||||
global PREFIXES, ENABLE_USER_SITE
|
global PREFIXES, ENABLE_USER_SITE
|
||||||
|
|
||||||
|
@ -445,19 +443,16 @@ def venv(known_paths):
|
||||||
]
|
]
|
||||||
|
|
||||||
if candidate_confs:
|
if candidate_confs:
|
||||||
import re
|
|
||||||
config_line = re.compile(CONFIG_LINE)
|
|
||||||
virtual_conf = candidate_confs[0]
|
virtual_conf = candidate_confs[0]
|
||||||
system_site = "true"
|
system_site = "true"
|
||||||
# Issue 25185: Use UTF-8, as that's what the venv module uses when
|
# Issue 25185: Use UTF-8, as that's what the venv module uses when
|
||||||
# writing the file.
|
# writing the file.
|
||||||
with open(virtual_conf, encoding='utf-8') as f:
|
with open(virtual_conf, encoding='utf-8') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
if '=' in line:
|
||||||
m = config_line.match(line)
|
key, _, value = line.partition('=')
|
||||||
if m:
|
key = key.strip().lower()
|
||||||
d = m.groupdict()
|
value = value.strip()
|
||||||
key, value = d['key'].lower(), d['value']
|
|
||||||
if key == 'include-system-site-packages':
|
if key == 'include-system-site-packages':
|
||||||
system_site = value.lower()
|
system_site = value.lower()
|
||||||
elif key == 'home':
|
elif key == 'home':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue