Skip to content

GH-145273: warn when we can't find the standard library#145274

Open
FFY00 wants to merge 7 commits intopython:mainfrom
FFY00:gh-145273
Open

GH-145273: warn when we can't find the standard library#145274
FFY00 wants to merge 7 commits intopython:mainfrom
FFY00:gh-145273

Conversation

@FFY00
Copy link
Member

@FFY00 FFY00 commented Feb 26, 2026

Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00
Copy link
Member Author

FFY00 commented Feb 26, 2026

The main issue with this is that we don't have a way to disable these warnings, which is resolved by GH-145277.

Signed-off-by: Filipe Laíns <lains@riseup.net>
if not stdlib_dir or not isdir(stdlib_dir):
hint = home_hint if home else f'sys.prefix is set to {prefix}, is this correct?'
warn('WARN: Could not find the standard library directory! ' + hint)
elif (not platstdlib_dir and not build_prefix) or not isdir(platstdlib_dir):
Copy link
Member Author

@FFY00 FFY00 Feb 26, 2026

Choose a reason for hiding this comment

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

I fixed the tests, but unless we skip the platstdlib_dir check when running from source, the warning will show up on make, during the pybuilddir.txt generation.

I would prefer to drop the build_prefix check, and instead add -X pathconfig_warnings=0 to the -m sysconfig --generate-posix-vars call in the makefile.

Suggested change
elif (not platstdlib_dir and not build_prefix) or not isdir(platstdlib_dir):
elif not platstdlib_dir or not isdir(platstdlib_dir):

Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00
Copy link
Member Author

FFY00 commented Feb 27, 2026

I was thinking the symlink tests were failing on Windows because the getpath implementation of isdir/isfile didn't follow the link, but looking at the GetFileAttributesW documentation, it says it does follow symlinks.

This means the tests were failing because the symlink target did not exist, but in test_platform,PlatformTest.test_architecture_via_symlink for eg. I cannot see how that's possible? It uses test.support.PythonSymlink, which checks for it.

if os.path.lexists(self.real) and not os.path.exists(self.real):
# App symlink appears to not exist, but we want the
# real executable here anyway
self.real = _winapi.GetModuleFileName(0)

This reverts commit 3a67467.

Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00
Copy link
Member Author

FFY00 commented Feb 27, 2026

Ah, test.support.PythonSymlink is not setting PYTHONHOME correctly. It sets it based on the executable, and it knows this is incorrect on source builds, so it sets PYTHONPATH as a workaround.

self._env["PYTHONHOME"] = os.path.dirname(self.real)
if sysconfig.is_python_build():
self._env["PYTHONPATH"] = STDLIB_DIR

I am not familiar with the build on Windows, but looking at getpath I see that on source builds it set the prefix to VPATH.

@FFY00
Copy link
Member Author

FFY00 commented Feb 27, 2026

It's weird that it needs to set PYTHONHOME though. Did getpath perhaps not resolve the executable symlink in the past?

Anyway, the CI is still finishing, but test_platform has passed, so I guess it is fixed. That's enough debugging through CI for the day 😅

Signed-off-by: Filipe Laíns <lains@riseup.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant