@@ -155,47 +155,66 @@ def create_configuration(self, context):
155155 f .write ('include-system-site-packages = %s\n ' % incl )
156156 f .write ('version = %d.%d.%d\n ' % sys .version_info [:3 ])
157157
158- def symlink_or_copy (self , src , dst , relative_symlinks_ok = False ):
159- """
160- Try symlinking a file, and if that fails, fall back to copying.
161- """
162- force_copy = not self .symlinks
163- if not force_copy :
164- try :
165- if not os .path .islink (dst ): # can't link to itself!
158+ if os .name != 'nt' :
159+ def symlink_or_copy (self , src , dst , relative_symlinks_ok = False ):
160+ """
161+ Try symlinking a file, and if that fails, fall back to copying.
162+ """
163+ force_copy = not self .symlinks
164+ if not force_copy :
165+ try :
166+ if not os .path .islink (dst ): # can't link to itself!
167+ if relative_symlinks_ok :
168+ assert os .path .dirname (src ) == os .path .dirname (dst )
169+ os .symlink (os .path .basename (src ), dst )
170+ else :
171+ os .symlink (src , dst )
172+ except Exception : # may need to use a more specific exception
173+ logger .warning ('Unable to symlink %r to %r' , src , dst )
174+ force_copy = True
175+ if force_copy :
176+ shutil .copyfile (src , dst )
177+ else :
178+ def symlink_or_copy (self , src , dst , relative_symlinks_ok = False ):
179+ """
180+ Try symlinking a file, and if that fails, fall back to copying.
181+ """
182+ bad_src = os .path .lexists (src ) and not os .path .exists (src )
183+ if self .symlinks and not bad_src and not os .path .islink (dst ):
184+ try :
166185 if relative_symlinks_ok :
167186 assert os .path .dirname (src ) == os .path .dirname (dst )
168187 os .symlink (os .path .basename (src ), dst )
169188 else :
170189 os .symlink (src , dst )
171- except Exception : # may need to use a more specific exception
172- logger .warning ('Unable to symlink %r to %r' , src , dst )
173- force_copy = True
174- if force_copy :
175- if os .name == 'nt' :
176- # On Windows, we rewrite symlinks to our base python.exe into
177- # copies of venvlauncher.exe
178- basename , ext = os .path .splitext (os .path .basename (src ))
179- srcfn = os .path .join (os .path .dirname (__file__ ),
180- "scripts" ,
181- "nt" ,
182- basename + ext )
183- # Builds or venv's from builds need to remap source file
184- # locations, as we do not put them into Lib/venv/scripts
185- if sysconfig .is_python_build (True ) or not os .path .isfile (srcfn ):
186- if basename .endswith ('_d' ):
187- ext = '_d' + ext
188- basename = basename [:- 2 ]
189- if basename == 'python' :
190- basename = 'venvlauncher'
191- elif basename == 'pythonw' :
192- basename = 'venvwlauncher'
193- src = os .path .join (os .path .dirname (src ), basename + ext )
194- else :
195- src = srcfn
196- if not os .path .exists (src ):
197- logger .warning ('Unable to copy %r' , src )
198190 return
191+ except Exception : # may need to use a more specific exception
192+ logger .warning ('Unable to symlink %r to %r' , src , dst )
193+
194+ # On Windows, we rewrite symlinks to our base python.exe into
195+ # copies of venvlauncher.exe
196+ basename , ext = os .path .splitext (os .path .basename (src ))
197+ srcfn = os .path .join (os .path .dirname (__file__ ),
198+ "scripts" ,
199+ "nt" ,
200+ basename + ext )
201+ # Builds or venv's from builds need to remap source file
202+ # locations, as we do not put them into Lib/venv/scripts
203+ if sysconfig .is_python_build (True ) or not os .path .isfile (srcfn ):
204+ if basename .endswith ('_d' ):
205+ ext = '_d' + ext
206+ basename = basename [:- 2 ]
207+ if basename == 'python' :
208+ basename = 'venvlauncher'
209+ elif basename == 'pythonw' :
210+ basename = 'venvwlauncher'
211+ src = os .path .join (os .path .dirname (src ), basename + ext )
212+ else :
213+ src = srcfn
214+ if not os .path .exists (src ):
215+ if not bad_src :
216+ logger .warning ('Unable to copy %r' , src )
217+ return
199218
200219 shutil .copyfile (src , dst )
201220
0 commit comments