##// END OF EJS Templates
pycompat: make fewer assumptions about sys.executable...
Rodrigo Damazio Bovendorp -
r42723:49998d5b default
parent child Browse files
Show More
@@ -138,7 +138,9 b' def _getmtimepaths(ui):'
138 modules.append(__version__)
138 modules.append(__version__)
139 except ImportError:
139 except ImportError:
140 pass
140 pass
141 files = [pycompat.sysexecutable]
141 files = []
142 if pycompat.sysexecutable:
143 files.append(pycompat.sysexecutable)
142 for m in modules:
144 for m in modules:
143 try:
145 try:
144 files.append(pycompat.fsencode(inspect.getabsfile(m)))
146 files.append(pycompat.fsencode(inspect.getabsfile(m)))
@@ -1240,7 +1240,7 b' def debuginstall(ui, **opts):'
1240
1240
1241 # Python
1241 # Python
1242 fm.write('pythonexe', _("checking Python executable (%s)\n"),
1242 fm.write('pythonexe', _("checking Python executable (%s)\n"),
1243 pycompat.sysexecutable)
1243 pycompat.sysexecutable or _("unknown"))
1244 fm.write('pythonver', _("checking Python version (%s)\n"),
1244 fm.write('pythonver', _("checking Python version (%s)\n"),
1245 ("%d.%d.%d" % sys.version_info[:3]))
1245 ("%d.%d.%d" % sys.version_info[:3]))
1246 fm.write('pythonlib', _("checking Python lib (%s)...\n"),
1246 fm.write('pythonlib', _("checking Python lib (%s)...\n"),
@@ -282,7 +282,16 b' def Popen4(cmd, wd, timeout, env=None):'
282
282
283 return p
283 return p
284
284
285 PYTHON = _bytespath(sys.executable.replace('\\', '/'))
285 if sys.executable:
286 sysexecutable = sys.executable
287 elif os.environ.get('PYTHONEXECUTABLE'):
288 sysexecutable = os.environ['PYTHONEXECUTABLE']
289 elif os.environ.get('PYTHON'):
290 sysexecutable = os.environ['PYTHON']
291 else:
292 raise AssertionError('Could not find Python interpreter')
293
294 PYTHON = _bytespath(sysexecutable.replace('\\', '/'))
286 IMPL_PATH = b'PYTHONPATH'
295 IMPL_PATH = b'PYTHONPATH'
287 if 'java' in sys.platform:
296 if 'java' in sys.platform:
288 IMPL_PATH = b'JYTHONPATH'
297 IMPL_PATH = b'JYTHONPATH'
@@ -1094,7 +1103,7 b' class Test(unittest.TestCase):'
1094 env["HGRCPATH"] = _strpath(os.path.join(self._threadtmp, b'.hgrc'))
1103 env["HGRCPATH"] = _strpath(os.path.join(self._threadtmp, b'.hgrc'))
1095 env["DAEMON_PIDS"] = _strpath(os.path.join(self._threadtmp,
1104 env["DAEMON_PIDS"] = _strpath(os.path.join(self._threadtmp,
1096 b'daemon.pids'))
1105 b'daemon.pids'))
1097 env["HGEDITOR"] = ('"' + sys.executable + '"'
1106 env["HGEDITOR"] = ('"' + sysexecutable + '"'
1098 + ' -c "import sys; sys.exit(0)"')
1107 + ' -c "import sys; sys.exit(0)"')
1099 env["HGUSER"] = "test"
1108 env["HGUSER"] = "test"
1100 env["HGENCODING"] = "ascii"
1109 env["HGENCODING"] = "ascii"
@@ -2349,7 +2358,7 b' class TextTestRunner(unittest.TextTestRu'
2349 withhg = self._runner.options.with_hg
2358 withhg = self._runner.options.with_hg
2350 if withhg:
2359 if withhg:
2351 opts += ' --with-hg=%s ' % shellquote(_strpath(withhg))
2360 opts += ' --with-hg=%s ' % shellquote(_strpath(withhg))
2352 rtc = '%s %s %s %s' % (sys.executable, sys.argv[0], opts,
2361 rtc = '%s %s %s %s' % (sysexecutable, sys.argv[0], opts,
2353 test)
2362 test)
2354 data = pread(bisectcmd + ['--command', rtc])
2363 data = pread(bisectcmd + ['--command', rtc])
2355 m = re.search(
2364 m = re.search(
@@ -3003,25 +3012,25 b' class TestRunner(object):'
3003 # Administrator rights.
3012 # Administrator rights.
3004 if getattr(os, 'symlink', None) and os.name != 'nt':
3013 if getattr(os, 'symlink', None) and os.name != 'nt':
3005 vlog("# Making python executable in test path a symlink to '%s'" %
3014 vlog("# Making python executable in test path a symlink to '%s'" %
3006 sys.executable)
3015 sysexecutable)
3007 mypython = os.path.join(self._tmpbindir, pyexename)
3016 mypython = os.path.join(self._tmpbindir, pyexename)
3008 try:
3017 try:
3009 if os.readlink(mypython) == sys.executable:
3018 if os.readlink(mypython) == sysexecutable:
3010 return
3019 return
3011 os.unlink(mypython)
3020 os.unlink(mypython)
3012 except OSError as err:
3021 except OSError as err:
3013 if err.errno != errno.ENOENT:
3022 if err.errno != errno.ENOENT:
3014 raise
3023 raise
3015 if self._findprogram(pyexename) != sys.executable:
3024 if self._findprogram(pyexename) != sysexecutable:
3016 try:
3025 try:
3017 os.symlink(sys.executable, mypython)
3026 os.symlink(sysexecutable, mypython)
3018 self._createdfiles.append(mypython)
3027 self._createdfiles.append(mypython)
3019 except OSError as err:
3028 except OSError as err:
3020 # child processes may race, which is harmless
3029 # child processes may race, which is harmless
3021 if err.errno != errno.EEXIST:
3030 if err.errno != errno.EEXIST:
3022 raise
3031 raise
3023 else:
3032 else:
3024 exedir, exename = os.path.split(sys.executable)
3033 exedir, exename = os.path.split(sysexecutable)
3025 vlog("# Modifying search path to find %s as %s in '%s'" %
3034 vlog("# Modifying search path to find %s as %s in '%s'" %
3026 (exename, pyexename, exedir))
3035 (exename, pyexename, exedir))
3027 path = os.environ['PATH'].split(os.pathsep)
3036 path = os.environ['PATH'].split(os.pathsep)
@@ -3048,7 +3057,7 b' class TestRunner(object):'
3048
3057
3049 # Run installer in hg root
3058 # Run installer in hg root
3050 script = os.path.realpath(sys.argv[0])
3059 script = os.path.realpath(sys.argv[0])
3051 exe = sys.executable
3060 exe = sysexecutable
3052 if PYTHON3:
3061 if PYTHON3:
3053 compiler = _bytespath(compiler)
3062 compiler = _bytespath(compiler)
3054 script = _bytespath(script)
3063 script = _bytespath(script)
General Comments 0
You need to be logged in to leave comments. Login now