https://github.com/alexpoulsen/importer
Preventing insanity when dealing with local imports [currently broken in 3.7]
https://github.com/alexpoulsen/importer
import imports module module-loader modules packages python python36 python37
Last synced: 22 days ago
JSON representation
Preventing insanity when dealing with local imports [currently broken in 3.7]
- Host: GitHub
- URL: https://github.com/alexpoulsen/importer
- Owner: AlexPoulsen
- Created: 2018-07-28T03:47:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-30T05:50:16.000Z (over 6 years ago)
- Last Synced: 2025-02-09T22:29:58.861Z (3 months ago)
- Topics: import, imports, module, module-loader, modules, packages, python, python36, python37
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# importer
Preventing insanity when dealing with local imports
Pushing Importer to the interpreter package directory with `push_importer_to_interpreter_path()`
The command copies the folder into itself ignoring git files and preventing infinite looping, initializes Importer with the copied version of itself and pushes it to the interpreter package directory, and deletes the created copy.
```python
import importer
Im = importer.Importer("moduleone", "moduletwo")
Im.moduleone.myfunc("foo", 1, 2)
Im.moduletwo.anotherfunc(3, 4, "bar")
Im.modulethree.func("foo", "bar", "bat") # yes this works, assuming all three packages are in the directory
Im.moduleone.__file__ # './moduleone/__init__.py'
Im.path("moduleone") # '/Users/you/folders/moduleone/__init__.py/'
```Packages with invalid characters in the name (-, /, $, +, etc) are now edited to remove them, and they are replaced with underscores. Even though this should work fine, you should still edit the package's name, if possible, to a valid name. Names starting with a number have it replaced with a _ by default.
Tested on py3.7, but should work on py3.6 as that is when f-strings were added. Importer could be backported further easily.