Here is my current directory structure:
proj/
proj/__init__.py
proj/submodFolder/
proj/submodFolder/submod/
proj/submodFolder/submod/__init__.py
I’m writing a project and I would like to have import submod or even import submodFolder.submod in proj/__init__.py. However without __init__.py in submodFolder this won’t work.
Assume submodFolder is a git repository that i have sub-repoed (a third party library if you will); adding the requisite __init__.py will break the git subrepo and complicate updating libraries from their master repos.
Assuming submodFolder is an immutable git sub-repo what is the best way to push python down the dirtree to the module? Modifying the python path seemed the nearest solution to me – but none of the questions already asked assumed an immutable submodFolder.
Examples welcome, note relative paths.
If you prefer not to modify the PYTHONPATH environment variable, you can modify
sys.pathinside of proj/__init__.py, the following should work:Step-by-step code with comments, so it makes a little more sense: