Python Forum
A bash script that is a hack to enable very easy Python Imports - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: A bash script that is a hack to enable very easy Python Imports (/thread-11978.html)



A bash script that is a hack to enable very easy Python Imports - vedant13 - Aug-03-2018

Python projects that have complex codebase directory structures introduce a fairly common problem with imports within the project. While providing absolute paths is recommended, it is cumbersome, repetitive, and rather boilerplate. Absolute imports may also decrease application portability. pyosphere.sh mitigates these issues by simply providing a flattened execution environment, allowing all files to relatively import each other trivially, while allowing developers to maintain their choice of directory structure.

Note: This is just a hack to make things easy while importing. Use at own will.

I do hope people will like this since it does make importing files easy as well as running files from other directories as well.

It is completely open source and can be found at: https://github.com/vedantpuri/pyosphere

Feel free to check it out and leave behind a star if you like it !


RE: A bash script that is a hack to enable very easy Python Imports - micseydel - Aug-04-2018

Could you give some examples of the code you think is bad and the code you can write instead?


RE: A bash script that is a hack to enable very easy Python Imports - wavic - Aug-04-2018

You don't need bash for that.

If you want to import foo you can scan for foo.py and add its full path to the PYTHONPATH.
All this can be done in try/except block.