How to write setup.py to include a git repo as a dependency

前端 未结 6 1941
感情败类
感情败类 2020-12-02 10:16

I am trying to write setup.py for my package. My package needs to specify a dependency on another git repo.

This is what I have so far:



        
6条回答
  •  遥遥无期
    2020-12-02 11:03

    Actually if you like to make your packages installable recursivelly (YourCurrentPackage includes your SomePrivateLib), e.g. when you want to include YourCurrentPackage into another one (like OuterPackage -> YourCurrentPackage -> SomePrivateLib) you'll need both:

    install_requires=[
        ...,
        "SomePrivateLib @ git+ssh://github.abc.com/abc/SomePrivateLib.git@0.1.0#egg=SomePrivateLib"
    ],
    dependency_links = [
        "git+ssh://github.abc.com/abc/SomePrivateLib.git@0.1.0#egg=SomePrivateLib"
    ]
    

    And make sure you have a tag created with your version number.

    Also if your git project is private and you like to install it inside the container e.g. Docker or GitLab runner, you will need authorized access to your repo. Please consider to use git+https with access tokens (like on GitLab: https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html):

    import os
    from setuptools import setup
    
    TOKEN_VALUE = os.getenv('EXPORTED_VAR_WITH_TOKEN')
    
    setup(
        ....
    
        install_requires=[
                ...,
                f"SomePrivateLib @ git+https://gitlab-ci-token:{TOKEN_VALUE}@gitlab.server.com/abc/SomePrivateLib.git@0.1.0#egg=SomePrivateLib"
        ],
        dependency_links = [
                f"git+https://gitlab-ci-token:{TOKEN_VALUE}@gitlab.server.com/abc/SomePrivateLib.git@0.1.0#egg=SomePrivateLib"
        ]
    )
    

提交回复
热议问题