Skip to content

Conversation

@geofft
Copy link
Collaborator

@geofft geofft commented Dec 1, 2025

Mostly fixes #380, and also fixes #713 because we prefer the actual
binary path to argv[0].

@geofft geofft added platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform python:3.14 python:3.15 arch:x86_64 and removed python:3.15 labels Dec 1, 2025
@jjhelmus
Copy link
Contributor

jjhelmus commented Dec 2, 2025

Passing the path the the executable via the library variable in getpath.py has a smell as the variable is described as being the path to the dylib/DLL/so. When static linking there is no shared library so I see the logic in passing the path to the binary (as it is a DSO) itself.

@jjhelmus
Copy link
Contributor

jjhelmus commented Dec 2, 2025

With this patch the directory pointed to by home in the pyvenv.cfg is still searched if the library search fails (but it should not fail).

The change from python/cpython#106045 (comment) (below) would update this path to the directory of the base_executable when it exists. I'm somewhat partial to that solution in addition to this change.

@@ -411,6 +412,9 @@ def search_up(prefix, *landmarks, test=isfile):
                             if isfile(candidate):
                                 base_executable = candidate
                                 break
+                if base_executable and isfile(base_executable):
+                    # Update the executable directory to be based on the resolved base executable
+                    executable_dir = real_executable_dir = dirname(base_executable)
             # home key found; stop iterating over lines
             break

@jjhelmus
Copy link
Contributor

jjhelmus commented Dec 2, 2025

I've found following helpful check/reproduce/debug this issue:

./configure --prefix=/example
make -j
make DESTDIR=<some_real_path> install
cd <some_real_path>
./example/bin/python3.14 # can be used to create symlinks/venv/etc 

@jjhelmus jjhelmus closed this Dec 2, 2025
@zanieb
Copy link
Member

zanieb commented Dec 2, 2025

Did you mean to close this?

@jjhelmus jjhelmus reopened this Dec 2, 2025
@jjhelmus
Copy link
Contributor

jjhelmus commented Dec 2, 2025

Did you mean to close this?

Nope, oops

@geofft geofft changed the title Short-term getpath fix Use the symlink-resolved location of Python in getpath on 3.14+ Dec 5, 2025
@geofft geofft marked this pull request as ready for review December 5, 2025 14:35
@geofft
Copy link
Collaborator Author

geofft commented Dec 5, 2025

I think adding both this patch and the one in #903 is a good idea, though even with both patches I would consider it not quite a complete fix.

I've added some test cases based on #380 and #713. The patch in #903 by itself passes the tests for #380 but not the one in #713. (On the other hand the patch in #903 works on 3.11+.)

Getting this patch to work for 3.11-3.13 isn't hard, but I'm not sure if I will get to that today.

Mostly fixes #380, and also fixes #713 because we prefer the actual
binary path to argv[0].
geofft and others added 4 commits December 5, 2025 13:14
Patch CPython to allow venvs to be created from symlinks.
When inside a venv and base_executable is passed available. Use the
resolved path as the executable_dir rather than the one specified by
home in pyvenv.cfg
Comment on lines +303 to +305
# TODO: does not yet work on ARM64
# with self.subTest(msg="weird argv[0]"):
# assertPythonWorks(sys.executable, argv0="/dev/null")
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a part of the skipif?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think you can skipIf a single subTest. You can call self.skipTest("doesn't yet work on arm64"). I probably could have structured this one as a separate test case, though....

@geofft geofft added the ci:skip label Dec 5, 2025
@zanieb
Copy link
Member

zanieb commented Dec 5, 2025

Includes #903?

@jjhelmus
Copy link
Contributor

jjhelmus commented Dec 5, 2025

Includes #903?

Yes, this supersedes #903

@geofft
Copy link
Collaborator Author

geofft commented Dec 5, 2025

Yes, to fix the aarch64 failures.

@geofft geofft merged commit 91c11ac into main Dec 5, 2025
7 of 19 checks passed
@geofft geofft deleted the geofft/getpath branch December 5, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:skip platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

os.execl fails to execute Python Virtualenvs created from links are broken

4 participants