def _store_python_version(self, python_version): """Configure the python version.""" if python_version: if isinstance(python_version, str): version = utils.version_from_string(python_version) else: version = python_version else: version = sys.version_info[:2] if len(version) != 2: self.error("--python_version must be <major>.<minor>: %r" % python_version) # Check that we have a version supported by pytype. utils.validate_version(version) self.output_options.python_version = version if utils.can_compile_bytecode_natively( self.output_options.python_version): # pytype does not need an exe for bytecode compilation. Abort early to # avoid extracting a large unused exe into /tmp. self.output_options.python_exe = None return for exe in utils.get_python_exes(self.output_options.python_version): exe_version = utils.get_python_exe_version(exe) if exe_version == self.output_options.python_version: self.output_options.python_exe = exe break else: self.error("Need a valid python%d.%d executable in $PATH" % self.output_options.python_version)
def _store_python_exe(self, python_exe): """Postprocess --python_exe.""" if python_exe is None: python_exe, flags = utils.get_python_exe( self.output_options.python_version) user_provided_exe = False else: if isinstance(python_exe, tuple): python_exe, flags = python_exe else: flags = [] user_provided_exe = True python_exe_version = utils.get_python_exe_version(python_exe) if python_exe_version != self.output_options.python_version: if not user_provided_exe: err = ("Need a valid python%d.%d executable in $PATH" % self.output_options.python_version) elif python_exe_version: err = ( "--python_exe version %d.%d does not match " "--python_version %d.%d" % (python_exe_version + self.output_options.python_version)) else: err = "Bad flag --python_exe: could not run %s" % python_exe self.error(err) self.output_options.python_exe = (python_exe, flags)
def _store_python_exe(self, python_exe): """Postprocess --python_exe.""" if python_exe is None and utils.can_compile_bytecode_natively( self.output_options.python_version): # The user has not requested a custom exe and pytype does not need an exe # for bytecode compilation. Abort early to avoid extracting a large unused # exe into /tmp. self.output_options.python_exe = (None, None) return if python_exe is None: python_exe, flags = utils.get_python_exe( self.output_options.python_version) user_provided_exe = False else: if isinstance(python_exe, tuple): python_exe, flags = python_exe else: flags = [] user_provided_exe = True python_exe_version = utils.get_python_exe_version(python_exe) if python_exe_version != self.output_options.python_version: if not user_provided_exe: err = ("Need a valid python%d.%d executable in $PATH" % self.output_options.python_version) elif python_exe_version: err = ("--python_exe version %d.%d does not match " "--python_version %d.%d" % ( python_exe_version + self.output_options.python_version)) else: err = "Bad flag --python_exe: could not run %s" % python_exe self.error(err) self.output_options.python_exe = (python_exe, flags)
def test_get_python_exe_version(self): version = utils.get_python_exe_version(["python"]) self.assertIsInstance(version, tuple) self.assertEqual(len(version), 2)
def testGetPythonExeVersion(self): version = utils.get_python_exe_version("python") self.assertIsInstance(version, tuple) self.assertEqual(len(version), 2)