blob: 4a8629e6bd31bd523527341f07ec242f3e1a569d [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>
Tarek Ziadéedacea32010-01-29 11:41:03 +000010
11**This module has been moved out of Distutils and will be removed from
Tarek Ziadébd797682010-02-02 23:16:13 +000012Python in the next version (3.3)**
Greg Ward1190ee31998-12-18 23:46:33 +000013"""
14
Greg Ward82d71ca2000-06-03 00:44:30 +000015__revision__ = "$Id$"
Greg Ward1190ee31998-12-18 23:46:33 +000016
Guido van Rossum63236cf2007-05-25 18:39:29 +000017import io
Greg Ward9ddaaa11999-01-06 14:46:06 +000018import os
19import re
Tarek Ziadéedacea32010-01-29 11:41:03 +000020from warnings import warn
Greg Ward1190ee31998-12-18 23:46:33 +000021
Tarek Ziadéedacea32010-01-29 11:41:03 +000022from distutils.errors import DistutilsPlatformError
Greg Warda0ca3f22000-02-02 00:05:14 +000023
Tarek Ziadéedacea32010-01-29 11:41:03 +000024# importing sysconfig from Lib
25# to avoid this module to shadow it
26_sysconfig = __import__('sysconfig')
Fred Drakec1ee39a2000-03-09 15:54:52 +000027
Tarek Ziadé8b441d02010-01-29 11:46:31 +000028# names defined here to keep backward compatibility
29# for APIs that were relocated
30get_python_version = _sysconfig.get_python_version
31get_config_h_filename = _sysconfig.get_config_h_filename
32parse_config_h = _sysconfig.parse_config_h
33get_config_vars = _sysconfig.get_config_vars
34get_config_var = _sysconfig.get_config_var
35from distutils.ccompiler import customize_compiler
36
Tarek Ziadéedacea32010-01-29 11:41:03 +000037_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
38 "Use the APIs provided by the sysconfig module instead")
Christian Heimes255f53b2007-12-08 15:33:56 +000039
Tarek Ziadéedacea32010-01-29 11:41:03 +000040def _get_project_base():
41 return _sysconfig._PROJECT_BASE
42
43project_base = _get_project_base()
44
45class _DeprecatedBool(int):
46 def __nonzero__(self):
47 warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
48 return super(_DeprecatedBool, self).__nonzero__()
49
Christian Heimes2202f872008-02-06 14:31:34 +000050def _python_build():
Tarek Ziadéedacea32010-01-29 11:41:03 +000051 return _DeprecatedBool(_sysconfig.is_python_build())
52
Christian Heimes2202f872008-02-06 14:31:34 +000053python_build = _python_build()
Fred Drakec916cdc2001-08-02 20:03:12 +000054
Greg Wardd38e6f72000-04-10 01:17:49 +000055def get_python_inc(plat_specific=0, prefix=None):
Tarek Ziadéedacea32010-01-29 11:41:03 +000056 """This function is deprecated.
57
58 Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000059
60 If 'plat_specific' is false (the default), this is the path to the
61 non-platform-specific header files, i.e. Python.h and so on;
62 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000063 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000064
Greg Wardd38e6f72000-04-10 01:17:49 +000065 If 'prefix' is supplied, use it instead of sys.prefix or
66 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000067 """
Tarek Ziadéedacea32010-01-29 11:41:03 +000068 warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
69 get_path = _sysconfig.get_path
70
71 if prefix is not None:
72 vars = {'base': prefix}
73 return get_path('include', vars=vars)
74
75 if not plat_specific:
76 return get_path('include')
Greg Ward7d73b9e2000-03-09 03:16:05 +000077 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +000078 return get_path('platinclude')
Greg Ward7d73b9e2000-03-09 03:16:05 +000079
Tarek Ziadéedacea32010-01-29 11:41:03 +000080def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
81 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +000082
Tarek Ziadéedacea32010-01-29 11:41:03 +000083 Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000084 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000085
Fred Drakec1ee39a2000-03-09 15:54:52 +000086 If 'plat_specific' is true, return the directory containing
87 platform-specific modules, i.e. any module from a non-pure-Python
88 module distribution; otherwise, return the platform-shared library
89 directory. If 'standard_lib' is true, return the directory
90 containing standard Python library modules; otherwise, return the
91 directory for site-specific modules.
92
Greg Wardd38e6f72000-04-10 01:17:49 +000093 If 'prefix' is supplied, use it instead of sys.prefix or
94 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000095 """
Tarek Ziadéedacea32010-01-29 11:41:03 +000096 warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
97 vars = {}
98 get_path = _sysconfig.get_path
99 if prefix is not None:
Greg Warddc9fe8a2000-08-02 01:49:40 +0000100 if plat_specific:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000101 vars['platbase'] = prefix
Greg Ward7d73b9e2000-03-09 03:16:05 +0000102 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000103 vars['base'] = prefix
104 if standard_lib:
105 if plat_specific:
106 return get_path('platstdlib', vars=vars)
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000107 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000108 return get_path('stdlib', vars=vars)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000109 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000110 if plat_specific:
111 return get_path('platlib', vars=vars)
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000112 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000113 return get_path('purelib', vars=vars)
Greg Ward1190ee31998-12-18 23:46:33 +0000114
Greg Ward9ddaaa11999-01-06 14:46:06 +0000115def get_makefile_filename():
Tarek Ziadéedacea32010-01-29 11:41:03 +0000116 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +0000117
Tarek Ziadéedacea32010-01-29 11:41:03 +0000118 Return full pathname of installed Makefile from the Python build.
Fred Drake522af3a1999-01-06 16:28:34 +0000119 """
Greg Ward1190ee31998-12-18 23:46:33 +0000120
Tarek Ziadéedacea32010-01-29 11:41:03 +0000121 warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
122 return _sysconfig._get_makefile_filename()
Greg Wardd283ce72000-09-17 00:53:02 +0000123
124# Regexes needed for parsing Makefile (and similar syntaxes,
125# like old-style Setup files).
126_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
127_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
128_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
129
Greg Ward3fff8d22000-09-15 00:03:13 +0000130def parse_makefile(fn, g=None):
Tarek Ziadéedacea32010-01-29 11:41:03 +0000131 """This function is deprecated.
132
133 Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000134
135 A dictionary containing name/value pairs is returned. If an
136 optional dictionary is passed in as the second argument, it is
137 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000138 """
Tarek Ziadéedacea32010-01-29 11:41:03 +0000139 warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
140 return _sysconfig._parse_makefile(fn, g)
Greg Ward1190ee31998-12-18 23:46:33 +0000141
Greg Wardd283ce72000-09-17 00:53:02 +0000142def expand_makefile_vars(s, vars):
Tarek Ziadéedacea32010-01-29 11:41:03 +0000143 """This function is deprecated.
144
145 Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000146 'string' according to 'vars' (a dictionary mapping variable names to
147 values). Variables not present in 'vars' are silently expanded to the
148 empty string. The variable values in 'vars' should not contain further
149 variable expansions; if 'vars' is the output of 'parse_makefile()',
150 you're fine. Returns a variable-expanded version of 's'.
151 """
Tarek Ziadéedacea32010-01-29 11:41:03 +0000152 warn('this function will be removed in then next version of Python',
153 DeprecationWarning)
Greg Wardd283ce72000-09-17 00:53:02 +0000154
155 # This algorithm does multiple expansion, so if vars['foo'] contains
156 # "${bar}", it will expand ${foo} to ${bar}, and then expand
157 # ${bar}... and so forth. This is fine as long as 'vars' comes from
158 # 'parse_makefile()', which takes care of such expansions eagerly,
159 # according to make's variable expansion semantics.
160
Collin Winter5b7e9d72007-08-30 03:52:21 +0000161 while True:
Greg Wardd283ce72000-09-17 00:53:02 +0000162 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
163 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000164 (beg, end) = m.span()
165 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
166 else:
167 break
168 return s