示例#1
0
def run_pytype(args, dry_run, typeshed_location):
    """Runs pytype, returning the stderr if any."""
    if dry_run:
        return None
    old_typeshed_home = os.environ.get(TYPESHED_HOME, UNSET)
    os.environ[TYPESHED_HOME] = typeshed_location
    try:
        io.parse_pyi(config.Options(args))
    except Exception:
        stderr = traceback.format_exc()
    else:
        stderr = None
    if old_typeshed_home is UNSET:
        del os.environ[TYPESHED_HOME]
    else:
        os.environ[TYPESHED_HOME] = old_typeshed_home
    return stderr
示例#2
0
def _run_pytype(options):
    """Run pytype with the given configuration options."""
    if options.generate_builtins:
        return _generate_builtins_pickle(options)
    elif options.parse_pyi:
        return io.parse_pyi(options)
    else:
        return io.process_one_file(options)
def run_pytype(*, filename: str, python_version: str, typeshed_location: str) -> Optional[str]:
    """Runs pytype, returning the stderr if any."""
    options = pytype_config.Options.create(
        filename, module_name=_get_module_name(filename), parse_pyi=True, python_version=python_version
    )
    old_typeshed_home = os.environ.get(TYPESHED_HOME, UNSET)
    os.environ[TYPESHED_HOME] = typeshed_location
    try:
        pytype_io.parse_pyi(options)
    except Exception:
        stderr = traceback.format_exc()
    else:
        stderr = None
    if old_typeshed_home is UNSET:
        del os.environ[TYPESHED_HOME]
    else:
        os.environ[TYPESHED_HOME] = old_typeshed_home
    return stderr
示例#4
0
 def communicate(self):
     if self.results:
         return self.results
     old_env = {}
     if self.env:
         for var, val in self.env.items():
             old_env[var] = os.environ.get(var, UNSET)
             os.environ[var] = val
     try:
         io.parse_pyi(config.Options(self.args[1:]))
     except Exception:
         self.results = (1, '', traceback.format_exc())
     else:
         self.results = (0, '', '')
     for var, val in old_env.items():
         if val is UNSET:
             del os.environ[var]
         else:
             os.environ[var] = val
     return self.results