parse import and from import dicts to a third party package list Args: scan_result (dict): including the import and from import result Returns: list: a list of package ignored 'modelscope' and relative path import
(self, scan_result: dict)
| 416 | pass |
| 417 | |
| 418 | def parse_import(self, scan_result: dict) -> list: |
| 419 | """parse import and from import dicts to a third party package list |
| 420 | |
| 421 | Args: |
| 422 | scan_result (dict): including the import and from import result |
| 423 | |
| 424 | Returns: |
| 425 | list: a list of package ignored 'modelscope' and relative path import |
| 426 | """ |
| 427 | output = [] |
| 428 | output.extend(list(scan_result[IMPORT_KEY].keys())) |
| 429 | output.extend(list(scan_result[FROM_IMPORT_KEY].keys())) |
| 430 | |
| 431 | # get the package name |
| 432 | for index, item in enumerate(output): |
| 433 | if '' == item.split('.')[0]: |
| 434 | output[index] = '.' |
| 435 | else: |
| 436 | output[index] = item.split('.')[0] |
| 437 | |
| 438 | ignored = set() |
| 439 | for item in output: |
| 440 | for ignored_package in IGNORED_PACKAGES: |
| 441 | if item.startswith(ignored_package): |
| 442 | ignored.add(item) |
| 443 | return list(set(output) - set(ignored)) |
| 444 | |
| 445 | def traversal_files(self, path, check_sub_dir=None, include_init=False): |
| 446 | self.file_dirs = [] |
no test coverage detected