Return two lists, one with modules that are certainly missing and one with modules that *may* be missing. The latter names could either be submodules *or* just global names in the package. The reason it can't always be determined is that it's impossible to tell which
(self)
| 536 | return missing + maybe |
| 537 | |
| 538 | def any_missing_maybe(self): |
| 539 | """Return two lists, one with modules that are certainly missing |
| 540 | and one with modules that *may* be missing. The latter names could |
| 541 | either be submodules *or* just global names in the package. |
| 542 | |
| 543 | The reason it can't always be determined is that it's impossible to |
| 544 | tell which names are imported when "from module import *" is done |
| 545 | with an extension module, short of actually importing it. |
| 546 | """ |
| 547 | missing = [] |
| 548 | maybe = [] |
| 549 | for name in self.badmodules: |
| 550 | if name in self.excludes: |
| 551 | continue |
| 552 | i = name.rfind(".") |
| 553 | if i < 0: |
| 554 | missing.append(name) |
| 555 | continue |
| 556 | subname = name[i+1:] |
| 557 | pkgname = name[:i] |
| 558 | pkg = self.modules.get(pkgname) |
| 559 | if pkg is not None: |
| 560 | if pkgname in self.badmodules[name]: |
| 561 | # The package tried to import this module itself and |
| 562 | # failed. It's definitely missing. |
| 563 | missing.append(name) |
| 564 | elif subname in pkg.globalnames: |
| 565 | # It's a global in the package: definitely not missing. |
| 566 | pass |
| 567 | elif pkg.starimports: |
| 568 | # It could be missing, but the package did an "import *" |
| 569 | # from a non-Python module, so we simply can't be sure. |
| 570 | maybe.append(name) |
| 571 | else: |
| 572 | # It's not a global in the package, the package didn't |
| 573 | # do funny star imports, it's very likely to be missing. |
| 574 | # The symbol could be inserted into the package from the |
| 575 | # outside, but since that's not good style we simply list |
| 576 | # it missing. |
| 577 | missing.append(name) |
| 578 | else: |
| 579 | missing.append(name) |
| 580 | missing.sort() |
| 581 | maybe.sort() |
| 582 | return missing, maybe |
| 583 | |
| 584 | def replace_paths_in_code(self, co): |
| 585 | new_filename = original_filename = os.path.normpath(co.co_filename) |