| 377 | |
| 378 | |
| 379 | class FilesAstScanning(object): |
| 380 | |
| 381 | def __init__(self) -> None: |
| 382 | self.astScaner = AstScanning() |
| 383 | self.file_dirs = [] |
| 384 | self.requirement_dirs = [] |
| 385 | |
| 386 | def _parse_import_path(self, |
| 387 | import_package: str, |
| 388 | current_path: str = None) -> str: |
| 389 | """ |
| 390 | Args: |
| 391 | import_package (str): relative import or abs import |
| 392 | current_path (str): path/to/current/file |
| 393 | """ |
| 394 | if import_package.startswith(IGNORED_PACKAGES[0]): |
| 395 | return MODELSCOPE_PATH + '/' + '/'.join( |
| 396 | import_package.split('.')[1:]) + '.py' |
| 397 | elif import_package.startswith(IGNORED_PACKAGES[1]): |
| 398 | current_path_list = current_path.split('/') |
| 399 | import_package_list = import_package.split('.') |
| 400 | level = 0 |
| 401 | for index, item in enumerate(import_package_list): |
| 402 | if item != '': |
| 403 | level = index |
| 404 | break |
| 405 | |
| 406 | abs_path_list = current_path_list[0:-level] |
| 407 | abs_path_list.extend(import_package_list[index:]) |
| 408 | return '/' + '/'.join(abs_path_list) + '.py' |
| 409 | else: |
| 410 | return current_path |
| 411 | |
| 412 | def _traversal_import( |
| 413 | self, |
| 414 | import_abs_path, |
| 415 | ): |
| 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] |
no outgoing calls
searching dependent graphs…