Verify that only vendored modules have been imported.
(project, match, root=None)
| 87 | |
| 88 | |
| 89 | def check_modules(project, match, root=None): |
| 90 | """Verify that only vendored modules have been imported.""" |
| 91 | if root is None: |
| 92 | root = project_root(project) |
| 93 | extensions = [] |
| 94 | unvendored = {} |
| 95 | for modname, mod in list(sys.modules.items()): |
| 96 | if not match(modname, mod): |
| 97 | continue |
| 98 | try: |
| 99 | filename = getattr(mod, "__file__", None) |
| 100 | except: # In theory it's possible that any error is raised when accessing __file__ |
| 101 | filename = None |
| 102 | if not filename: # extension module |
| 103 | extensions.append(modname) |
| 104 | elif not filename.startswith(root): |
| 105 | unvendored[modname] = filename |
| 106 | return unvendored, extensions |
| 107 | |
| 108 | |
| 109 | @contextlib.contextmanager |
no test coverage detected
searching dependent graphs…