354 shutil.rmtree(HGTMP, True) |
354 shutil.rmtree(HGTMP, True) |
355 |
355 |
356 def usecorrectpython(): |
356 def usecorrectpython(): |
357 # some tests run python interpreter. they must use same |
357 # some tests run python interpreter. they must use same |
358 # interpreter we use or bad things will happen. |
358 # interpreter we use or bad things will happen. |
359 exedir, exename = os.path.split(sys.executable) |
359 pyexename = sys.platform == 'win32' and 'python.exe' or 'python' |
360 if exename in ('python', 'python.exe'): |
|
361 path = findprogram(exename) |
|
362 if os.path.dirname(path) == exedir: |
|
363 return |
|
364 else: |
|
365 exename = 'python' |
|
366 if sys.platform == 'win32': |
|
367 exename = 'python.exe' |
|
368 if getattr(os, 'symlink', None): |
360 if getattr(os, 'symlink', None): |
369 vlog("# Making python executable in test path a symlink to '%s'" % |
361 vlog("# Making python executable in test path a symlink to '%s'" % |
370 sys.executable) |
362 sys.executable) |
371 mypython = os.path.join(BINDIR, exename) |
363 mypython = os.path.join(BINDIR, pyexename) |
372 try: |
364 try: |
373 os.symlink(sys.executable, mypython) |
365 if os.readlink(mypython) == sys.executable: |
|
366 return |
|
367 os.unlink(mypython) |
374 except OSError, err: |
368 except OSError, err: |
375 # child processes may race, which is harmless |
369 if err.errno != errno.ENOENT: |
376 if err.errno != errno.EEXIST: |
|
377 raise |
370 raise |
|
371 if findprogram(pyexename) != sys.executable: |
|
372 try: |
|
373 os.symlink(sys.executable, mypython) |
|
374 except OSError, err: |
|
375 # child processes may race, which is harmless |
|
376 if err.errno != errno.EEXIST: |
|
377 raise |
378 else: |
378 else: |
379 vlog("# Modifying search path to find %s in '%s'" % (exename, exedir)) |
379 exedir, exename = os.path.split(sys.executable) |
|
380 vlog("# Modifying search path to find %s as %s in '%s'" % |
|
381 (exename, pyexename, exedir)) |
380 path = os.environ['PATH'].split(os.pathsep) |
382 path = os.environ['PATH'].split(os.pathsep) |
381 while exedir in path: |
383 while exedir in path: |
382 path.remove(exedir) |
384 path.remove(exedir) |
383 os.environ['PATH'] = os.pathsep.join([exedir] + path) |
385 os.environ['PATH'] = os.pathsep.join([exedir] + path) |
384 if not findprogram(exename): |
386 if not findprogram(pyexename): |
385 print "WARNING: Cannot find %s in search path" % exename |
387 print "WARNING: Cannot find %s in search path" % pyexename |
386 |
388 |
387 def installhg(options): |
389 def installhg(options): |
388 vlog("# Performing temporary installation of HG") |
390 vlog("# Performing temporary installation of HG") |
389 installerrs = os.path.join("tests", "install.err") |
391 installerrs = os.path.join("tests", "install.err") |
390 compiler = '' |
392 compiler = '' |