Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve dependencies of Python Git Submodule

Tags:

git

python

I have Python projects A, B, and C in separate git repos. They're using some similar code in each so I want to refactor the code into a separate, shared repository.The Python code in this repository is really just a few helper classes. I can include the files in this new repo in projects A, B, and C as a git-submodule.

The problem I have now though is that if the code in the git submodule has external pip dependencies, how do the top-level projects resolve those dependencies in addition to their own?

Perhaps git-submodules are not the right approach here, but I really want to avoid setting up a private pypi server for what amounts to 3-4 lightweight modules/classes.

like image 221
swigganicks Avatar asked Oct 16 '22 13:10

swigganicks


1 Answers

The problem I have now though is that if the code in the git submodule has external pip dependencies, how do the top-level projects resolve those dependencies in addition to their own?

In your sub-module repository, include your dependencies in requirements.txt as usual.

Then in your documentation, be sure to include instructions on installing the sub-module package before installing A, B, or C.

For an example, lets say that package A is foo, and the sub-module is bar.

tree
.
└── foo
    ├── bar
    │   ├── bar
    │   │   └── __init__.py
    │   ├── requirements.txt # external pip dependencies
    │   └── setup.py
    ├── foo
    │   └── __init__.py
    ├── requirements.txt
    └── setup.py # include 

4 directories, 6 files

Then in your documentation you can include something like this,


Installation for Foo

# Initialize submodule(s)
git submodule update --init --recursive

# First install bar
cd bar

# Resolve any dependencies for bar
pip install -r requirements.txt

# Install bar
python setup.py install

# Now install foo
cd ..

# Resolve any other dependencies for foo
pip install -r requirements.txt

# Install foo
python setup.py install

Note: This should be done for all three repositories, e.g., A, B, and C.


Resources:

  • https://github.com/pypa/sampleproject
like image 104
oxr463 Avatar answered Oct 19 '22 03:10

oxr463