blob: dec37f8be1dda6263716fa6d0989025e57b6d532 [file] [log] [blame]
Fred Drake70b014d2001-07-18 18:39:56 +00001"""Provide access to Python's configuration information. The specific
2configuration variables available depend heavily on the platform and
3configuration. The values may be retrieved using
4get_config_var(name), and the list of variables is available via
5get_config_vars().keys(). Additional convenience functions are also
6available.
Greg Ward1190ee31998-12-18 23:46:33 +00007
8Written by: Fred L. Drake, Jr.
9Email: <fdrake@acm.org>
Greg Ward1190ee31998-12-18 23:46:33 +000010"""
11
Greg Ward9ddaaa11999-01-06 14:46:06 +000012import os
13import re
Tarek Ziadé36797272010-07-22 12:50:05 +000014import sys
Greg Ward1190ee31998-12-18 23:46:33 +000015
Tarek Ziadé36797272010-07-22 12:50:05 +000016from .errors import DistutilsPlatformError
Greg Warda0ca3f22000-02-02 00:05:14 +000017
Tarek Ziadé36797272010-07-22 12:50:05 +000018# These are needed in a couple of spots, so just compute them once.
19PREFIX = os.path.normpath(sys.prefix)
20EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
Fred Drakec1ee39a2000-03-09 15:54:52 +000021
Tarek Ziadé36797272010-07-22 12:50:05 +000022# Path to the base directory of the project. On Windows the binary may
23# live in project/PCBuild9. If we're dealing with an x64 Windows build,
24# it'll live in project/PCbuild/amd64.
25project_base = os.path.dirname(os.path.abspath(sys.executable))
26if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
27 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
28# PC/VS7.1
29if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
30 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
31 os.path.pardir))
32# PC/AMD64
33if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
34 project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
35 os.path.pardir))
Tarek Ziadé8b441d02010-01-29 11:46:31 +000036
Tarek Ziadé36797272010-07-22 12:50:05 +000037# python_build: (Boolean) if true, we're either building Python or
38# building an extension with an un-installed Python, so we use
39# different (hard-wired) directories.
40# Setup.local is available for Makefile builds including VPATH builds,
41# Setup.dist is available on Windows
Christian Heimes2202f872008-02-06 14:31:34 +000042def _python_build():
Tarek Ziadé36797272010-07-22 12:50:05 +000043 for fn in ("Setup.dist", "Setup.local"):
44 if os.path.isfile(os.path.join(project_base, "Modules", fn)):
45 return True
46 return False
Christian Heimes2202f872008-02-06 14:31:34 +000047python_build = _python_build()
Fred Drakec916cdc2001-08-02 20:03:12 +000048
Barry Warsaw14d98ac2010-11-24 19:43:47 +000049# Calculate the build qualifier flags if they are defined. Adding the flags
50# to the include and lib directories only makes sense for an installation, not
51# an in-source build.
52build_flags = ''
53try:
54 if not python_build:
55 build_flags = sys.abiflags
56except AttributeError:
57 # It's not a configure-based build, so the sys module doesn't have
58 # this attribute, which is fine.
59 pass
60
Tarek Ziadé36797272010-07-22 12:50:05 +000061def get_python_version():
62 """Return a string containing the major and minor Python version,
63 leaving off the patchlevel. Sample return values could be '1.5'
64 or '2.2'.
65 """
66 return sys.version[:3]
Tarek Ziadéedacea32010-01-29 11:41:03 +000067
Tarek Ziadé36797272010-07-22 12:50:05 +000068
69def get_python_inc(plat_specific=0, prefix=None):
70 """Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000071
72 If 'plat_specific' is false (the default), this is the path to the
73 non-platform-specific header files, i.e. Python.h and so on;
74 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000075 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000076
Greg Wardd38e6f72000-04-10 01:17:49 +000077 If 'prefix' is supplied, use it instead of sys.prefix or
78 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000079 """
Tarek Ziadé36797272010-07-22 12:50:05 +000080 if prefix is None:
81 prefix = plat_specific and EXEC_PREFIX or PREFIX
82 if os.name == "posix":
83 if python_build:
Vinay Sajipae7d7fa2010-09-20 10:29:54 +000084 # Assume the executable is in the build directory. The
85 # pyconfig.h file should be in the same directory. Since
86 # the build directory may not be the source directory, we
87 # must use "srcdir" from the makefile to find the "Include"
88 # directory.
89 base = os.path.dirname(os.path.abspath(sys.executable))
90 if plat_specific:
91 return base
92 else:
93 incdir = os.path.join(get_config_var('srcdir'), 'Include')
94 return os.path.normpath(incdir)
Barry Warsaw14d98ac2010-11-24 19:43:47 +000095 python_dir = 'python' + get_python_version() + build_flags
96 return os.path.join(prefix, "include", python_dir)
Tarek Ziadé36797272010-07-22 12:50:05 +000097 elif os.name == "nt":
98 return os.path.join(prefix, "include")
Tarek Ziadé36797272010-07-22 12:50:05 +000099 elif os.name == "os2":
100 return os.path.join(prefix, "Include")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000101 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000102 raise DistutilsPlatformError(
103 "I don't know where Python installs its C header files "
104 "on platform '%s'" % os.name)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000105
106
Tarek Ziadé36797272010-07-22 12:50:05 +0000107def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
108 """Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +0000109 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +0000110
Fred Drakec1ee39a2000-03-09 15:54:52 +0000111 If 'plat_specific' is true, return the directory containing
112 platform-specific modules, i.e. any module from a non-pure-Python
113 module distribution; otherwise, return the platform-shared library
114 directory. If 'standard_lib' is true, return the directory
115 containing standard Python library modules; otherwise, return the
116 directory for site-specific modules.
117
Greg Wardd38e6f72000-04-10 01:17:49 +0000118 If 'prefix' is supplied, use it instead of sys.prefix or
119 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000120 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000121 if prefix is None:
122 prefix = plat_specific and EXEC_PREFIX or PREFIX
123
124 if os.name == "posix":
125 libpython = os.path.join(prefix,
126 "lib", "python" + get_python_version())
127 if standard_lib:
128 return libpython
Greg Ward7d73b9e2000-03-09 03:16:05 +0000129 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000130 return os.path.join(libpython, "site-packages")
131 elif os.name == "nt":
132 if standard_lib:
133 return os.path.join(prefix, "Lib")
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000134 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000135 if get_python_version() < "2.2":
136 return prefix
137 else:
138 return os.path.join(prefix, "Lib", "site-packages")
Tarek Ziadé36797272010-07-22 12:50:05 +0000139 elif os.name == "os2":
140 if standard_lib:
141 return os.path.join(prefix, "Lib")
142 else:
143 return os.path.join(prefix, "Lib", "site-packages")
Greg Ward7d73b9e2000-03-09 03:16:05 +0000144 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000145 raise DistutilsPlatformError(
146 "I don't know where Python installs its library "
147 "on platform '%s'" % os.name)
148
Ned Deilyfc20d772013-01-31 01:28:23 -0800149
Tarek Ziadé36797272010-07-22 12:50:05 +0000150
151def customize_compiler(compiler):
152 """Do any platform-specific customization of a CCompiler instance.
153
154 Mainly needed on Unix, so we can plug in the information that
155 varies across Unices and is stored in Python's Makefile.
156 """
157 if compiler.compiler_type == "unix":
Ned Deilyfc20d772013-01-31 01:28:23 -0800158 if sys.platform == "darwin":
159 # Perform first-time customization of compiler-related
160 # config vars on OS X now that we know we need a compiler.
161 # This is primarily to support Pythons from binary
162 # installers. The kind and paths to build tools on
163 # the user system may vary significantly from the system
164 # that Python itself was built on. Also the user OS
165 # version and build tools may not support the same set
166 # of CPU architectures for universal builds.
167 global _config_vars
168 if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
169 import _osx_support
170 _osx_support.customize_compiler(_config_vars)
171 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
172
doko@ubuntu.comd5537d02013-03-21 13:21:49 -0700173 (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
Tarek Ziadé36797272010-07-22 12:50:05 +0000174 get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
doko@ubuntu.comd5537d02013-03-21 13:21:49 -0700175 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
Tarek Ziadé36797272010-07-22 12:50:05 +0000176
Ned Deily99377482012-02-10 13:01:08 +0100177 newcc = None
Tarek Ziadé36797272010-07-22 12:50:05 +0000178 if 'CC' in os.environ:
Ned Deilyfc20d772013-01-31 01:28:23 -0800179 cc = os.environ['CC']
Tarek Ziadé36797272010-07-22 12:50:05 +0000180 if 'CXX' in os.environ:
181 cxx = os.environ['CXX']
182 if 'LDSHARED' in os.environ:
183 ldshared = os.environ['LDSHARED']
184 if 'CPP' in os.environ:
185 cpp = os.environ['CPP']
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000186 else:
Tarek Ziadé36797272010-07-22 12:50:05 +0000187 cpp = cc + " -E" # not always
188 if 'LDFLAGS' in os.environ:
189 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
190 if 'CFLAGS' in os.environ:
191 cflags = opt + ' ' + os.environ['CFLAGS']
192 ldshared = ldshared + ' ' + os.environ['CFLAGS']
193 if 'CPPFLAGS' in os.environ:
194 cpp = cpp + ' ' + os.environ['CPPFLAGS']
195 cflags = cflags + ' ' + os.environ['CPPFLAGS']
196 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
197 if 'AR' in os.environ:
198 ar = os.environ['AR']
199 if 'ARFLAGS' in os.environ:
200 archiver = ar + ' ' + os.environ['ARFLAGS']
201 else:
202 archiver = ar + ' ' + ar_flags
203
204 cc_cmd = cc + ' ' + cflags
205 compiler.set_executables(
206 preprocessor=cpp,
207 compiler=cc_cmd,
208 compiler_so=cc_cmd + ' ' + ccshared,
209 compiler_cxx=cxx,
210 linker_so=ldshared,
211 linker_exe=cc,
212 archiver=archiver)
213
doko@ubuntu.comd5537d02013-03-21 13:21:49 -0700214 compiler.shared_lib_extension = shlib_suffix
Tarek Ziadé36797272010-07-22 12:50:05 +0000215
216
217def get_config_h_filename():
218 """Return full pathname of installed pyconfig.h file."""
219 if python_build:
220 if os.name == "nt":
221 inc_dir = os.path.join(project_base, "PC")
222 else:
223 inc_dir = project_base
224 else:
225 inc_dir = get_python_inc(plat_specific=1)
226 if get_python_version() < '2.2':
227 config_h = 'config.h'
228 else:
229 # The name of the config.h file changed in 2.2
230 config_h = 'pyconfig.h'
231 return os.path.join(inc_dir, config_h)
232
Greg Ward1190ee31998-12-18 23:46:33 +0000233
Greg Ward9ddaaa11999-01-06 14:46:06 +0000234def get_makefile_filename():
Tarek Ziadé36797272010-07-22 12:50:05 +0000235 """Return full pathname of installed Makefile from the Python build."""
236 if python_build:
237 return os.path.join(os.path.dirname(sys.executable), "Makefile")
Éric Araujofea2d042011-10-08 01:56:52 +0200238 lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
Barry Warsaw14d98ac2010-11-24 19:43:47 +0000239 config_file = 'config-{}{}'.format(get_python_version(), build_flags)
240 return os.path.join(lib_dir, config_file, 'Makefile')
Greg Ward7d73b9e2000-03-09 03:16:05 +0000241
Tarek Ziadé36797272010-07-22 12:50:05 +0000242
243def parse_config_h(fp, g=None):
244 """Parse a config.h-style file.
245
246 A dictionary containing name/value pairs is returned. If an
247 optional dictionary is passed in as the second argument, it is
248 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000249 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000250 if g is None:
251 g = {}
252 define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
253 undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
254 #
255 while True:
256 line = fp.readline()
257 if not line:
258 break
259 m = define_rx.match(line)
260 if m:
261 n, v = m.group(1, 2)
262 try: v = int(v)
263 except ValueError: pass
264 g[n] = v
265 else:
266 m = undef_rx.match(line)
267 if m:
268 g[m.group(1)] = 0
269 return g
Greg Ward1190ee31998-12-18 23:46:33 +0000270
Greg Wardd283ce72000-09-17 00:53:02 +0000271
272# Regexes needed for parsing Makefile (and similar syntaxes,
273# like old-style Setup files).
274_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
275_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
276_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
277
Greg Ward3fff8d22000-09-15 00:03:13 +0000278def parse_makefile(fn, g=None):
Tarek Ziadé36797272010-07-22 12:50:05 +0000279 """Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000280
281 A dictionary containing name/value pairs is returned. If an
282 optional dictionary is passed in as the second argument, it is
283 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000284 """
Tarek Ziadé36797272010-07-22 12:50:05 +0000285 from distutils.text_file import TextFile
Victor Stinner75d8c5c2010-10-23 17:02:31 +0000286 fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
Tarek Ziadé36797272010-07-22 12:50:05 +0000287
288 if g is None:
289 g = {}
290 done = {}
291 notdone = {}
292
293 while True:
294 line = fp.readline()
295 if line is None: # eof
296 break
297 m = _variable_rx.match(line)
298 if m:
299 n, v = m.group(1, 2)
300 v = v.strip()
301 # `$$' is a literal `$' in make
302 tmpv = v.replace('$$', '')
303
304 if "$" in tmpv:
305 notdone[n] = v
306 else:
307 try:
308 v = int(v)
309 except ValueError:
310 # insert literal `$'
311 done[n] = v.replace('$$', '$')
312 else:
313 done[n] = v
314
Ronald Oussorene8d252d2010-07-23 09:43:17 +0000315 # Variables with a 'PY_' prefix in the makefile. These need to
316 # be made available without that prefix through sysconfig.
317 # Special care is needed to ensure that variable expansion works, even
318 # if the expansion uses the name without a prefix.
319 renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
320
Tarek Ziadé36797272010-07-22 12:50:05 +0000321 # do variable interpolation here
322 while notdone:
323 for name in list(notdone):
324 value = notdone[name]
325 m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
326 if m:
327 n = m.group(1)
328 found = True
329 if n in done:
330 item = str(done[n])
331 elif n in notdone:
332 # get it on a subsequent round
333 found = False
334 elif n in os.environ:
335 # do it like make: fall back to environment
336 item = os.environ[n]
Ronald Oussorene8d252d2010-07-23 09:43:17 +0000337
338 elif n in renamed_variables:
339 if name.startswith('PY_') and name[3:] in renamed_variables:
340 item = ""
341
342 elif 'PY_' + n in notdone:
343 found = False
344
345 else:
346 item = str(done['PY_' + n])
Tarek Ziadé36797272010-07-22 12:50:05 +0000347 else:
348 done[n] = item = ""
349 if found:
350 after = value[m.end():]
351 value = value[:m.start()] + item + after
352 if "$" in after:
353 notdone[name] = value
354 else:
355 try: value = int(value)
356 except ValueError:
357 done[name] = value.strip()
358 else:
359 done[name] = value
360 del notdone[name]
Ronald Oussorene8d252d2010-07-23 09:43:17 +0000361
362 if name.startswith('PY_') \
363 and name[3:] in renamed_variables:
364
365 name = name[3:]
366 if name not in done:
367 done[name] = value
Tarek Ziadé36797272010-07-22 12:50:05 +0000368 else:
369 # bogus variable reference; just drop it since we can't deal
370 del notdone[name]
371
372 fp.close()
373
Antoine Pitroudbec7802010-10-10 09:37:12 +0000374 # strip spurious spaces
375 for k, v in done.items():
376 if isinstance(v, str):
377 done[k] = v.strip()
378
Tarek Ziadé36797272010-07-22 12:50:05 +0000379 # save the results in the global dictionary
380 g.update(done)
381 return g
382
Greg Ward1190ee31998-12-18 23:46:33 +0000383
Greg Wardd283ce72000-09-17 00:53:02 +0000384def expand_makefile_vars(s, vars):
Tarek Ziadé36797272010-07-22 12:50:05 +0000385 """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000386 'string' according to 'vars' (a dictionary mapping variable names to
387 values). Variables not present in 'vars' are silently expanded to the
388 empty string. The variable values in 'vars' should not contain further
389 variable expansions; if 'vars' is the output of 'parse_makefile()',
390 you're fine. Returns a variable-expanded version of 's'.
391 """
392
393 # This algorithm does multiple expansion, so if vars['foo'] contains
394 # "${bar}", it will expand ${foo} to ${bar}, and then expand
395 # ${bar}... and so forth. This is fine as long as 'vars' comes from
396 # 'parse_makefile()', which takes care of such expansions eagerly,
397 # according to make's variable expansion semantics.
398
Collin Winter5b7e9d72007-08-30 03:52:21 +0000399 while True:
Greg Wardd283ce72000-09-17 00:53:02 +0000400 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
401 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000402 (beg, end) = m.span()
403 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
404 else:
405 break
406 return s
Tarek Ziadé36797272010-07-22 12:50:05 +0000407
408
409_config_vars = None
410
411def _init_posix():
412 """Initialize the module as appropriate for POSIX systems."""
413 g = {}
414 # load the installed Makefile:
415 try:
416 filename = get_makefile_filename()
417 parse_makefile(filename, g)
418 except IOError as msg:
419 my_msg = "invalid Python installation: unable to open %s" % filename
420 if hasattr(msg, "strerror"):
421 my_msg = my_msg + " (%s)" % msg.strerror
422
423 raise DistutilsPlatformError(my_msg)
424
425 # load the installed pyconfig.h:
426 try:
427 filename = get_config_h_filename()
Brett Cannon5c035c02010-10-29 22:36:08 +0000428 with open(filename) as file:
429 parse_config_h(file, g)
Tarek Ziadé36797272010-07-22 12:50:05 +0000430 except IOError as msg:
431 my_msg = "invalid Python installation: unable to open %s" % filename
432 if hasattr(msg, "strerror"):
433 my_msg = my_msg + " (%s)" % msg.strerror
434
435 raise DistutilsPlatformError(my_msg)
436
Tarek Ziadé36797272010-07-22 12:50:05 +0000437 # On AIX, there are wrong paths to the linker scripts in the Makefile
438 # -- these paths are relative to the Python source, but when installed
439 # the scripts are in another directory.
440 if python_build:
441 g['LDSHARED'] = g['BLDSHARED']
442
443 elif get_python_version() < '2.1':
444 # The following two branches are for 1.5.2 compatibility.
445 if sys.platform == 'aix4': # what about AIX 3.x ?
446 # Linker script is in the config directory, not in Modules as the
447 # Makefile says.
448 python_lib = get_python_lib(standard_lib=1)
449 ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
450 python_exp = os.path.join(python_lib, 'config', 'python.exp')
451
452 g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
453
454 global _config_vars
455 _config_vars = g
456
457
458def _init_nt():
459 """Initialize the module as appropriate for NT"""
460 g = {}
461 # set basic install directories
462 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
463 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
464
465 # XXX hmmm.. a normal install puts include files here
466 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
467
468 g['SO'] = '.pyd'
doko@ubuntu.comd5537d02013-03-21 13:21:49 -0700469 g['EXT_SUFFIX'] = '.pyd'
Tarek Ziadé36797272010-07-22 12:50:05 +0000470 g['EXE'] = ".exe"
471 g['VERSION'] = get_python_version().replace(".", "")
472 g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
473
474 global _config_vars
475 _config_vars = g
476
477
Tarek Ziadé36797272010-07-22 12:50:05 +0000478def _init_os2():
479 """Initialize the module as appropriate for OS/2"""
480 g = {}
481 # set basic install directories
482 g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
483 g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
484
485 # XXX hmmm.. a normal install puts include files here
486 g['INCLUDEPY'] = get_python_inc(plat_specific=0)
487
488 g['SO'] = '.pyd'
doko@ubuntu.comd5537d02013-03-21 13:21:49 -0700489 g['EXT_SUFFIX'] = '.pyd'
Tarek Ziadé36797272010-07-22 12:50:05 +0000490 g['EXE'] = ".exe"
491
492 global _config_vars
493 _config_vars = g
494
495
496def get_config_vars(*args):
497 """With no arguments, return a dictionary of all configuration
498 variables relevant for the current platform. Generally this includes
499 everything needed to build extensions and install both pure modules and
500 extensions. On Unix, this means every variable defined in Python's
501 installed Makefile; on Windows and Mac OS it's a much smaller set.
502
503 With arguments, return a list of values that result from looking up
504 each argument in the configuration variable dictionary.
505 """
506 global _config_vars
507 if _config_vars is None:
508 func = globals().get("_init_" + os.name)
509 if func:
510 func()
511 else:
512 _config_vars = {}
513
514 # Normalized versions of prefix and exec_prefix are handy to have;
515 # in fact, these are the standard versions used most places in the
516 # Distutils.
517 _config_vars['prefix'] = PREFIX
518 _config_vars['exec_prefix'] = EXEC_PREFIX
519
520 # Convert srcdir into an absolute path if it appears necessary.
521 # Normally it is relative to the build directory. However, during
522 # testing, for example, we might be running a non-installed python
523 # from a different directory.
524 if python_build and os.name == "posix":
525 base = os.path.dirname(os.path.abspath(sys.executable))
526 if (not os.path.isabs(_config_vars['srcdir']) and
527 base != os.getcwd()):
528 # srcdir is relative and we are not in the same directory
529 # as the executable. Assume executable is in the build
530 # directory and make srcdir absolute.
531 srcdir = os.path.join(base, _config_vars['srcdir'])
532 _config_vars['srcdir'] = os.path.normpath(srcdir)
533
Ned Deilyfc20d772013-01-31 01:28:23 -0800534 # OS X platforms require special customization to handle
535 # multi-architecture, multi-os-version installers
Tarek Ziadé36797272010-07-22 12:50:05 +0000536 if sys.platform == 'darwin':
Ned Deilyfc20d772013-01-31 01:28:23 -0800537 import _osx_support
538 _osx_support.customize_config_vars(_config_vars)
Tarek Ziadé36797272010-07-22 12:50:05 +0000539
540 if args:
541 vals = []
542 for name in args:
543 vals.append(_config_vars.get(name))
544 return vals
545 else:
546 return _config_vars
547
548def get_config_var(name):
549 """Return the value of a single variable using the dictionary
550 returned by 'get_config_vars()'. Equivalent to
551 get_config_vars().get(name)
552 """
553 return get_config_vars().get(name)