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 main(): argument_parser = make_parser() opts = argument_parser.parse_args() python_version = utils.version_from_string(opts.python_version) try: utils.validate_version(python_version) except utils.UsageError as e: sys.stderr.write("Usage error: %s\n" % utils.message(e)) sys.exit(1) with open(opts.input) as fi: sourcecode = fi.read() try: parsed = parser.parse_string(sourcecode, filename=opts.input, python_version=python_version) except parser.ParseError as e: sys.stderr.write(str(e)) sys.exit(1) if opts.optimize: parsed = optimize.Optimize(parsed, builtins.GetBuiltinsPyTD(python_version), lossy=opts.lossy, use_abcs=opts.use_abcs, max_union=opts.max_union, remove_mutable=opts.remove_mutable, can_do_lookup=False) if opts.output is not None: out_text = pytd_utils.Print(parsed, opts.multiline_args) if opts.output == "-": sys.stdout.write(out_text) else: with open(opts.output, "w") as out: out.write(out_text)
def _store_python_version(self, python_version): """Configure the python version.""" self.output_options.python_version = utils.split_version( python_version) if len(self.output_options.python_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(self.output_options.python_version)
def _store_python_version(self, python_version): """Configure the python version.""" self.python_version = utils.parse_version(python_version) if len(self.python_version) != 2: raise optparse.OptionValueError( "--python_version must be <major>.<minor>: %r" % python_version) # Check that we have a version supported by pytype. utils.validate_version(self.python_version)
def _store_python_version(self, python_version): """Configure the python version.""" if python_version: if isinstance(python_version, str): self.output_options.python_version = utils.split_version(python_version) else: self.output_options.python_version = python_version else: self.output_options.python_version = sys.version_info[:2] if len(self.output_options.python_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(self.output_options.python_version)
def _validate_version_helper(self, python_version): with self.assertRaises(utils.UsageError): utils.validate_version(python_version)