Skip to content

Commit 08846b2

Browse files
committed
GH-145273: warn when we can't find the standard library
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent 4401f23 commit 08846b2

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A warning is now shown during :ref:`sys-path-init` if it can't find a valid
2+
standard library.

Modules/getpath.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def search_up(prefix, *landmarks, test=isfile):
236236

237237
real_executable_dir = None
238238
platstdlib_dir = None
239+
stdlib_zip = None
239240

240241
# ******************************************************************************
241242
# CALCULATE program_name
@@ -697,12 +698,13 @@ def search_up(prefix, *landmarks, test=isfile):
697698
library_dir = dirname(library)
698699
else:
699700
library_dir = executable_dir
700-
pythonpath.append(joinpath(library_dir, ZIP_LANDMARK))
701+
stdlib_zip = joinpath(library_dir, ZIP_LANDMARK)
701702
elif build_prefix:
702703
# QUIRK: POSIX uses the default prefix when in the build directory
703-
pythonpath.append(joinpath(PREFIX, ZIP_LANDMARK))
704+
stdlib_zip = joinpath(PREFIX, ZIP_LANDMARK)
704705
else:
705-
pythonpath.append(joinpath(base_prefix, ZIP_LANDMARK))
706+
stdlib_zip = joinpath(base_prefix, ZIP_LANDMARK)
707+
pythonpath.append(stdlib_zip)
706708

707709
if os_name == 'nt' and use_environment and winreg:
708710
# QUIRK: Windows also lists paths in the registry. Paths are stored
@@ -767,6 +769,21 @@ def search_up(prefix, *landmarks, test=isfile):
767769
config['module_search_paths_set'] = 1
768770

769771

772+
# ******************************************************************************
773+
# SANITY CHECKS
774+
# ******************************************************************************
775+
776+
# Warn if the standard library is missing
777+
if not stdlib_zip or not isfile(stdlib_zip):
778+
home_hint = f"The Python 'home' directory was set to {home!r}, is this correct?"
779+
if not stdlib_dir or not isdir(stdlib_dir):
780+
hint = home_hint if home else f'sys.prefix is set to {prefix}, is this correct?'
781+
warn('WARN: Could not find the standard library directory! ' + hint)
782+
elif (not platstdlib_dir and not build_prefix) or not isdir(platstdlib_dir):
783+
hint = home_hint if home else f'sys.exec_prefix is set to {exec_prefix}, is this correct?'
784+
warn('WARN: Could not find the platform standard library directory! ' + hint)
785+
786+
770787
# ******************************************************************************
771788
# POSIX prefix/exec_prefix QUIRKS
772789
# ******************************************************************************

0 commit comments

Comments
 (0)