11import os
22import os .path
3- import re
43import shlex
54import shutil
65import subprocess
6+ import sysconfig
7+ from test import support
78
89
910TESTS_DIR = os .path .dirname (__file__ )
1011TOOL_ROOT = os .path .dirname (TESTS_DIR )
11- SRCDIR = os .path .dirname ( os . path . dirname ( TOOL_ROOT ))
12+ SRCDIR = os .path .abspath ( sysconfig . get_config_var ( 'srcdir' ))
1213
1314MAKE = shutil .which ('make' )
1415FREEZE = os .path .join (TOOL_ROOT , 'freeze.py' )
@@ -75,56 +76,17 @@ def ensure_opt(args, name, value):
7576
7677
7778def copy_source_tree (newroot , oldroot ):
78- print (f'copying the source tree into { newroot } ...' )
79+ print (f'copying the source tree from { oldroot } to { newroot } ...' )
7980 if os .path .exists (newroot ):
8081 if newroot == SRCDIR :
8182 raise Exception ('this probably isn\' t what you wanted' )
8283 shutil .rmtree (newroot )
8384
84- def ignore_non_src (src , names ):
85- """Turns what could be a 1000M copy into a 100M copy."""
86- # Don't copy the ~600M+ of needless git repo metadata.
87- # source only, ignore cached .pyc files.
88- subdirs_to_skip = {'.git' , '__pycache__' }
89- if os .path .basename (src ) == 'Doc' :
90- # Another potential ~250M+ of non test related data.
91- subdirs_to_skip .add ('build' )
92- subdirs_to_skip .add ('venv' )
93- return subdirs_to_skip
94-
95- shutil .copytree (oldroot , newroot , ignore = ignore_non_src )
85+ shutil .copytree (oldroot , newroot , ignore = support .copy_python_src_ignore )
9686 if os .path .exists (os .path .join (newroot , 'Makefile' )):
9787 _run_quiet ([MAKE , 'clean' ], newroot )
9888
9989
100- def get_makefile_var (builddir , name ):
101- regex = re .compile (rf'^{ name } *=\s*(.*?)\s*$' )
102- filename = os .path .join (builddir , 'Makefile' )
103- try :
104- infile = open (filename , encoding = 'utf-8' )
105- except FileNotFoundError :
106- return None
107- with infile :
108- for line in infile :
109- m = regex .match (line )
110- if m :
111- value , = m .groups ()
112- return value or ''
113- return None
114-
115-
116- def get_config_var (builddir , name ):
117- python = os .path .join (builddir , 'python' )
118- if os .path .isfile (python ):
119- cmd = [python , '-c' ,
120- f'import sysconfig; print(sysconfig.get_config_var("{ name } "))' ]
121- try :
122- return _run_stdout (cmd )
123- except subprocess .CalledProcessError :
124- pass
125- return get_makefile_var (builddir , name )
126-
127-
12890##################################
12991# freezing
13092
@@ -151,10 +113,8 @@ def prepare(script=None, outdir=None):
151113
152114 # Run configure.
153115 print (f'configuring python in { builddir } ...' )
154- cmd = [
155- os .path .join (srcdir , 'configure' ),
156- * shlex .split (get_config_var (SRCDIR , 'CONFIG_ARGS' ) or '' ),
157- ]
116+ config_args = shlex .split (sysconfig .get_config_var ('CONFIG_ARGS' ) or '' )
117+ cmd = [os .path .join (srcdir , 'configure' ), * config_args ]
158118 ensure_opt (cmd , 'cache-file' , os .path .join (outdir , 'python-config.cache' ))
159119 prefix = os .path .join (outdir , 'python-installation' )
160120 ensure_opt (cmd , 'prefix' , prefix )
0 commit comments