def check(self, files_or_modules): """main checking entry: check a list of files or modules from their name. files_or_modules is either a string or list of strings presenting modules to check. """ self.initialize() if not isinstance(files_or_modules, (list, tuple)): files_or_modules = (files_or_modules, ) if self.config.from_stdin: if len(files_or_modules) != 1: raise exceptions.InvalidArgsError( "Missing filename required for --from-stdin") filepath = files_or_modules[0] with fix_import_path(files_or_modules): self._check_files( functools.partial(self.get_ast, data=_read_stdin()), [self._get_file_descr_from_stdin(filepath)], ) elif self.config.jobs == 1: with fix_import_path(files_or_modules): self._check_files(self.get_ast, self._iterate_file_descrs(files_or_modules)) else: check_parallel( self, self.config.jobs, self._iterate_file_descrs(files_or_modules), files_or_modules, )
def run(self, args): """checking arguments and run project""" if not args: print(self.help()) return 1 with fix_import_path(args): project = project_from_files( args, project_name=self.config.project, black_list=self.config.ignore_list, ) linker = Linker(project, tag=True) handler = DiadefsHandler(self.config) diadefs = handler.get_diadefs(project, linker) writer.DiagramWriter(self.config).write(diadefs) return 0
def test_import_sibling_module_from_namespace( initialized_linter: PyLinter) -> None: """If the parent directory above `namespace` is on sys.path, ensure that modules under `namespace` can import each other without raising `import-error`.""" linter = initialized_linter with tempdir() as tmpdir: create_files(["namespace/submodule1.py", "namespace/submodule2.py"]) second_path = Path("namespace/submodule2.py") with open(second_path, "w", encoding="utf-8") as f: f.write("""\"\"\"This module imports submodule1.\"\"\" import submodule1 print(submodule1) """) os.chdir("namespace") # Add the parent directory to sys.path with fix_import_path([tmpdir]): linter.check(["submodule2.py"]) assert not linter.stats.by_msg