blob: 48f22ad734d7edd92db6b7219261fc4845b9e03a [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
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
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éedacea32010-01-29 11:41:03 +000028_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
29 "Use the APIs provided by the sysconfig module instead")
Christian Heimes255f53b2007-12-08 15:33:56 +000030
Tarek Ziadéedacea32010-01-29 11:41:03 +000031def _get_project_base():
32 return _sysconfig._PROJECT_BASE
33
34project_base = _get_project_base()
35
36class _DeprecatedBool(int):
37 def __nonzero__(self):
38 warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
39 return super(_DeprecatedBool, self).__nonzero__()
40
Christian Heimes2202f872008-02-06 14:31:34 +000041def _python_build():
Tarek Ziadéedacea32010-01-29 11:41:03 +000042 return _DeprecatedBool(_sysconfig.is_python_build())
43
Christian Heimes2202f872008-02-06 14:31:34 +000044python_build = _python_build()
Fred Drakec916cdc2001-08-02 20:03:12 +000045
Greg Wardd38e6f72000-04-10 01:17:49 +000046def get_python_inc(plat_specific=0, prefix=None):
Tarek Ziadéedacea32010-01-29 11:41:03 +000047 """This function is deprecated.
48
49 Return the directory containing installed Python header files.
Fred Drakec1ee39a2000-03-09 15:54:52 +000050
51 If 'plat_specific' is false (the default), this is the path to the
52 non-platform-specific header files, i.e. Python.h and so on;
53 otherwise, this is the path to platform-specific header files
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000054 (namely pyconfig.h).
Fred Drakec1ee39a2000-03-09 15:54:52 +000055
Greg Wardd38e6f72000-04-10 01:17:49 +000056 If 'prefix' is supplied, use it instead of sys.prefix or
57 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakeb94b8492001-12-06 20:51:35 +000058 """
Tarek Ziadéedacea32010-01-29 11:41:03 +000059 warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
60 get_path = _sysconfig.get_path
61
62 if prefix is not None:
63 vars = {'base': prefix}
64 return get_path('include', vars=vars)
65
66 if not plat_specific:
67 return get_path('include')
Greg Ward7d73b9e2000-03-09 03:16:05 +000068 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +000069 return get_path('platinclude')
Greg Ward7d73b9e2000-03-09 03:16:05 +000070
Tarek Ziadéedacea32010-01-29 11:41:03 +000071def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
72 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +000073
Tarek Ziadéedacea32010-01-29 11:41:03 +000074 Return the directory containing the Python library (standard or
Fred Drakec1ee39a2000-03-09 15:54:52 +000075 site additions).
Greg Ward7d73b9e2000-03-09 03:16:05 +000076
Fred Drakec1ee39a2000-03-09 15:54:52 +000077 If 'plat_specific' is true, return the directory containing
78 platform-specific modules, i.e. any module from a non-pure-Python
79 module distribution; otherwise, return the platform-shared library
80 directory. If 'standard_lib' is true, return the directory
81 containing standard Python library modules; otherwise, return the
82 directory for site-specific modules.
83
Greg Wardd38e6f72000-04-10 01:17:49 +000084 If 'prefix' is supplied, use it instead of sys.prefix or
85 sys.exec_prefix -- i.e., ignore 'plat_specific'.
Fred Drakec1ee39a2000-03-09 15:54:52 +000086 """
Tarek Ziadéedacea32010-01-29 11:41:03 +000087 warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
88 vars = {}
89 get_path = _sysconfig.get_path
90 if prefix is not None:
Greg Warddc9fe8a2000-08-02 01:49:40 +000091 if plat_specific:
Tarek Ziadéedacea32010-01-29 11:41:03 +000092 vars['platbase'] = prefix
Greg Ward7d73b9e2000-03-09 03:16:05 +000093 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +000094 vars['base'] = prefix
95 if standard_lib:
96 if plat_specific:
97 return get_path('platstdlib', vars=vars)
Marc-André Lemburg2544f512002-01-31 18:56:00 +000098 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +000099 return get_path('stdlib', vars=vars)
Greg Ward7d73b9e2000-03-09 03:16:05 +0000100 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000101 if plat_specific:
102 return get_path('platlib', vars=vars)
Andrew M. Kuchling29c86232002-11-04 19:53:24 +0000103 else:
Tarek Ziadéedacea32010-01-29 11:41:03 +0000104 return get_path('purelib', vars=vars)
Greg Ward1190ee31998-12-18 23:46:33 +0000105
Greg Ward9ddaaa11999-01-06 14:46:06 +0000106def get_makefile_filename():
Tarek Ziadéedacea32010-01-29 11:41:03 +0000107 """This function is deprecated.
Greg Ward7d73b9e2000-03-09 03:16:05 +0000108
Tarek Ziadéedacea32010-01-29 11:41:03 +0000109 Return full pathname of installed Makefile from the Python build.
Fred Drake522af3a1999-01-06 16:28:34 +0000110 """
Greg Ward1190ee31998-12-18 23:46:33 +0000111
Tarek Ziadéedacea32010-01-29 11:41:03 +0000112 warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
113 return _sysconfig._get_makefile_filename()
Greg Wardd283ce72000-09-17 00:53:02 +0000114
115# Regexes needed for parsing Makefile (and similar syntaxes,
116# like old-style Setup files).
117_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
118_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
119_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
120
Greg Ward3fff8d22000-09-15 00:03:13 +0000121def parse_makefile(fn, g=None):
Tarek Ziadéedacea32010-01-29 11:41:03 +0000122 """This function is deprecated.
123
124 Parse a Makefile-style file.
Fred Drakec1ee39a2000-03-09 15:54:52 +0000125
126 A dictionary containing name/value pairs is returned. If an
127 optional dictionary is passed in as the second argument, it is
128 used instead of a new dictionary.
Fred Drake522af3a1999-01-06 16:28:34 +0000129 """
Tarek Ziadéedacea32010-01-29 11:41:03 +0000130 warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
131 return _sysconfig._parse_makefile(fn, g)
Greg Ward1190ee31998-12-18 23:46:33 +0000132
Greg Wardd283ce72000-09-17 00:53:02 +0000133def expand_makefile_vars(s, vars):
Tarek Ziadéedacea32010-01-29 11:41:03 +0000134 """This function is deprecated.
135
136 Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
Greg Wardd283ce72000-09-17 00:53:02 +0000137 'string' according to 'vars' (a dictionary mapping variable names to
138 values). Variables not present in 'vars' are silently expanded to the
139 empty string. The variable values in 'vars' should not contain further
140 variable expansions; if 'vars' is the output of 'parse_makefile()',
141 you're fine. Returns a variable-expanded version of 's'.
142 """
Tarek Ziadéedacea32010-01-29 11:41:03 +0000143 warn('this function will be removed in then next version of Python',
144 DeprecationWarning)
Greg Wardd283ce72000-09-17 00:53:02 +0000145
146 # This algorithm does multiple expansion, so if vars['foo'] contains
147 # "${bar}", it will expand ${foo} to ${bar}, and then expand
148 # ${bar}... and so forth. This is fine as long as 'vars' comes from
149 # 'parse_makefile()', which takes care of such expansions eagerly,
150 # according to make's variable expansion semantics.
151
Collin Winter5b7e9d72007-08-30 03:52:21 +0000152 while True:
Greg Wardd283ce72000-09-17 00:53:02 +0000153 m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
154 if m:
Greg Wardd283ce72000-09-17 00:53:02 +0000155 (beg, end) = m.span()
156 s = s[0:beg] + vars.get(m.group(1)) + s[end:]
157 else:
158 break
159 return s