Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FFY00 merged 12 commits intopython:mainfromFFY00:gh-145273
Mar 2, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
08846b2
GH-145273: warn when we can't find the standard library
FFY00Feb 26, 2026
d38285d
Fix test_embed
FFY00Feb 26, 2026
c55803d
Create stdlib dir on test_init_pybuilddir{,_win32}
FFY00Feb 26, 2026
3a67467
Resolve symlinks before file check (needed for Windows)
FFY00Feb 26, 2026
aa6014a
Revert "Resolve symlinks before file check (needed for Windows)"
FFY00Feb 27, 2026
540d965
Fix test.support.PythonSymlink on Windows source builds
FFY00Feb 27, 2026
9cb1166
Fix test_embed by creating expected paths instead of ignoring stderr
FFY00Feb 27, 2026
d8b5280
Don't blindly create paths
FFY00Feb 28, 2026
36e43a7
Fix test_init_is_python_build_with_home
FFY00Feb 28, 2026
8d63f14
Fix test_init_setpythonhome
FFY00Feb 28, 2026
e69cddb
Don't create VPATH subdirs
FFY00Mar 2, 2026
460501d
Create stdlibdir in test_init_pybuilddir_win32
FFY00Mar 2, 2026
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

Some comments aren't visible on the classic Files Changed page.

5 changes: 3 additions & 2 deletionsLib/test/support/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1716,9 +1716,10 @@ def _platform_specific(self):
))

self._env= {k.upper():os.getenv(k)forkinos.environ}
self._env["PYTHONHOME"]=os.path.dirname(self.real)
home=os.path.dirname(self.real)
ifsysconfig.is_python_build():
self._env["PYTHONPATH"]=STDLIB_DIR
home=os.path.join(home,sysconfig.get_config_var('VPATH'))
self._env["PYTHONHOME"]=home
else:
def_platform_specific(self):
pass
Expand Down
30 changes: 26 additions & 4 deletionsLib/test/test_embed.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1491,8 +1491,12 @@ def test_init_setpythonhome(self):
}
self.default_program_name(config)
env= {'TESTHOME':home,'PYTHONPATH':paths_str}
# When running from source, TESTHOME will be the build directory, which
# isn't a valid home unless _is_python_build is set. getpath will then
# fail to find the standard library and show a warning, so we need to
# ignore stderr.
self.check_all_configs("test_init_setpythonhome",config,
api=API_COMPAT,env=env)
api=API_COMPAT,env=env,ignore_stderr=True)

deftest_init_is_python_build_with_home(self):
# Test _Py_path_config._is_python_build configuration (gh-91985)
Expand DownExpand Up@@ -1528,15 +1532,26 @@ def test_init_is_python_build_with_home(self):
'exec_prefix':exec_prefix,
'base_exec_prefix':exec_prefix,
'pythonpath_env':paths_str,
'stdlib_dir':stdlib,
'stdlib_dir':stdlib,# Only correct on _is_python_build==0!
}
# The code above is taken from test_init_setpythonhome()
env= {'TESTHOME':home,'PYTHONPATH':paths_str}

env['NEGATIVE_ISPYTHONBUILD']='1'
config['_is_python_build']=0
# This configuration doesn't set a valid stdlibdir/plststdlibdir because
# with _is_python_build=0 getpath doesn't check for the build directory
# landmarks in PYTHONHOME/Py_SetPythonHome.
# getpath correctly shows a warning, which messes up check_all_configs,
# so we need to ignore stderr.
self.check_all_configs("test_init_is_python_build",config,
api=API_COMPAT,env=env)
api=API_COMPAT,env=env,ignore_stderr=True)

# config['stdlib_dir'] = os.path.join(home, 'Lib')
# FIXME: This test does not check if stdlib_dir is calculated correctly.
# test_init_is_python_build runs the initialization twice,
# setting stdlib_dir in _Py_path_config on the first run, which
# then overrides the stdlib_dir calculation (as of GH-108730).

