99import shutil
1010import subprocess
1111import sys
12- import sysconfig
1312import types
1413
1514logger = logging .getLogger (__name__ )
@@ -64,11 +63,10 @@ def create(self, env_dir):
6463 self .system_site_packages = False
6564 self .create_configuration (context )
6665 self .setup_python (context )
67- if not self .upgrade :
68- self .setup_scripts (context )
6966 if self .with_pip :
7067 self ._setup_pip (context )
7168 if not self .upgrade :
69+ self .setup_scripts (context )
7270 self .post_setup (context )
7371 if true_system_site_packages :
7472 # We had set it to False before, now
@@ -159,6 +157,14 @@ def create_configuration(self, context):
159157 f .write ('include-system-site-packages = %s\n ' % incl )
160158 f .write ('version = %d.%d.%d\n ' % sys .version_info [:3 ])
161159
160+ if os .name == 'nt' :
161+ def include_binary (self , f ):
162+ if f .endswith (('.pyd' , '.dll' )):
163+ result = True
164+ else :
165+ result = f .startswith ('python' ) and f .endswith ('.exe' )
166+ return result
167+
162168 def symlink_or_copy (self , src , dst , relative_symlinks_ok = False ):
163169 """
164170 Try symlinking a file, and if that fails, fall back to copying.
@@ -188,9 +194,9 @@ def setup_python(self, context):
188194 binpath = context .bin_path
189195 path = context .env_exe
190196 copier = self .symlink_or_copy
197+ copier (context .executable , path )
191198 dirname = context .python_dir
192199 if os .name != 'nt' :
193- copier (context .executable , path )
194200 if not os .path .islink (path ):
195201 os .chmod (path , 0o755 )
196202 for suffix in ('python' , 'python3' ):
@@ -202,33 +208,32 @@ def setup_python(self, context):
202208 if not os .path .islink (path ):
203209 os .chmod (path , 0o755 )
204210 else :
205- # For normal cases, the venvlauncher will be copied from
206- # our scripts folder. For builds, we need to copy it
207- # manually.
208- if sysconfig .is_python_build (True ):
209- suffix = '.exe'
210- if context .python_exe .lower ().endswith ('_d.exe' ):
211- suffix = '_d.exe'
212-
213- src = os .path .join (dirname , "venvlauncher" + suffix )
214- dst = os .path .join (binpath , context .python_exe )
215- copier (src , dst )
216-
217- src = os .path .join (dirname , "venvwlauncher" + suffix )
218- dst = os .path .join (binpath , "pythonw" + suffix )
219- copier (src , dst )
220-
221- # copy init.tcl over
222- for root , dirs , files in os .walk (context .python_dir ):
223- if 'init.tcl' in files :
224- tcldir = os .path .basename (root )
225- tcldir = os .path .join (context .env_dir , 'Lib' , tcldir )
226- if not os .path .exists (tcldir ):
227- os .makedirs (tcldir )
228- src = os .path .join (root , 'init.tcl' )
229- dst = os .path .join (tcldir , 'init.tcl' )
230- shutil .copyfile (src , dst )
231- break
211+ subdir = 'DLLs'
212+ include = self .include_binary
213+ files = [f for f in os .listdir (dirname ) if include (f )]
214+ for f in files :
215+ src = os .path .join (dirname , f )
216+ dst = os .path .join (binpath , f )
217+ if dst != context .env_exe : # already done, above
218+ copier (src , dst )
219+ dirname = os .path .join (dirname , subdir )
220+ if os .path .isdir (dirname ):
221+ files = [f for f in os .listdir (dirname ) if include (f )]
222+ for f in files :
223+ src = os .path .join (dirname , f )
224+ dst = os .path .join (binpath , f )
225+ copier (src , dst )
226+ # copy init.tcl over
227+ for root , dirs , files in os .walk (context .python_dir ):
228+ if 'init.tcl' in files :
229+ tcldir = os .path .basename (root )
230+ tcldir = os .path .join (context .env_dir , 'Lib' , tcldir )
231+ if not os .path .exists (tcldir ):
232+ os .makedirs (tcldir )
233+ src = os .path .join (root , 'init.tcl' )
234+ dst = os .path .join (tcldir , 'init.tcl' )
235+ shutil .copyfile (src , dst )
236+ break
232237
233238 def _setup_pip (self , context ):
234239 """Installs or upgrades pip in a virtual environment"""
@@ -315,7 +320,7 @@ def install_scripts(self, context, path):
315320 dstfile = os .path .join (dstdir , f )
316321 with open (srcfile , 'rb' ) as f :
317322 data = f .read ()
318- if not srcfile .endswith (( '.exe' , '.pdb' ) ):
323+ if not srcfile .endswith ('.exe' ):
319324 try :
320325 data = data .decode ('utf-8' )
321326 data = self .replace_variables (data , context )
0 commit comments