Skip to content

Commit 1875570

Browse files
author
Tarek Ziadé
committed
Merged revisions 77914 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77914 | tarek.ziade | 2010-02-02 23:27:58 +0100 (Tue, 02 Feb 2010) | 1 line first version of the sysconfig module documentation ........
1 parent bd79768 commit 1875570

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed

Doc/library/python.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ overview:
1212
.. toctree::
1313

1414
sys.rst
15+
sysconfig.rst
1516
builtins.rst
1617
__main__.rst
1718
warnings.rst

Doc/library/sysconfig.rst

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
:mod:`sysconfig` --- Provide access to Python's configuration information
2+
=========================================================================
3+
4+
.. module:: sysconfig
5+
:synopsis: Python's configuration information
6+
.. moduleauthor:: Tarek Ziade <tarek@ziade.org>
7+
.. sectionauthor:: Tarek Ziade <tarek@ziade.org>
8+
.. versionadded:: 2.7
9+
.. index::
10+
single: configuration information
11+
12+
The :mod:`sysconfig` module provides access to Python's configuration
13+
information like the list of installation paths and the configuration
14+
variables relevant for the current platform.
15+
16+
Configuration variables
17+
-----------------------
18+
19+
A Python distribution contains a :file:`Makefile` file and a :file:`python.h`
20+
that are used to build the Python binary itself, but also any C extension
21+
created in a third party project and compiled using :mod:`distutils`.
22+
23+
:mod:`sysconfig` put all variables found in these files in a dictionnary
24+
that can be accessed using :func:`get_config_vars` or :func:`get_config_var`.
25+
26+
Notice that on Windows, it's a much smaller set.
27+
28+
.. function:: get_config_vars(\*args)
29+
30+
With no arguments, return a dictionary of all configuration
31+
variables relevant for the current platform.
32+
33+
With arguments, return a list of values that result from looking up
34+
each argument in the configuration variable dictionary.
35+
36+
For each argument, if the value is not found, returns None.
37+
38+
.. function:: get_config_var(name)
39+
40+
Return the value of a single variable *name*. Equivalent to
41+
get_config_vars().get(name).
42+
43+
If *name* is not found, return None.
44+
45+
Example of usage::
46+
47+
>>> import sysconfig
48+
>>> sysconfig.get_config_var('Py_ENABLE_SHARED')
49+
0
50+
>>> sysconfig.get_config_var('LIBDIR')
51+
'/usr/local/lib'
52+
>>> sysconfig.get_config_vars('AR', 'CXX')
53+
['ar', 'g++']
54+
55+
56+
Installation paths
57+
------------------
58+
59+
Python uses an installation scheme that differs depending on the platform
60+
and on the installation options. These schemes are stored in :mod:`sysconfig`
61+
under unique identifiers based on the value returned by :const:`os.name`.
62+
63+
Every new component that is installed using :mod:`distutils` or a
64+
Distutils-based system will follow the same scheme to copy its file in the
65+
right places.
66+
67+
Python currently supports seven schemes:
68+
69+
- *posix_prefix*: scheme for posix platforms like Linux or Mac OS X. This is the
70+
default scheme used when Python or a component is installed.
71+
- *posix_home*: scheme for posix platform used when a *home* option is used
72+
upon installation. This scheme is used when a component is installed through
73+
Distutils with a specific home prefix.
74+
- *posix_user*: scheme for posix platform used when a component is installed
75+
through Distutils and the *user* option is used. This scheme defines paths
76+
located under the user home directory.
77+
- *nt*: scheme for nt platforms like Windows.
78+
- *nt_user*: scheme for nt platforms, when the *user* option is used.
79+
- *os2*: scheme for OS2 platforms.
80+
- *os2_home*: scheme for OS2 patforms, when the *user* option is used.
81+
82+
Each scheme is itself composed of a series of paths and each path has a unique
83+
identifier. Python currently uses eight paths:
84+
85+
- *stdlib*: directory containing the standard Python library files that are
86+
not platform-specific.
87+
- *platstdlib*: directory containing the standard Python library files that
88+
are platform-specific files.
89+
- *platlib*: directory for the site-specific, platform-specific files.
90+
- *purelib*: directory for the site-specific, non platform-specific files.
91+
- *include*: directory containing the non-platform-specific header files.
92+
- *platinclude*: directory containing the platform-specific header files.
93+
- *scripts*: directory containing the script files.
94+
- *data*: directory containing the data files.
95+
96+
:mod:`sysconfig` provides some functions to read these paths.
97+
98+
.. function:: get_scheme_names()
99+
100+
Return a tuple containing all schemes currently supported in
101+
:mod:`sysconfig`.
102+
103+
.. function:: get_path_names()
104+
105+
Return a tuple containing all path names currently supported in
106+
:mod:`sysconfig`.
107+
108+
109+
.. function:: get_path(name, [scheme, [vars, [expand]]])
110+
111+
Return an installation path corresponding to the path *name*, from the
112+
install scheme named *scheme*.
113+
114+
*name* has to be a value from the list returned by :func:`get_path_names`.
115+
116+
:mod:`sysconfig` stores installation paths corresponding to the each
117+
path name, for each platform, with variables to be expanded. For instance
118+
the `stdlib` path for the `nt` scheme is: `{base}/Lib`.
119+
120+
:func:`get_path` will use the variables returned by :func:`get_config_vars`
121+
to expand the path. All variables have default values for each platform
122+
so one may call this function and get the default value.
123+
124+
If *scheme* is provided, it must be a value from the list returned by
125+
:func:`get_path_names`. Otherwise, the default scheme for the current
126+
platform is used.
127+
128+
If *vars* is provided, it must be a dictionnary of variables that will
129+
update the dictionnary return by :func:`get_config_vars`.
130+
131+
If *expand* is set to False, the path will not be expanded using
132+
the variables.
133+
134+
If *name* is not found, return None.
135+
136+
137+
.. function:: get_paths([scheme, [vars, [expand]]])
138+
139+
Return a dictionnary containing all installation paths corresponding to an
140+
installation scheme. See :func:`get_path` for more information.
141+
142+
If *scheme* is not provided, will use the default scheme for the current
143+
platform.
144+
145+
If *vars* is provided, it must be a dictionnary of variables that will
146+
update the dictionnary used to expand the paths.
147+
148+
If *expand* is set to False, the paths will not be expanded.
149+
150+
If *scheme* is not an existing scheme, :func:`get_paths` will raise a
151+
:exc:`KeyError`.
152+
153+
154+
Other functions
155+
---------------
156+
157+
.. function:: get_python_version()
158+
159+
Return the MAJOR.MINOR Python version number as a string. Similar to
160+
``sys.version[:3]``.
161+
162+
.. function:: get_platform()
163+
164+
Return a string that identifies the current platform.
165+
166+
This is used mainly to distinguish platform-specific build directories and
167+
platform-specific built distributions. Typically includes the OS name
168+
and version and the architecture (as supplied by 'os.uname()'),
169+
although the exact information included depends on the OS; eg. for IRIX
170+
the architecture isn't particularly important (IRIX only runs on SGI
171+
hardware), but for Linux the kernel version isn't particularly
172+
important.
173+
174+
Examples of returned values:
175+
176+
- linux-i586
177+
- linux-alpha (?)
178+
- solaris-2.6-sun4u
179+
- irix-5.3
180+
- irix64-6.2
181+
182+
Windows will return one of:
183+
184+
- win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
185+
- win-ia64 (64bit Windows on Itanium)
186+
- win32 (all others - specifically, sys.platform is returned)
187+
188+
Mac OS X can return :
189+
190+
- macosx-10.6-ppc
191+
- macosx-10.4-ppc64
192+
- macosx-10.3-i386
193+
- macosx-10.4-fat
194+
195+
For other non-POSIX platforms, currently just returns 'sys.platform'.
196+
197+
198+
.. function:: is_python_build():
199+
200+
Returns True if the current Python installation was built from source.
201+
202+
203+
.. function:: parse_config_h(fp[, vars]):
204+
205+
Parse a config.h-style file.
206+
207+
*fp* is a file-like object pointing to the config.h-like file.
208+
209+
A dictionary containing name/value pairs is returned. If an optional
210+
dictionary is passed in as the second argument, it is used instead of a
211+
new dictionary, and updated with the values read in the file.
212+
213+
214+
.. function:: get_config_h_filename():
215+
216+
Returns the path of pyconfig.h
217+
218+

0 commit comments

Comments
 (0)