Pim Reijersen Pim Reijersen - 27 days ago 7
Git Question

Import submodule with missing __init__

I used the following command to add an existing project as submodule to my project.

git submodule add https://github.com/...


However, the submodule root does not contain an
__init__.py
file. Is it possible to import the features from this submodule without making changes to it?

Contents of .gitmodules:

[submodule "name"]
path = name
url = https://github.com/name

Answer

I believe the solution is to add your submodule to your project, and than add a symbolic link into the actual package next to the submodule (or where ever it makes sense to put it)

So you'll have

project
  - submodule
    - package
    - setup.py
  - my_awesome_script.py
  - package (symbolic link to submodule/package)

then you can just import it through the symbolic link.

import package

package.work_your_magic()

Source: http://stackoverflow.com/a/15676423/5784822