8000 gh-102038: Skip a sometimes unnecessary stat in site.py by hauntsaninja · Pull Request #102039 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip a ``stat`` in :mod:`site` if we have already found a ``pyvenv.cfg``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With stat you mean the os.path.isfile check that is skipped? I am unfamiliar with the term, but from the news entry alone I did not understand this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, an unnecessary os.path.isfile is skipped. "stat" here comes from the name of the syscall: https://en.wikipedia.org/wiki/Stat_(system_call)

0