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

前端 未结 6 1966
感情败类
感情败类 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

    A more general answer, to get the information from the requeriments.txt file I do:

    from setuptools import setup, find_packages
    from os import path
    
    loc = path.abspath(path.dirname(__file__))
    
    with open(loc + '/requirements.txt') as f:
        requirements = f.read().splitlines()
    
    required = []
    dependency_links = []
    # do not add to required lines pointing to git repositories
    EGG_MARK = '#egg='
    for line in requirements:
        if line.startswith('-e git:') or line.startswith('-e git+') or \
                line.startswith('git:') or line.startswith('git+'):
            if EGG_MARK in line:
                package_name = line[line.find(EGG_MARK) + len(EGG_MARK):]
                required.append(package_name)
                dependency_links.append(line)
            else:
                print('Dependency to a git repository should have the format:')
                print('git+ssh://git@github.com/xxxxx/xxxxxx#egg=package_name')
        else:
            required.append(line)
    
    setup(
        name='myproject',  # Required
        version='0.0.1',  # Required
        description='Description here....',  # Required
        packages=find_packages(),  # Required
        install_requires=required,
        dependency_links=dependency_links,
    ) 
    

提交回复
热议问题