Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 1 | """Provide access to Python's configuration information. The specific |
| 2 | configuration variables available depend heavily on the platform and |
| 3 | configuration. The values may be retrieved using |
| 4 | get_config_var(name), and the list of variables is available via |
| 5 | get_config_vars().keys(). Additional convenience functions are also |
| 6 | available. |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 7 | |
| 8 | Written by: Fred L. Drake, Jr. |
| 9 | Email: <fdrake@acm.org> |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 10 | |
| 11 | **This module has been moved out of Distutils and will be removed from |
| 12 | Python in the next version (3.2)** |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 13 | """ |
| 14 | |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 15 | __revision__ = "$Id$" |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 16 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 17 | import re |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 18 | from warnings import warn |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 19 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 20 | # importing sysconfig from Lib |
| 21 | # to avoid this module to shadow it |
| 22 | _sysconfig = __import__('sysconfig') |
Greg Ward | a0ca3f2 | 2000-02-02 00:05:14 +0000 | [diff] [blame] | 23 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 24 | _DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. " |
| 25 | "Use the APIs provided by the sysconfig module instead") |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 26 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 27 | def _get_project_base(): |
| 28 | return _sysconfig._PROJECT_BASE |
Christian Heimes | d3fc07a4 | 2007-12-06 13:15:13 +0000 | [diff] [blame] | 29 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 30 | project_base = _get_project_base() |
| 31 | |
| 32 | class _DeprecatedBool(int): |
| 33 | def __nonzero__(self): |
| 34 | warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning) |
| 35 | return super(_DeprecatedBool, self).__nonzero__() |
| 36 | |
Marc-André Lemburg | 2db7cd3 | 2008-02-05 14:50:40 +0000 | [diff] [blame] | 37 | def _python_build(): |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 38 | return _DeprecatedBool(_sysconfig.is_python_build()) |
| 39 | |
Marc-André Lemburg | 2db7cd3 | 2008-02-05 14:50:40 +0000 | [diff] [blame] | 40 | python_build = _python_build() |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 41 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 42 | def get_python_inc(plat_specific=0, prefix=None): |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 43 | """This function is deprecated. |
| 44 | |
| 45 | Return the directory containing installed Python header files. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 46 | |
| 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öwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 50 | (namely pyconfig.h). |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 51 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 52 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 53 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 54 | """ |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 55 | 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 Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 64 | else: |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 65 | return get_path('platinclude') |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 66 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 67 | def get_python_lib(plat_specific=False, standard_lib=False, prefix=None): |
| 68 | """This function is deprecated. |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 69 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 70 | Return the directory containing the Python library (standard or |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 71 | site additions). |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 72 | |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 73 | 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 Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 80 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 81 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 82 | """ |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 83 | warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning) |
| 84 | vars = {} |
| 85 | get_path = _sysconfig.get_path |
| 86 | if prefix is not None: |
Greg Ward | dc9fe8a | 2000-08-02 01:49:40 +0000 | [diff] [blame] | 87 | if plat_specific: |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 88 | vars['platbase'] = prefix |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 89 | else: |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 90 | vars['base'] = prefix |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 91 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 92 | if standard_lib: |
| 93 | if plat_specific: |
| 94 | return get_path('platstdlib', vars=vars) |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 95 | else: |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 96 | return get_path('stdlib', vars=vars) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 97 | else: |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 98 | if plat_specific: |
| 99 | return get_path('platlib', vars=vars) |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 100 | else: |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 101 | return get_path('purelib', vars=vars) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 102 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 103 | def get_makefile_filename(): |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 104 | """This function is deprecated. |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 105 | |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 106 | Return full pathname of installed Makefile from the Python build. |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 107 | """ |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 108 | warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning) |
| 109 | return _sysconfig._get_makefile_filename() |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 110 | |
| 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 Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 117 | def parse_makefile(fn, g=None): |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 118 | """This function is deprecated. |
| 119 | |
| 120 | Parse a Makefile-style file. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 121 | |
| 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 Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 125 | """ |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 126 | warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning) |
| 127 | return _sysconfig._parse_makefile(fn, g) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 128 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 129 | def expand_makefile_vars(s, vars): |
Tarek Ziadé | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 130 | """This function is deprecated. |
| 131 | |
| 132 | Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 133 | '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é | 5633a80 | 2010-01-23 09:23:15 +0000 | [diff] [blame^] | 139 | warn('this function will be removed in then next version of Python', |
| 140 | DeprecationWarning) |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 141 | |
| 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 Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 151 | (beg, end) = m.span() |
| 152 | s = s[0:beg] + vars.get(m.group(1)) + s[end:] |
| 153 | else: |
| 154 | break |
| 155 | return s |