summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>1999-01-06 14:46:06 (GMT)
committerGreg Ward <gward@python.net>1999-01-06 14:46:06 (GMT)
commit9ddaaa1a30a8a0681b60922e877f3b7d23e6bdf6 (patch)
tree52557bc9c0399c7c636c914642aef697ec47cf43
parentf4bf044999ad48684b8d70c229756a1da8a7613b (diff)
downloadcpython-9ddaaa1a30a8a0681b60922e877f3b7d23e6bdf6.zip
cpython-9ddaaa1a30a8a0681b60922e877f3b7d23e6bdf6.tar.gz
cpython-9ddaaa1a30a8a0681b60922e877f3b7d23e6bdf6.tar.bz2
Another patch from Fred: factored _init_posix into
get_config_h_filename, get_makefile_filename, parse_config_h, and parse_makefile.
-rw-r--r--Lib/distutils/sysconfig.py55
1 files changed, 37 insertions, 18 deletions
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 3eee9b3..1d8231a 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -11,24 +11,26 @@ Initial date: 17-Dec-1998
__version__ = "$Revision$"
+import os
+import re
+import string
+import sys
-def _init_posix():
- import os
- import re
- import string
- import sys
- g = globals()
+def get_config_h_filename():
+ return os.path.join(sys.exec_prefix, "lib", "python" + sys.version[:3],
+ "config", "config.h")
- version = sys.version[:3]
- config_dir = os.path.join(
- sys.exec_prefix, "lib", "python" + version, "config")
+def get_makefile_filename():
+ return os.path.join(sys.exec_prefix, "lib", "python" + sys.version[:3],
+ "config", "Makefile")
- # load the installed config.h:
+def parse_config_h(fp, g=None):
+ if g is None:
+ g = {}
define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
- fp = open(os.path.join(config_dir, "config.h"))
-
+ #
while 1:
line = fp.readline()
if not line:
@@ -43,13 +45,15 @@ def _init_posix():
m = undef_rx.match(line)
if m:
g[m.group(1)] = 0
+ return g
- # load the installed Makefile.pre.in:
+def parse_makefile(fp, g=None):
+ if g is None:
+ g = {}
variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)\n")
done = {}
notdone = {}
- fp = open(os.path.join(config_dir, "Makefile"))
-
+ #
while 1:
line = fp.readline()
if not line:
@@ -106,9 +110,24 @@ def _init_posix():
# save the results in the global dictionary
g.update(done)
+ return g
-import os
-exec "_init_%s()" % os.name
-del os
+def _init_posix():
+ g = globals()
+ # load the installed config.h:
+ parse_config_h(open(get_config_h_filename()), g)
+ # load the installed Makefile.pre.in:
+ parse_makefile(open(get_makefile_filename()), g)
+
+
+
+try:
+ exec "_init_" + os.name
+except NameError:
+ # not needed for this platform
+ pass
+else:
+ exec "_init_%s()" % os.name
+
del _init_posix