env['NEGATIVE_ISPYTHONBUILD']='0'
config['_is_python_build']=1
Expand All@@ -1551,8 +1566,14 @@ def test_init_is_python_build_with_home(self):
expected_paths[0]=self.module_search_paths(prefix=prefix)[0]
config.update(prefix=prefix,base_prefix=prefix,
exec_prefix=exec_prefix,base_exec_prefix=exec_prefix)
# This also shows the bad stdlib warning, getpath is run twice. The
# first time with _is_python_build=0, which results in the warning just
# as explained above. However, the second time a valid standard library
# should be found, but the stdlib_dir is cached in _Py_path_config from
# the first run, which ovewrites it, so it also shows the warning.
# Also ignore stderr.
self.check_all_configs("test_init_is_python_build",config,
api=API_COMPAT,env=env)
api=API_COMPAT,env=env,ignore_stderr=True)

defcopy_paths_by_env(self,config):
all_configs=self._get_expected_config()
Expand DownExpand Up@@ -1612,6 +1633,7 @@ def test_init_pybuilddir_win32(self):
prefix=os.path.normpath(os.path.join(tmpdir,vpath))
# The stdlib dir is dirname(executable) + VPATH + 'Lib'
stdlibdir=os.path.normpath(os.path.join(tmpdir,vpath,'Lib'))
os.mkdir(stdlibdir)

filename=os.path.join(tmpdir,'pybuilddir.txt')
withopen(filename,"w",encoding="utf8")asfp:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
A warning is now shown during:ref:`sys-path-init` if it can't find a valid
standard library.
23 changes: 20 additions & 3 deletionsModules/getpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -236,6 +236,7 @@ def search_up(prefix, *landmarks, test=isfile):

real_executable_dir=None
platstdlib_dir=None
stdlib_zip=None

# ******************************************************************************
# CALCULATE program_name
Expand DownExpand Up@@ -697,12 +698,13 @@ def search_up(prefix, *landmarks, test=isfile):
library_dir=dirname(library)
else:
library_dir=executable_dir
pythonpath.append(joinpath(library_dir,ZIP_LANDMARK))
stdlib_zip=joinpath(library_dir,ZIP_LANDMARK)
elifbuild_prefix:
# QUIRK: POSIX uses the default prefix when in the build directory
pythonpath.append(joinpath(PREFIX,ZIP_LANDMARK))
stdlib_zip=joinpath(PREFIX,ZIP_LANDMARK)
else:
pythonpath.append(joinpath(base_prefix,ZIP_LANDMARK))
stdlib_zip=joinpath(base_prefix,ZIP_LANDMARK)
pythonpath.append(stdlib_zip)

ifos_name=='nt'anduse_environmentandwinreg:
# QUIRK: Windows also lists paths in the registry. Paths are stored
Expand DownExpand Up@@ -767,6 +769,21 @@ def search_up(prefix, *landmarks, test=isfile):
config['module_search_paths_set']=1


# ******************************************************************************
# SANITY CHECKS
# ******************************************************************************

# Warn if the standard library is missing
ifnotstdlib_zipornotisfile(stdlib_zip):
home_hint=f"The Python 'home' directory was set to{home!r}, is this correct?"
ifnotstdlib_dirornotisdir(stdlib_dir):
hint=home_hintifhomeelsef'sys.prefix is set to{prefix}, is this correct?'
warn('WARN: Could not find the standard library directory! '+hint)
elif (notplatstdlib_dirandnotbuild_prefix)ornotisdir(platstdlib_dir):
hint=home_hintifhomeelsef'sys.exec_prefix is set to{exec_prefix}, is this correct?'
warn('WARN: Could not find the platform standard library directory! '+hint)


# ******************************************************************************
# POSIX prefix/exec_prefix QUIRKS
# ******************************************************************************
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp