Python setuptools: How can I list a private repository under install_requires?

前端 未结 8 1427
南旧
南旧 2020-12-04 15:07

I am creating a setup.py file for a project which depends on private GitHub repositories. The relevant parts of the file look like this:

from s         


        
相关标签:
8条回答
  • 2020-12-04 15:46

    I couldn't find any good documentation on this, but came across the solution mainly through trial & error. Further, installing from pip & setuptools have some subtle differences; but this way should work for both.

    GitHub don't (currently, as of August 2016) offer an easy way to get the zip / tarball of private repos. So you need to point setuptools to tell setuptools that you're pointing to a git repo:

    from setuptools import setup
    import os
    # get deploy key from https://help.github.com/articles/git-automation-with-oauth-tokens/
    github_token = os.environ['GITHUB_TOKEN']
    
    setup(
        # ...
        install_requires='package',
        dependency_links = [
        'git+https://{github_token}@github.com/user/{package}.git/@{version}#egg={package}-0'
            .format(github_token=github_token, package=package, version=master)
            ] 
    

    A couple of notes here:

    • For private repos, you need to authenticate with GitHub; the simplest way I found is to create an oauth token, drop that into your environment, and then include it with the URL
    • You need to include some version number (here is 0) at the end of the link, even if there's no package on PyPI. This has to be a actual number, not a word.
    • You need to preface with git+ to tell setuptools it's to clone the repo, rather than pointing at a zip / tarball
    • version can be a branch, a tag, or a commit hash
    • You need to supply --process-dependency-links if installing from pip
    0 讨论(0)
  • 2020-12-04 15:46

    Edit: This appears to only work with public github repositories, see comments.

    dependency_links=[
        'https://github.com/my_account/private_repo_1/tarball/master#egg=private_repo_1',
        'https://github.com/my_account/private_repo_2/tarball/master#egg=private_repo_2',
    ],
    

    Above syntax seems to work for me with setuptools 1.0. At the moment at least the syntax of adding "#egg=project_name-version" to VCS dependencies is documented in the link you gave to distribute documentation.

    0 讨论(0)
提交回复
热议问题