我正在尝试为我的包编写setup.py。我的包需要指定对另一个git仓库的依赖。
这是我到目前为止:
from setuptools import setup, find_packages
setup(
name='abc',
packages=find_packages(),
url='https://github.abc.com/abc/myabc',
description='This is a description for abc',
long_description=open('README.md').read(),
install_requires=[
"requests==2.7.0",
"SomePrivateLib>=0.1.0",
],
dependency_links = [
"git+git://github.abc.com/abc/SomePrivateLib.git#egg=SomePrivateLib",
],
include_package_data=True,
)
当我跑:
pip install -e https://github.abc.com/abc/myabc.git#egg=analyse
我明白了
找不到满足要求的版本SomePrivateLib> = 0.1.0(来自analyze)(来自版本:)未找到SomePrivateLib的匹配分布> = 0.1.0(来自analyze)
我究竟做错了什么 ?
你可以找到正确的方法来做here。
dependency_links=['http://github.com/user/repo/tarball/master#egg=package-1.0']
关键是不要提供git存储库的链接,而是指向tarball的链接。如果你附加如上所示的/tarball/master
,Github会为你创建一个主分支的tarball。
在上面的评论和pip issue 3939中挖掘了由@muon链接的PEP-508 specification之后,我发现成功获得我的私人仓库依赖关系,使用setup.py
中的规范模式通过install_requires
安装(不再是dependency_links
):
install_requires = [
'some-pkg @ git+ssh://[email protected]/someorgname/[email protected]#egg=some-pkg',
]
@v1.1
表示在github上创建的发布标记,可以用分支,提交或不同类型的标记替换。
不幸的是,另一个答案不适用于私有存储库,这是最常见的用例之一。我最终确实使用了一个setup.py
文件,看起来像这样:
from setuptools import setup, find_packages
setup(
name = 'MyProject',
version = '0.1.0',
url = '',
description = '',
packages = find_packages(),
install_requires = [
# Github Private Repository - needs entry in `dependency_links`
'ExampleRepo'
],
dependency_links=[
# Make sure to include the `#egg` portion so the `install_requires` recognizes the package
'git+ssh://[email protected]/example_organization/ExampleRepo.git#egg=ExampleRepo-0.1'
]
)
更常见的答案是,我从requirements.txt文件中获取信息:
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://[email protected]/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,
)