[Python-checkins] cpython (3.2): Issue #12070: Fix the Makefile parser of the sysconfig module to handle

victor.stinner python-checkins at python.org
Tue May 24 23:38:25 CEST 2011


http://hg.python.org/cpython/rev/4a7bb2ef636a
changeset: 70352:4a7bb2ef636a
branch: 3.2
parent: 70348:7f2ab2f95a04
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Tue May 24 23:37:07 2011 +0200
summary:
 Issue #12070: Fix the Makefile parser of the sysconfig module to handle
correctly references to "bogus variable" (e.g. "prefix=$/opt/python").
files:
 Lib/sysconfig.py | 6 +++-
 Lib/test/test_sysconfig.py | 34 ++++++++++++++++++-------
 Misc/NEWS | 3 ++
 3 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -294,7 +294,7 @@
 variables.remove(name)
 
 if name.startswith('PY_') \
- and name[3:] in renamed_variables:
+ and name[3:] in renamed_variables:
 
 name = name[3:]
 if name not in done:
@@ -302,7 +302,9 @@
 
 
 else:
- # bogus variable reference; just drop it since we can't deal
+ # bogus variable reference (e.g. "prefix=$/opt/python");
+ # just drop it since we can't deal
+ done[name] = value
 variables.remove(name)
 
 # strip spurious spaces
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -26,7 +26,6 @@
 """Make a copy of sys.path"""
 super(TestSysConfig, self).setUp()
 self.sys_path = sys.path[:]
- self.makefile = None
 # patching os.uname
 if hasattr(os, 'uname'):
 self.uname = os.uname
@@ -49,8 +48,6 @@
 def tearDown(self):
 """Restore sys.path"""
 sys.path[:] = self.sys_path
- if self.makefile is not None:
- os.unlink(self.makefile)
 self._cleanup_testfn()
 if self.uname is not None:
 os.uname = self.uname
@@ -236,12 +233,6 @@
 config_h = sysconfig.get_config_h_filename()
 self.assertTrue(os.path.isfile(config_h), config_h)
 
- @unittest.skipIf(sys.platform.startswith('win'),
- 'Test is not Windows compatible')
- def test_get_makefile_filename(self):
- makefile = sysconfig.get_makefile_filename()
- self.assertTrue(os.path.isfile(makefile), makefile)
-
 def test_get_scheme_names(self):
 wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
 'posix_home', 'posix_prefix', 'posix_user')
@@ -339,10 +330,33 @@
 self.assertEqual(my_platform, test_platform)
 
 
+class MakefileTests(unittest.TestCase):
+ @unittest.skipIf(sys.platform.startswith('win'),
+ 'Test is not Windows compatible')
+ def test_get_makefile_filename(self):
+ makefile = sysconfig.get_makefile_filename()
+ self.assertTrue(os.path.isfile(makefile), makefile)
+
+ def test_parse_makefile(self):
+ self.addCleanup(unlink, TESTFN)
+ with open(TESTFN, "w") as makefile:
+ print("var1=a$(VAR2)", file=makefile)
+ print("VAR2=b$(var3)", file=makefile)
+ print("var3=42", file=makefile)
+ print("var4=$/invalid", file=makefile)
+ print("var5=dollar$5ドル", file=makefile)
+ vars = sysconfig._parse_makefile(TESTFN)
+ self.assertEqual(vars, {
+ 'var1': 'ab42',
+ 'VAR2': 'b42',
+ 'var3': 42,
+ 'var4': '$/invalid',
+ 'var5': 'dollar5ドル',
+ })
 
 
 def test_main():
- run_unittest(TestSysConfig)
+ run_unittest(TestSysConfig, MakefileTests)
 
 if __name__ == "__main__":
 test_main()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
 Library
 -------
 
+- Issue #12070: Fix the Makefile parser of the sysconfig module to handle
+ correctly references to "bogus variable" (e.g. "prefix=$/opt/python").
+
 - Issue #12100: Don't reset incremental encoders of CJK codecs at each call to
 their encode() method anymore, but continue to call the reset() method if the
 final argument is True.
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /