Chenlu
Chenlu

Reputation: 459

Python namespace sub-package depending on another sub-package fails to install

My goal is to create a namespace package with two sub-packages: foo and bar (dependent on foo), and push the namespace package to a git repo (without publishing it to PyPI) so that I can install either sub-package with the repo url.

I'm following this tutorial to create the namespace structure:

root/
 ├ setup.py
 └ microlibs/
    ├ foo/
    │  ├ setup.py
    │  ├ macrolib/
    │     └ foo/
    │        ├ __init__.py
    │        ├ module1.py
    │        ├ ...
    │        └ moduleN.py
    .
    .
    .
    └ bar/
       ├ setup.py
       ├ macrolib/
          └ bar/
             ├ __init__.py
             ├ module1.py
             ├ ...
             └ moduleN.py

The setup.py file of foo has no dependencies:

foo/setup.py

from setuptools import setup
microlib_name = 'macrolib.foo'
setup(
    name=microlib_name,
    version="0.1.0",
    namespace_packages=['macrolib'],
    packages=[microlib_name],
    install_requires=[]
)

Since bar's dependencies include foo, the setup.py of bar includes macrolib.bar in install_requires list:

bar/setup.py

from setuptools import setup
microlib_name = 'macrolib.bar'
setup(
    name=microlib_name,
    version="0.1.0",
    namespace_packages=['macrolib'],
    packages=[microlib_name],
    install_requires=[
        'macrolib.foo'
    ]
)

After pushed to bitbucket repo, I can install macrolib.foo without problems with a subdirectory of the repo.

$ pip install git+http://path/to/repo.git@<branch name>#"subdirectory=foo&egg=macrolib.foo"

With macrolib.foo installed, I can also install macrolib.bar without problems with a subdirectory of the repo.

$ pip install git+http://path/to/repo.git@<branch name>#"subdirectory=bar&egg=macrolib.bar"

However, if I try to install macrolib.bar without installing macrolib.foo first, the installation failed.

$ pip install git+http://path/to/repo.git@<branch name>#"subdirectory=bar&egg=macrolib.bar"

error:

Collecting macrolib.foo (from macrolib.bar==0.1.0)
  Could not find a version that satisfies the requirement macrolib.foo (from macrolib.bar==0.1.0) (from versions: )
No matching distribution found for macrolib.foo (from macrolib.bar==0.1.0)

I'm guessing this is because of the missing of dependency_links in bar/setup.py. So I tried different combinations of link urls, all failed with the same error.

Formats I have tried:

dependency_links=['http://path/to/repo.git@<branch name>#"subdirectory=foo&egg=macrolib.foo"']

dependency_links=['http://path/to/repo.git@<branch name>#subdirectory=foo&egg=macrolib.foo']

dependency_links=['http://path/to/repo/tarball/<branch name>#"subdirectory=foo&egg=macrolib.foo"']

dependency_links=['http://path/to/repo/tarball/<branch name>#subdirectory=foo&egg=macrolib.foo']

dependency_links=['http://path/to/repo/archive/<branch name>.zip#"subdirectory=foo&egg=macrolib.foo"']

dependency_links=['http://path/to/repo/archive/<branch name>.zip#subdirectory=foo&egg=macrolib.foo']

OR add a prefix 'git+' to all the above urls.

My question is what is the correct url format for dependency_links in order to install macrolib.foo as a dependency, or is there any other ways to make it work?

Upvotes: 3

Views: 1239

Answers (1)

phd
phd

Reputation: 94482

This is the correct format (adding 'git+' and dependency version):

dependency_links=['git+http://path/to/repo.git@<branch name>#subdirectory=foo&egg=macrolib.foo-0.1.0']

and you need to ask pip to process it:

pip install --process-dependency-links git+http://path/to/repo.git@<branch name>#"subdirectory=bar&egg=macrolib.bar"

Upvotes: 2

Related Questions