简体   繁体   中英

How to resolve dependencies of Python Git Submodule

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.

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, eg, A, B, and C.


Resources:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM