991010"""
1111
12- import _imp
1312import os
1413import re
1514import sys
1615import sysconfig
1716
1817from .errors import DistutilsPlatformError
18+ from . import py39compat
1919
2020IS_PYPY = '__pypy__' in sys .builtin_module_names
2121
@@ -48,6 +48,7 @@ def _is_python_source_dir(d):
4848 return True
4949 return False
5050
51+
5152_sys_home = getattr (sys , '_home' , None )
5253
5354if os .name == 'nt' :
@@ -59,11 +60,13 @@ def _fix_pcbuild(d):
5960 project_base = _fix_pcbuild (project_base )
6061 _sys_home = _fix_pcbuild (_sys_home )
6162
63+
6264def _python_build ():
6365 if _sys_home :
6466 return _is_python_source_dir (_sys_home )
6567 return _is_python_source_dir (project_base )
6668
69+
6770python_build = _python_build ()
6871
6972
@@ -79,6 +82,7 @@ def _python_build():
7982 # this attribute, which is fine.
8083 pass
8184
85+
8286def get_python_version ():
8387 """Return a string containing the major and minor Python version,
8488 leaving off the patchlevel. Sample return values could be '1.5'
@@ -192,7 +196,6 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
192196 "on platform '%s'" % os .name )
193197
194198
195-
196199def customize_compiler (compiler ):
197200 """Do any platform-specific customization of a CCompiler instance.
198201
@@ -217,8 +220,9 @@ def customize_compiler(compiler):
217220 _config_vars ['CUSTOMIZED_OSX_COMPILER' ] = 'True'
218221
219222 (cc , cxx , cflags , ccshared , ldshared , shlib_suffix , ar , ar_flags ) = \
220- get_config_vars ('CC' , 'CXX' , 'CFLAGS' ,
221- 'CCSHARED' , 'LDSHARED' , 'SHLIB_SUFFIX' , 'AR' , 'ARFLAGS' )
223+ get_config_vars (
224+ 'CC' , 'CXX' , 'CFLAGS' ,
225+ 'CCSHARED' , 'LDSHARED' , 'SHLIB_SUFFIX' , 'AR' , 'ARFLAGS' )
222226
223227 if 'CC' in os .environ :
224228 newcc = os .environ ['CC' ]
@@ -280,7 +284,6 @@ def get_config_h_filename():
280284 return sysconfig .get_config_h_filename ()
281285
282286
283-
284287def get_makefile_filename ():
285288 """Return full pathname of installed Makefile from the Python build."""
286289 return sysconfig .get_makefile_filename ()
@@ -302,6 +305,7 @@ def parse_config_h(fp, g=None):
302305_findvar1_rx = re .compile (r"\$\(([A-Za-z][A-Za-z0-9_]*)\)" )
303306_findvar2_rx = re .compile (r"\${([A-Za-z][A-Za-z0-9_]*)}" )
304307
308+
305309def parse_makefile (fn , g = None ):
306310 """Parse a Makefile-style file.
307311
@@ -310,7 +314,9 @@ def parse_makefile(fn, g=None):
310314 used instead of a new dictionary.
311315 """
312316 from distutils .text_file import TextFile
313- fp = TextFile (fn , strip_comments = 1 , skip_blanks = 1 , join_lines = 1 , errors = "surrogateescape" )
317+ fp = TextFile (
318+ fn , strip_comments = 1 , skip_blanks = 1 , join_lines = 1 ,
319+ errors = "surrogateescape" )
314320
315321 if g is None :
316322 g = {}
@@ -319,7 +325,7 @@ def parse_makefile(fn, g=None):
319325
320326 while True :
321327 line = fp .readline ()
322- if line is None : # eof
328+ if line is None : # eof
323329 break
324330 m = _variable_rx .match (line )
325331 if m :
@@ -363,7 +369,8 @@ def parse_makefile(fn, g=None):
363369 item = os .environ [n ]
364370
365371 elif n in renamed_variables :
366- if name .startswith ('PY_' ) and name [3 :] in renamed_variables :
372+ if name .startswith ('PY_' ) and \
373+ name [3 :] in renamed_variables :
367374 item = ""
368375
369376 elif 'PY_' + n in notdone :
@@ -379,15 +386,16 @@ def parse_makefile(fn, g=None):
379386 if "$" in after :
380387 notdone [name ] = value
381388 else :
382- try : value = int (value )
389+ try :
390+ value = int (value )
383391 except ValueError :
384392 done [name ] = value .strip ()
385393 else :
386394 done [name ] = value
387395 del notdone [name ]
388396
389397 if name .startswith ('PY_' ) \
390- and name [3 :] in renamed_variables :
398+ and name [3 :] in renamed_variables :
391399
392400 name = name [3 :]
393401 if name not in done :
@@ -449,6 +457,7 @@ def get_config_vars(*args):
449457 global _config_vars
450458 if _config_vars is None :
451459 _config_vars = sysconfig .get_config_vars ().copy ()
460+ py39compat .add_ext_suffix (_config_vars )
452461
453462 if args :
454463 vals = []
@@ -458,12 +467,14 @@ def get_config_vars(*args):
458467 else :
459468 return _config_vars
460469
470+
461471def get_config_var (name ):
462472 """Return the value of a single variable using the dictionary
463473 returned by 'get_config_vars()'. Equivalent to
464474 get_config_vars().get(name)
465475 """
466476 if name == 'SO' :
467477 import warnings
468- warnings .warn ('SO is deprecated, use EXT_SUFFIX' , DeprecationWarning , 2 )
478+ warnings .warn (
479+ 'SO is deprecated, use EXT_SUFFIX' , DeprecationWarning , 2 )
469480 return get_config_vars ().get (name )
0 commit comments