blob: bb8b5125e411e617971e25e984dee4a87f1bc631 [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é5633a802010-01-23 09:23:15 +000010
11**This module has been moved out of Distutils and will be removed from
12Python in the next version (3.2)**
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
Greg Ward9ddaaa11999-01-06 14:46:06 +000017import re
Tarek Ziadé5633a802010-01-23 09:23:15 +000018from warnings import warn
Greg Ward1190ee31998-12-18 23:46:33 +000019
Tarek Ziadé5633a802010-01-23 09:23:15 +000020# importing sysconfig from Lib
21# to avoid this module to shadow it
22_sysconfig = __import__('sysconfig')
Greg Warda0ca3f22000-02-02 00:05:14 +000023
Tarek Ziadé5633a802010-01-23 09:23:15 +000024_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
25 "Use the APIs provided by the sysconfig module instead")
Fred Drakec1ee39a2000-03-09 15:54:52 +000026
Tarek Ziadé5633a802010-01-23 09:23:15 +000027def _get_project_base():
28 return _sysconfig._PROJECT_BASE
Christian Heimesd3fc07a42007-12-06 13:15:13 +000029
Tarek Ziadé5633a802010-01-23 09:23:15 +000030project_base = _get_project_base()
31
32class _DeprecatedBool(int):
33 def __nonzero__(self):
34 warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
35 return super(_DeprecatedBool, self).__nonzero__()
36
Marc-André Lemburg2db7cd32008-02-05 14:50:40 +000037def _python_build():
Tarek Ziadé5633a802010-01-23 09:23:15 +000038 return _DeprecatedBool(_sysconfig.is_python_build())
39
Marc-André Lemburg2db7cd32008-02-05 14:50:40 +000040python_build = _python_build()
Fred Drakec1ee39a2000-03-09 15:54:52 +000041
Greg Wardd38e6f72000-04-10 01:17:49 +000042def get_python_inc(plat_specific=0, prefix=None):
Tarek Ziadé5633a802010-01-23 09:23:15 +000043 """This function is deprecated.
44
45 Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000046
47 If 'plat_specific' is false (the default), this is the path to the
48 non-platform-specific header files, i.e. Python.h and so on;
49 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000050 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000051
Greg Wardd38e6f72000-04-10 01:17:49 +000052 If 'prefix' is supplied, use it instead of sys.prefix or
53 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000054 """
Tarek Ziadé5633a802010-01-23 09:23:15 +000055 warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
56 get_path = _sysconfig.get_path
57
58 if prefix is not None:
59 vars = {'base': prefix}
60 return get_path('include', vars=vars)
61
62 if not plat_specific:
63 return get_path('include')
Greg Ward7d73b9e2000-03-09 03:16:05 +000064 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +000065 return get_path('platinclude')
Greg Ward7d73b9e2000-03-09 03:16:05 +000066
Tarek Ziadé5633a802010-01-23 09:23:15 +000067def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
68 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +000069
Tarek Ziadé5633a802010-01-23 09:23:15 +000070 Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000071 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000072
Fred Drakec1ee39a2000-03-09 15:54:52 +000073 If 'plat_specific' is true, return the directory containing
74 platform-specific modules, i.e. any module from a non-pure-Python
75 module distribution; otherwise, return the platform-shared library
76 directory. If 'standard_lib' is true, return the directory
77 containing standard Python library modules; otherwise, return the
78 directory for site-specific modules.
79
Greg Wardd38e6f72000-04-10 01:17:49 +000080 If 'prefix' is supplied, use it instead of sys.prefix or
81 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000082 """
Tarek Ziadé5633a802010-01-23 09:23:15 +000083 warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
84 vars = {}
85 get_path = _sysconfig.get_path
86 if prefix is not None:
Greg Warddc9fe8a2000-08-02 01:49:40 +000087 if plat_specific:
Tarek Ziadé5633a802010-01-23 09:23:15 +000088 vars['platbase'] = prefix
Greg Ward7d73b9e2000-03-09 03:16:05 +000089 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +000090 vars['base'] = prefix
Marc-André Lemburg2544f512002-01-31 18:56:00 +000091
Tarek Ziadé5633a802010-01-23 09:23:15 +000092 if standard_lib:
93 if plat_specific:
94 return get_path('platstdlib', vars=vars)
Marc-André Lemburg2544f512002-01-31 18:56:00 +000095 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +000096 return get_path('stdlib', vars=vars)
Greg Ward7d73b9e2000-03-09 03:16:05 +000097 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +000098 if plat_specific:
99 return get_path('platlib', vars=vars)
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000100 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +0000101 return get_path('purelib', vars=vars)
Greg Ward1190ee31998-12-18 23:46:33 +0000102
Greg Ward9ddaaa11999-01-06 14:46:06 +0000103def get_makefile_filename():
Tarek Ziadé5633a802010-01-23 09:23:15 +0000104 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +0000105
Tarek Ziadé5633a802010-01-23 09:23:15 +0000106 Return full pathname of installed Makefile from the Python build.
Fred Drake522af3a1999-01-06 16:28:34 +0000107 """
Tarek Ziadé5633a802010-01-23 09:23:15 +0000108 warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
109 return _sysconfig._get_makefile_filename()
Greg Wardd283ce72000-09-17 00:53:02 +0000110
111# Regexes needed for parsing Makefile (and similar syntaxes,
112# like old-style Setup files).
113_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
114_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
115_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
116
Greg Ward3fff8d22000-09-15 00:03:13 +0000117def parse_makefile(fn, g=None):
Tarek Ziadé5633a802010-01-23 09:23:15 +0000118 """This function is deprecated.
119
120 Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000121
122 A dictionary containing name/value pairs is returned. If an
123 optional dictionary is passed in as the second argument, it is
124 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000125 """
Tarek Ziadé5633a802010-01-23 09:23:15 +0000126 warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
127 return _sysconfig._parse_makefile(fn, g)
Greg Ward1190ee31998-12-18 23:46:33 +0000128
Greg Wardd283ce72000-09-17 00:53:02 +0000129def expand_makefile_vars(s, vars):
Tarek Ziadé5633a802010-01-23 09:23:15 +0000130 """This function is deprecated.
131
132 Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000133 'string' according to 'vars' (a dictionary mapping variable names to
134 values). Variables not present in 'vars' are silently expanded to the
135 empty string. The variable values in 'vars' should not contain further
136 variable expansions; if 'vars' is the output of 'parse_makefile()',
137 you're fine. Returns a variable-expanded version of 's'.
138 """
Tarek Ziadé5633a802010-01-23 09:23:15 +0000139 warn('this function will be removed in then next version of Python',
140 DeprecationWarning)
Greg Wardd283ce72000-09-17 00:53:02 +0000141
142 # This algorithm does multiple expansion, so if vars['foo'] contains
143 # "${bar}", it will expand ${foo} to ${bar}, and then expand
144 # ${bar}... and so forth. This is fine as long as 'vars' comes from
145 # 'parse_makefile()', which takes care of such expansions eagerly,
146 # according to make's variable expansion semantics.
147
148 while 1:
149 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
150 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000151 (beg, end) = m.span()
152 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
153 else:
154 break
155 return s