From b120191ec71713ef3e30ccd1e734b141249f418c Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 18 Feb 2023 17:42:51 -0800 Subject: [PATCH 1/2] gh-102038: Skip a sometimes unnecessary stat in site.py --- Lib/site.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index 7faf1c6f6af2231..89ea3d33c9fff38 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. From a0ed09416eb78c04c421195900c80d5a70e7dc78 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 19 Feb 2023 01:49:48 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-02-19-01-49-46.gh-issue-102038.n3if3D.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-02-19-01-49-46.gh-issue-102038.n3if3D.rst 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 000000000000000..40df20cb596049f --- /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``