I'm trying to setup for myself a number of small-ish support libraries & project in python. I intent it to be modular and manage those as git submodule, to be imported into other git repos. That part works well.
What I can't manage well is the dependancies of those submodule within python. I'm trying to make setuptools.find_package() do that, but I just can't seem to figure it out.
I believe that this answer somewhat has what I am looking for, but it is phrased at such at high level that I cannot seem to get the implementation right.
My objectives:
- I don't want to have to explicitely list the submodule's dependancies in the parent module's requirements.txt or setup.py. I have made it "work" this way. But ultimately on bigger projects that's not a viable path, so I want to do things right from the start.
- The structure should make sense for the submodules as standalone project, as well as when they are used within other project. I don't mind if the structure as to be different from what I have below. I just want to still be able to use the submodules on their own.
Here's what I have:
MyProj
├── MyProj
│ ├── __init__.py
│ ├── main.py
│ └── submodule
│ ├── setup.py
│ └── submodule
│ ├── hello.py
│ └── __init__.py
└── setup.py
MyProj.setup.py:
from setuptools import setup, find_packages
""" a minimalist setup.py sample structure """
setup(
name='MyProj',
version='0.1.0',
author='An Awesome demo of the basics of using pkgs',
author_email='blablabla.it@gmail.com',
packages=find_packages(),
description='An awesome package that does something',
install_requires=["PyYAML"],
)
submodule.setup.py
from setuptools import setup, find_packages
""" a minimalist setup.py sample structure """
setup(
name='submodule',
version='0.1.0',
author='An Awesome demo of the basics of using pkgs',
author_email='blababla.it@gmail.com',
packages=find_packages(),
license='license.txt',
description='An awesome package that does something',
install_requires=["numpy"],
)
MyProj.main:
from MyProj.submodule.submodule.hello import count_matrix
if __name__ == '__main__':
print(count_matrix())
hello.py
just builds a matrix using numpy (to check the submodule's dependancies are properly managed even when imported elsewhere), and then MyProj.main just calls hello.py
.
If I run:
pip install .
from /MyProj, then MyProj installs fine along with its PyYaml dependency:
Successfully built MyProj
Installing collected packages: PyYAML, MyProj
Attempting uninstall: MyProj
Found existing installation: MyProj 0.1.0
Uninstalling MyProj-0.1.0:
Successfully uninstalled MyProj-0.1.0
Successfully installed MyProj-0.1.0 PyYAML-5.3.1
However, if I run MyProj.main, then ModuleNotFoundError: No module named 'numpy'
, and I can see anyway from the previous pip install that numpy wasn't installed. Nor was submodule for that matter.