blob: a247bc2cd7496aff49838d0ed1f870ff5d6fa994 [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
Tarek Ziadébece7f22010-02-02 22:55:00 +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
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é0276c7a2010-01-26 21:21:54 +000024# names defined here to keep backward compatibility
25# for APIs that were relocated
26get_python_version = _sysconfig.get_python_version
27get_config_h_filename = _sysconfig.get_config_h_filename
28parse_config_h = _sysconfig.parse_config_h
29get_config_vars = _sysconfig.get_config_vars
30get_config_var = _sysconfig.get_config_var
31from distutils.ccompiler import customize_compiler
32
Tarek Ziadé5633a802010-01-23 09:23:15 +000033_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
34 "Use the APIs provided by the sysconfig module instead")
Fred Drakec1ee39a2000-03-09 15:54:52 +000035
Tarek Ziadé5633a802010-01-23 09:23:15 +000036def _get_project_base():
37 return _sysconfig._PROJECT_BASE
Christian Heimesd3fc07a42007-12-06 13:15:13 +000038
Tarek Ziadé5633a802010-01-23 09:23:15 +000039project_base = _get_project_base()
40
41class _DeprecatedBool(int):
42 def __nonzero__(self):
43 warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
44 return super(_DeprecatedBool, self).__nonzero__()
45
Marc-André Lemburg2db7cd32008-02-05 14:50:40 +000046def _python_build():
Tarek Ziadé5633a802010-01-23 09:23:15 +000047 return _DeprecatedBool(_sysconfig.is_python_build())
48
Marc-André Lemburg2db7cd32008-02-05 14:50:40 +000049python_build = _python_build()
Fred Drakec1ee39a2000-03-09 15:54:52 +000050
Greg Wardd38e6f72000-04-10 01:17:49 +000051def get_python_inc(plat_specific=0, prefix=None):
Tarek Ziadé5633a802010-01-23 09:23:15 +000052 """This function is deprecated.
53
54 Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000055
56 If 'plat_specific' is false (the default), this is the path to the
57 non-platform-specific header files, i.e. Python.h and so on;
58 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000059 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000060
Greg Wardd38e6f72000-04-10 01:17:49 +000061 If 'prefix' is supplied, use it instead of sys.prefix or
62 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000063 """
Tarek Ziadé5633a802010-01-23 09:23:15 +000064 warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
65 get_path = _sysconfig.get_path
66
67 if prefix is not None:
68 vars = {'base': prefix}
69 return get_path('include', vars=vars)
70
71 if not plat_specific:
72 return get_path('include')
Greg Ward7d73b9e2000-03-09 03:16:05 +000073 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +000074 return get_path('platinclude')
Greg Ward7d73b9e2000-03-09 03:16:05 +000075
Tarek Ziadé5633a802010-01-23 09:23:15 +000076def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
77 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +000078
Tarek Ziadé5633a802010-01-23 09:23:15 +000079 Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000080 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000081
Fred Drakec1ee39a2000-03-09 15:54:52 +000082 If 'plat_specific' is true, return the directory containing
83 platform-specific modules, i.e. any module from a non-pure-Python
84 module distribution; otherwise, return the platform-shared library
85 directory. If 'standard_lib' is true, return the directory
86 containing standard Python library modules; otherwise, return the
87 directory for site-specific modules.
88
Greg Wardd38e6f72000-04-10 01:17:49 +000089 If 'prefix' is supplied, use it instead of sys.prefix or
90 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000091 """
Tarek Ziadé5633a802010-01-23 09:23:15 +000092 warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
93 vars = {}
94 get_path = _sysconfig.get_path
95 if prefix is not None:
Greg Warddc9fe8a2000-08-02 01:49:40 +000096 if plat_specific:
Tarek Ziadé5633a802010-01-23 09:23:15 +000097 vars['platbase'] = prefix
Greg Ward7d73b9e2000-03-09 03:16:05 +000098 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +000099 vars['base'] = prefix
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000100
Tarek Ziadé5633a802010-01-23 09:23:15 +0000101 if standard_lib:
102 if plat_specific:
103 return get_path('platstdlib', vars=vars)
Marc-André Lemburg2544f512002-01-31 18:56:00 +0000104 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +0000105 return get_path('stdlib', vars=vars)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000106 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +0000107 if plat_specific:
108 return get_path('platlib', vars=vars)
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000109 else:
Tarek Ziadé5633a802010-01-23 09:23:15 +0000110 return get_path('purelib', vars=vars)
Greg Ward1190ee31998-12-18 23:46:33 +0000111
Greg Ward9ddaaa11999-01-06 14:46:06 +0000112def get_makefile_filename():
Tarek Ziadé5633a802010-01-23 09:23:15 +0000113 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +0000114
Tarek Ziadé5633a802010-01-23 09:23:15 +0000115 Return full pathname of installed Makefile from the Python build.
Fred Drake522af3a1999-01-06 16:28:34 +0000116 """
Tarek Ziadé5633a802010-01-23 09:23:15 +0000117 warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
118 return _sysconfig._get_makefile_filename()
Greg Wardd283ce72000-09-17 00:53:02 +0000119
120# Regexes needed for parsing Makefile (and similar syntaxes,
121# like old-style Setup files).
122_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
123_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
124_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
125
Greg Ward3fff8d22000-09-15 00:03:13 +0000126def parse_makefile(fn, g=None):
Tarek Ziadé5633a802010-01-23 09:23:15 +0000127 """This function is deprecated.
128
129 Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000130
131 A dictionary containing name/value pairs is returned. If an
132 optional dictionary is passed in as the second argument, it is
133 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000134 """
Tarek Ziadé5633a802010-01-23 09:23:15 +0000135 warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
136 return _sysconfig._parse_makefile(fn, g)
Greg Ward1190ee31998-12-18 23:46:33 +0000137
Greg Wardd283ce72000-09-17 00:53:02 +0000138def expand_makefile_vars(s, vars):
Tarek Ziadé5633a802010-01-23 09:23:15 +0000139 """This function is deprecated.
140
141 Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000142 'string' according to 'vars' (a dictionary mapping variable names to
143 values). Variables not present in 'vars' are silently expanded to the
144 empty string. The variable values in 'vars' should not contain further
145 variable expansions; if 'vars' is the output of 'parse_makefile()',
146 you're fine. Returns a variable-expanded version of 's'.
147 """
Tarek Ziadé5633a802010-01-23 09:23:15 +0000148 warn('this function will be removed in then next version of Python',
149 DeprecationWarning)
Greg Wardd283ce72000-09-17 00:53:02 +0000150
151 # This algorithm does multiple expansion, so if vars['foo'] contains
152 # "${bar}", it will expand ${foo} to ${bar}, and then expand
153 # ${bar}... and so forth. This is fine as long as 'vars' comes from
154 # 'parse_makefile()', which takes care of such expansions eagerly,
155 # according to make's variable expansion semantics.
156
157 while 1:
158 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
159 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000160 (beg, end) = m.span()
161 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
162 else:
163 break
164 return s