mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-20 19:01:24 +00:00
Re exec the hash seed pin as a module, not by replaying argv[0]
The previous form replayed sys.argv[0] as the script path to run,
which happens to work for a POSIX console script wrapper or a python
dash m invocation, both of which are real, runnable Python content.
It does not work for a uv, pip, or pipx console script launcher on
Windows, which installs as a native executable stub with no such
content, so the interpreter has nothing to open and every affected
command failed outright the moment it tried to pin the seed.
Re execing through the module flag instead never depends on argv[0]
being anything runnable at all, so a launcher stub that is not even a
real file no longer matters, and this now matches the exact
invocation shape the end to end test for this function already
exercised and proved working.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
(cherry picked from commit 6509f609dc)
This commit is contained in:
1 parent
a5957aa6ef
commit
d9d4756506
1 file changed
+11
-1
+11
-1
@@ -522,7 +522,17 @@ def _pin_hash_seed_if_needed() -> None:
|
||||
if "PYTHONHASHSEED" in os.environ or "PYTEST_CURRENT_TEST" in os.environ:
|
||||
return
|
||||
try:
|
||||
os.execvpe(sys.executable, [sys.executable, *sys.argv], {**os.environ, "PYTHONHASHSEED": "0"})
|
||||
# Re-exec as a module (-m graphify) rather than replaying sys.argv[0]
|
||||
# as a script path: that works for a POSIX console-script wrapper or
|
||||
# a `python -m graphify` invocation, but a uv/pip/pipx console-script
|
||||
# launcher on Windows is a native .exe with no .py content, so
|
||||
# `python.exe <that .exe path>` fails outright with "can't open
|
||||
# file" -- every command this function touches (#3779).
|
||||
os.execvpe(
|
||||
sys.executable,
|
||||
[sys.executable, "-m", "graphify", *sys.argv[1:]],
|
||||
{**os.environ, "PYTHONHASHSEED": "0"},
|
||||
)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user