From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 2 Apr 2023 22:47:31 +0000 (-0700) Subject: gh-102038: Skip a sometimes unnecessary stat in site.py (#102039) X-Git-Tag: v3.12.0a7~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=385b5d6e091da454c3e0d3f7271acf3af26d8532;p=thirdparty%2FPython%2Fcpython.git gh-102038: Skip a sometimes unnecessary stat in site.py (#102039) --- diff --git a/Lib/site.py b/Lib/site.py index 5c1ff31f4e0f..672fa7b000ad 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -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. diff --git a/Misc/NEWS.d/next/Library/2023-02-19-01-49-46.gh-issue-102038.n3if3D.rst b/Misc/NEWS.d/next/Library/2023-02-19-01-49-46.gh-issue-102038.n3if3D.rst new file mode 100644 index 000000000000..40df20cb5960 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-19-01-49-46.gh-issue-102038.n3if3D.rst @@ -0,0 +1 @@ +Skip a ``stat`` in :mod:`site` if we have already found a ``pyvenv.cfg``