2

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
MrTux
  • 32,350
  • 30
  • 109
  • 146
Pim Reijersen
  • 1,123
  • 9
  • 33

2 Answers2

1

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: https://stackoverflow.com/a/15676423/5784822

Community
  • 1
  • 1
Sune Kjærgård
  • 688
  • 6
  • 11
-1

You simply have to grab the content of the submodule:

git submodule init
git submodule update

This will checkout all the content of the submodules into your working directory under the submodule folder.


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?

Yep

In this case you will have to use subtree instead of submodules. The main difference between subtree and submodule is that subtree content is managed at the root level so you will be able to use checkout command to checkout any content from any path in your project while in submodules you cant, and you will need to copy it.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167