예제 #1
0
 def cal_import_deps(self, src: Path, stub: Path):
     with os.scandir(src) as entries:
         for entry in entries:
             if entry.is_dir():
                 stub_dir_path = find(entry.name, stub)
                 self.cal_import_deps(entry, stub_dir_path)
             elif entry.name.endswith(".py"):
                 stub_file = find(entry.name[:-3] + ".pyi", stub)
                 if stub_file is None:
                     self.cal_import_deps_single(Path(entry), Path(entry))
                 else:
                     self.cal_import_deps_single(Path(entry), Path(entry))
                     self.cal_import_deps_single(stub_file, Path(entry))
예제 #2
0
 def cal_not_match_stub(self, src: Path, stub: Path):
     with os.scandir(stub) as entries:
         for entry in entries:
             if entry.is_dir():
                 src_dir_path = find(entry.name, src)
                 if src_dir_path is None:
                     self.file_count(entry)
                 else:
                     self.cal_not_match_stub(src_dir_path, entry)
             elif entry.name.endswith(".pyi"):
                 src_file = find(entry.name[:-4] + ".py", src)
                 if src_file is None:
                     self.not_match_lst.append(
                         Path(entry).relative_to(self.stub_root))
 def cal_cov(self, src: pathlib.Path, stub: Path):
     with os.scandir(src) as entries:
         for entry in entries:
             if entry.is_dir():
                 stub_dir_path = find(entry.name, stub)
                 if stub_dir_path is None:
                     self.fun_count(entry)
                 else:
                     self.cal_cov(entry, stub_dir_path)
             elif entry.name.endswith(".py"):
                 stub_file = find(entry.name[:-3] + ".pyi", stub)
                 if stub_file is None:
                     self.fun_count(entry)
                 else:
                     self._fun_count_pair(Path(entry), stub_file)
    def cal_class_use(self, src: Path = None, stub: Path = None):
        if src is None:
            src = self.src_dir
        if stub is None:
            stub = self.stub_dir

        with os.scandir(src) as entries:
            for entry in entries:
                if entry.is_dir():
                    stub_dir_path = find(entry.name, stub)
                    if stub_dir_path is None:
                        self.class_count(Path(entry))
                    else:
                        self.cal_class_use(Path(entry), stub_dir_path)
                elif entry.name.endswith(".py"):
                    stub_file = find(entry.name[:-3] + ".pyi", stub)
                    if stub_file is None:
                        self.class_count(Path(entry))
                    else:
                        self.class_count_pair(Path(entry), stub_file)
예제 #5
0
 def cal_cov(self, src: pathlib.Path, stub: Path):
     with os.scandir(src) as entries:
         for entry in entries:
             if entry.is_dir():
                 stub_dir_path = find(entry.name, stub)
                 if stub_dir_path is None:
                     self.file_count(entry)
                 else:
                     self.cal_cov(entry, stub_dir_path)
             elif entry.name.endswith(".py"):
                 self.file_count(entry)
                 stub_file = find(entry.name[:-3] + ".pyi", stub)
                 if stub_file is not None:
                     self._matched_stub_num += 1
                     with open(stub_file, "r", encoding="utf-8") as file:
                         lines = file.read().split('\n')
                         for line in lines:
                             tokens = line.split()
                             if tokens:
                                 if tokens[0][0] != '#':
                                     self._matched_stub_line_num += 1