8000 gh-102038: Skip a sometimes unnecessary stat in site.py (#102039) · python/cpython@385b5d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 385b5d6

Browse files
authored
gh-102038: Skip a sometimes unnecessary stat in site.py (#102039)
1 parent 55decb7 commit 385b5d6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Lib/site.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,20 +492,23 @@ def venv(known_paths):
492492
executable = sys._base_executable = os.environ['__PYVENV_LAUNCHER__']
493493
else:
494494
executable = sys.executable
495-
exe_dir, _ = os.path.split(os.path.abspath(executable))
495+
exe_dir = os.path.dirname(os.path.abspath(executable))
496496
site_prefix = os.path.dirname(exe_dir)
497497
sys._home = None
498498
conf_basename = 'pyvenv.cfg'
499-
candidate_confs = [
500-
conffile for conffile in (
501-
os.path.join(exe_dir, conf_basename),
502-
os.path.join(site_prefix, conf_basename)
499+
candidate_conf = next(
500+
(
501+
conffile for conffile in (
502+
os.path.join(exe_dir, conf_basename),
503+
os.path.join(site_prefix, conf_basename)
503504
)
504-
if os.path.isfile(conffile)
505-
]
505+
if os.path.isfile(conffile)
506+
),
507+
None
508+
)
506509

507-
if candidate_confs:
508-
virtual_conf = candidate_confs[0]
510+
if candidate_conf:
511+
virtual_conf = candidate_conf
509512
system_site = "true"
510513
# Issue 25185: Use UTF-8, as that's what the venv module uses when
511514
# writing the file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip a ``stat`` in :mod:`site` if we have already found a ``pyvenv.cfg``

0 commit comments

Comments
 (0)
0