def make_converters(cwd=None): """For items that need coaxing into their internal representations.""" return { 'exclude': lambda v: file_utils.expand_source_files(v, cwd), 'inputs': lambda v: file_utils.expand_source_files(v, cwd), 'output': lambda v: file_utils.expand_path(v, cwd), 'pythonpath': lambda v: file_utils.expand_pythonpath(v, cwd), }
def make_converters(cwd=None): """For items that need coaxing into their internal representations.""" return { 'exclude': lambda v: file_utils.expand_source_files(v, cwd), 'keep_going': string_to_bool, 'inputs': lambda v: file_utils.expand_source_files(v, cwd), 'output': lambda v: file_utils.expand_path(v, cwd), 'python_version': get_python_version, 'pythonpath': lambda v: file_utils.expand_pythonpath(v, cwd), 'disable': concat_disabled_rules, }
def main(): parser = parse_args.make_parser() args = parser.parse_args(sys.argv[1:]) if args.version: print(io.get_pytype_version()) sys.exit(0) tool_utils.setup_logging_or_die(args.verbosity) if args.generate_config: config.generate_sample_config_or_die(args.generate_config) sys.exit(0) args.filenames = file_utils.expand_source_files(args.filenames) conf = parser.config_from_defaults() # File options overwrite defaults. file_config = config.read_config_file_or_die(args.config) parser.postprocess(file_config, from_strings=True) conf.populate_from(file_config) # Command line arguments overwrite file options. conf.populate_from(args) if not conf.pythonpath: conf.pythonpath = environment.compute_pythonpath(args.filenames) logging.info('\n '.join(['Configuration:'] + str(conf).split('\n'))) if not args.filenames: parser.parser.print_usage() sys.exit(0) # Importlab needs the python exe, so we check it as early as possible. environment.check_python_exe_or_die(conf.python_version) typeshed = environment.initialize_typeshed_or_die() env = create_importlab_environment(conf, typeshed) try: import_graph = importlab.graph.ImportGraph.create(env, args.filenames) except Exception as e: # pylint: disable=broad-except logging.critical('Cannot parse input files:\n%s', str(e)) sys.exit(1) if args.tree: print('Source tree:') importlab.output.print_tree(import_graph) sys.exit(0) if args.unresolved: print('Unresolved dependencies:') for imp in sorted(import_graph.get_all_unresolved()): print(' ', imp.name) sys.exit(0) logging.info('Source tree:\n%s', importlab.output.formatted_deps_list(import_graph)) tool_utils.makedirs_or_die(conf.output, 'Could not create output directory') deps = pytype_runner.deps_from_import_graph(import_graph) runner = pytype_runner.PytypeRunner(args.filenames, deps, conf) runner.run()
def test_cwd(self): with file_utils.Tempdir() as d: fs = [d.create_file(f) for f in self.FILES] pyfiles = [f for f in fs if f.endswith(".py")] # cd to d.path and run with just "." as an argument with file_utils.cd(d.path): self.assertItemsEqual(pyfiles, file_utils.expand_source_files("."))
def test_multiple_magic(self): filenames = ["a.py", "b/c.py"] with file_utils.Tempdir() as d: for f in filenames: d.create_file(f) self.assertEqual( file_utils.expand_source_files("*.py b/*.py", cwd=d.path), {os.path.join(d.path, f) for f in filenames})
def test_magic(self): filenames = ["a.py", "b/c.py"] with file_utils.Tempdir() as d: for f in filenames: d.create_file(f) with file_utils.cd(d.path): self.assertEqual(file_utils.expand_source_files("**/*.py"), {os.path.realpath(f) for f in filenames})
def _test_expand(self, args): with file_utils.Tempdir() as d: fs = [d.create_file(f) for f in self.FILES] pyfiles = [f for f in fs if f.endswith(".py")] self.assertItemsEqual(pyfiles, file_utils.expand_source_files(args, d.path))
def test_find_dir(self): with file_utils.Tempdir() as d: d.create_file(".d/find.py") self.assertEqual( file_utils.expand_source_files(".d/**/*", cwd=d.path), {os.path.join(d.path, ".d", "find.py")})
def test_ignore_dir(self): with file_utils.Tempdir() as d: d.create_file("d1/.d2/ignore.py") self.assertEqual( file_utils.expand_source_files("d1/**/*", cwd=d.path), set())
def test_empty(self): self.assertEqual(file_utils.expand_source_files(""), set())
def _test_expand(self, string): with file_utils.Tempdir() as d: fs = [d.create_file(f) for f in self.FILES] pyfiles = [f for f in fs if f.endswith(".py")] six.assertCountEqual( self, pyfiles, file_utils.expand_source_files(string, d.path))