gh-102038: Skip a sometimes unnecessary stat in site.py (#102039)

This commit is contained in:
Shantanu 2023-04-02 15:47:31 -07:00 committed by GitHub
parent 55decb72c4
commit 385b5d6e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -492,20 +492,23 @@ def venv(known_paths):
executable = sys._base_executable = os.environ['__PYVENV_LAUNCHER__']
else:
executable = sys.executable
exe_dir, _ = os.path.split(os.path.abspath(executable))
exe_dir = os.path.dirname(os.path.abspath(executable))
site_prefix = os.path.dirname(exe_dir)
sys._home = None
conf_basename = 'pyvenv.cfg'
candidate_confs = [
conffile for conffile in (
os.path.join(exe_dir, conf_basename),
os.path.join(site_prefix, conf_basename)
candidate_conf = next(
(
conffile for conffile in (
os.path.join(exe_dir, conf_basename),
os.path.join(site_prefix, conf_basename)
)
if os.path.isfile(conffile)
]
if os.path.isfile(conffile)
),
None
)
if candidate_confs:
virtual_conf = candidate_confs[0]
if candidate_conf:
virtual_conf = candidate_conf
system_site = "true"
# Issue 25185: Use UTF-8, as that's what the venv module uses when
# writing the file.

View File

@ -0,0 +1 @@
Skip a ``stat`` in :mod:`site` if we have already found a ``pyvenv.cfg``