Skip to content

Commit 8494829

Browse files
PavelStishenkovstinner
authored andcommitted
bpo-31955: Fix distutils CCompiler.set_executable() for Unicode (GH-4316)
Fix CCompiler.set_executable() of distutils to handle properly Unicode strings.
1 parent cd66d6d commit 8494829

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Lib/distutils/ccompiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class (via the 'executables' class attribute), but most will have:
160160
self.set_executable(key, args[key])
161161

162162
def set_executable(self, key, value):
163-
if isinstance(value, str):
163+
if isinstance(value, basestring):
164164
setattr(self, key, split_quoted(value))
165165
else:
166166
setattr(self, key, value)

Lib/distutils/tests/test_ccompiler.py

+24
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ def library_option(self, lib):
2424

2525
class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
2626

27+
def test_set_executables(self):
28+
class MyCCompiler(CCompiler):
29+
executables = {'compiler': '', 'compiler_cxx': '', 'linker': ''}
30+
31+
compiler = MyCCompiler()
32+
33+
# set executable as list
34+
compiler.set_executables(compiler=['env', 'OMPI_MPICC=clang', 'mpicc'])
35+
self.assertEqual(compiler.compiler, ['env',
36+
'OMPI_MPICC=clang',
37+
'mpicc'])
38+
39+
# set executable as string
40+
compiler.set_executables(compiler_cxx='env OMPI_MPICXX=clang++ mpicxx')
41+
self.assertEqual(compiler.compiler_cxx, ['env',
42+
'OMPI_MPICXX=clang++',
43+
'mpicxx'])
44+
45+
# set executable as unicode string
46+
compiler.set_executables(linker=u'env OMPI_MPICXX=clang++ mpiCC')
47+
self.assertEqual(compiler.linker, [u'env',
48+
u'OMPI_MPICXX=clang++',
49+
u'mpiCC'])
50+
2751
def test_gen_lib_options(self):
2852
compiler = FakeCompiler()
2953
libdirs = ['lib1', 'lib2']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix CCompiler.set_executable() of distutils to handle properly Unicode strings.

0 commit comments

Comments
 (0)