Skip to content

Commit

Permalink
sysconfig: use parse_config_h() from stdlib sysconfig
Browse files Browse the repository at this point in the history
The only difference is the argument name change
  • Loading branch information
lazka authored and FFY00 committed Dec 27, 2021
1 parent b17dad6 commit 9d0b8cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
22 changes: 2 additions & 20 deletions distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import re
import sys
import sysconfig

from .errors import DistutilsPlatformError

Expand Down Expand Up @@ -308,26 +309,7 @@ def parse_config_h(fp, g=None):
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
"""
if g is None:
g = {}
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
#
while True:
line = fp.readline()
if not line:
break
m = define_rx.match(line)
if m:
n, v = m.group(1, 2)
try: v = int(v)
except ValueError: pass
g[n] = v
else:
m = undef_rx.match(line)
if m:
g[m.group(1)] = 0
return g
return sysconfig.parse_config_h(fp, vars=g)


# Regexes needed for parsing Makefile (and similar syntaxes,
Expand Down
10 changes: 10 additions & 0 deletions distutils/tests/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def test_customize_compiler_before_get_config_vars(self):
outs, errs = p.communicate()
self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)

def test_parse_config_h(self):
config_h = sysconfig.get_config_h_filename()
input = {}
with open(config_h, encoding="utf-8") as f:
result = sysconfig.parse_config_h(f, g=input)
self.assertTrue(input)
self.assertTrue(input is result)
with open(config_h, encoding="utf-8") as f:
result = sysconfig.parse_config_h(f)
self.assertTrue(result)

def test_suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit 9d0b8cd

Please sign in to comment.