Skip to content

Commit

Permalink
Another patch from Fred: factored _init_posix into
Browse files Browse the repository at this point in the history
get_config_h_filename, get_makefile_filename, parse_config_h, and
parse_makefile.
  • Loading branch information
gward committed Jan 6, 1999
1 parent f4bf044 commit 9ddaaa1
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions Lib/distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@

__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:
Expand All @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 9ddaaa1

Please sign in to comment.