1 """Provide access to Python's configuration information. The specific names
2 defined in the module depend heavily on the platform and configuration.
4 Written by: Fred L. Drake, Jr.
5 Email: <fdrake@acm.org>
6 Initial date: 17-Dec-1998
9 __version__
= "$Revision$"
17 def get_config_h_filename():
18 """Return full pathname of installed config.h file."""
19 return os
.path
.join(sys
.exec_prefix
, "include", "python" + sys
.version
[:3],
22 def get_makefile_filename():
23 """Return full pathname of installed Makefile from the Python build."""
24 return os
.path
.join(sys
.exec_prefix
, "lib", "python" + sys
.version
[:3],
27 def parse_config_h(fp
, g
=None):
28 """Parse a config.h-style file. A dictionary containing name/value
29 pairs is returned. If an optional dictionary is passed in as the second
30 argument, it is used instead of a new dictionary.
34 define_rx
= re
.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
35 undef_rx
= re
.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
41 m
= define_rx
.match(line
)
44 try: v
= string
.atoi(v
)
45 except ValueError: pass
48 m
= undef_rx
.match(line
)
53 def parse_makefile(fp
, g
=None):
54 """Parse a Makefile-style file. A dictionary containing name/value
55 pairs is returned. If an optional dictionary is passed in as the second
56 argument, it is used instead of a new dictionary.
60 variable_rx
= re
.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)\n")
68 m
= variable_rx
.match(line
)
75 try: v
= string
.atoi(v
)
76 except ValueError: pass
79 # do variable interpolation here
80 findvar1_rx
= re
.compile(r
"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
81 findvar2_rx
= re
.compile(r
"\${([A-Za-z][A-Za-z0-9_]*)}")
83 for name
in notdone
.keys():
85 m
= findvar1_rx
.search(value
)
87 m
= findvar2_rx
.search(value
)
91 after
= value
[m
.end():]
92 value
= value
[:m
.start()] + done
[n
] + after
96 try: value
= string
.atoi(value
)
97 except ValueError: pass
98 done
[name
] = string
.strip(value
)
100 elif notdone
.has_key(n
):
101 # get it on a subsequent round
105 after
= value
[m
.end():]
106 value
= value
[:m
.start()] + after
108 notdone
[name
] = value
110 try: value
= string
.atoi(value
)
111 except ValueError: pass
112 done
[name
] = string
.strip(value
)
115 # bogus variable reference; just drop it since we can't deal
118 # save the results in the global dictionary
124 """Initialize the module as appropriate for POSIX systems."""
126 # load the installed config.h:
127 parse_config_h(open(get_config_h_filename()), g
)
128 # load the installed Makefile.pre.in:
129 parse_makefile(open(get_makefile_filename()), g
)
134 exec "_init_" + os
.name
136 # not needed for this platform
139 exec "_init_%s()" % os
.name