-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distutils test errors when CXX is not set #79078
Comments
while researching bpo-11191 I cam across 6 additional errors. There is a test in Lib/test/support/init.py def missing_compiler_executable(cmd_names=[]):
"""Check if the compiler components used to build the interpreter exist.
The "elif cmd is None:" is not successful because cmd maybe '' (null string) Initially I thought to change to In: Lib/distutils/sysconfig.py the final bits of customize_compiler is: compiler.set_executables(
preprocessor=cpp,
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared,
compiler_cxx=cxx,
linker_so=ldshared,
linker_exe=cc,
archiver=archiver) the value for cxx come from os.environ, if set, otherwise it comes from get_sys_vars()
If, during the build, CXX was not set - this sets cxx to the null string (''). So the fix is to assign cxx = None when len(cxx) == 0 if 'CXX' in os.environ:
cxx = os.environ['CXX']
if not len(cxx):
cxx = None While this only seems to happen for cxx - maybe this should be extended to all the variables in (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags)? So, ultimately - I choose to go with changing : compiler.set_executables() diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index b71d1d39bc..2e08c4abd2 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -148,7 +148,7 @@ class CCompiler:
if key not in self.executables:
raise ValueError("unknown executable '%s' for class %s" %
(key, self.__class__.__name__))
- self.set_executable(key, kwargs[key])
+ self.set_executable(key, kwargs[key] if len(kwargs[key]) else None) def set_executable(self, key, value):
if isinstance(value, str): Was: Traceback (most recent call last):
File "/data/prj/python/git/python3-3.8/Lib/distutils/tests/test_build_clib.py", line 121, in test_run
ccmd = missing_compiler_executable()
File "/data/prj/python/git/python3-3.8/Lib/test/support/__init__.py", line 2730, in missing_compiler_executable
if spawn.find_executable(cmd[0]) is None:
IndexError: list index out of range ====================================================================== Traceback (most recent call last):
File "/data/prj/python/git/python3-3.8/Lib/distutils/tests/test_build_ext.py", line 62, in test_build_ext
cmd = support.missing_compiler_executable()
File "/data/prj/python/git/python3-3.8/Lib/test/support/__init__.py", line 2730, in missing_compiler_executable
if spawn.find_executable(cmd[0]) is None:
IndexError: list index out of range ====================================================================== Traceback (most recent call last):
File "/data/prj/python/git/python3-3.8/Lib/distutils/tests/test_build_ext.py", line 308, in test_get_outputs
cmd = support.missing_compiler_executable()
File "/data/prj/python/git/python3-3.8/Lib/test/support/__init__.py", line 2730, in missing_compiler_executable
if spawn.find_executable(cmd[0]) is None:
IndexError: list index out of range ====================================================================== Traceback (most recent call last):
File "/data/prj/python/git/python3-3.8/Lib/distutils/tests/test_build_ext.py", line 62, in test_build_ext
cmd = support.missing_compiler_executable()
File "/data/prj/python/git/python3-3.8/Lib/test/support/__init__.py", line 2730, in missing_compiler_executable
if spawn.find_executable(cmd[0]) is None:
IndexError: list index out of range ====================================================================== Traceback (most recent call last):
File "/data/prj/python/git/python3-3.8/Lib/distutils/tests/test_build_ext.py", line 308, in test_get_outputs
cmd = support.missing_compiler_executable()
File "/data/prj/python/git/python3-3.8/Lib/test/support/__init__.py", line 2730, in missing_compiler_executable
if spawn.find_executable(cmd[0]) is None:
IndexError: list index out of range ====================================================================== Traceback (most recent call last):
File "/data/prj/python/git/python3-3.8/Lib/distutils/tests/test_install.py", line 200, in test_record_extensions
cmd = test_support.missing_compiler_executable()
File "/data/prj/python/git/python3-3.8/Lib/test/support/__init__.py", line 2730, in missing_compiler_executable
if spawn.find_executable(cmd[0]) is None:
IndexError: list index out of range |
I'm not sure that the resolution currently suggested, changing compiler.set_executables(), is the right way to go. This change to distutils is a break of backwards compatibility. Though it is a minor change, it could still break existing code. Fixing test.support seems just as good to me in terms of code design, and better in that it is only used internally for our tests. (BTW, instead of `elif cmd is None or (not cmd):`, you can just use `elif not cmd:`.) |
Although - during my testing I saw that the null string "" was not being My reading error was taking None to mean a value was not initialized This is the "ambiguity", at least for myself, that I feel I tracked down. It is "unfortunate" if this breaks backward compatibility - IF the Comments requested.
|
To get a clear understanding of what's going on, I recommend reading the short "Truth Value Testing" section in the docs: |
Thx. So, while "" is not None (i.e., "" is not False), it does test as a Boolean expression as 'False' so the test for None or "" is the same as testing for "" (but not the same as testing for None). I accept your logic - and shall make the change in the test in Lib/test/support/init.py rather than in the assignment in Lib/distutils/ccompiler.py |
Michael, please read more about comparisons[1] and the None object[2]. [1] https://docs.python.org/3/library/stdtypes.html#comparisons |
This issue also still affects Python versions 3.6.15 and 3.7.12 IMHO it would make sense to backport this patch to the 3.6 and 3.7 branches, especially as it only affects one line of code and doesn't seem to affect anything else, but solves the same issue for prior python versions as the merged patch did for 3.8+ |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: