Python: Allow absolute imports in directories with scripts

Fixes the import logic to account for absolute imports.

We do this by classifying which files and folders may serve as the
entry point for execution, based on a few simple heuristics. If the
file `module.py` is in the same folder as a file `main.py` that may be
executed directly, then we allow `module` to be a valid name for
`module.py` so that `import module` will work as expected.
This commit is contained in:
Taus Brock-Nannestad
2021-03-23 18:20:53 +01:00
parent 4289e358bf
commit 17d1768259
3 changed files with 38 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
| main | code/main.py:0:0:0:0 | Script main |
| module | code/module.py:0:0:0:0 | Module module |
| package | code/package:0:0:0:0 | Package package |
| package.__init__ | code/package/__init__.py:0:0:0:0 | Module package.__init__ |
| package.package_main | code/package/package_main.py:0:0:0:0 | Module package.package_main |