我有一个包(foo)在一个私人git回购。我想通过bar的setup.py安装foo供另一个包bar使用。我想要一个特定的版本-setup.pyforfoo中的版本控制与其git标记匹配(0.3.2,git标记为v0.3.2)
工具栏的setup.py如下所示:
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='bar',
install_requires=['foo@ git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=somedir']
)
我还尝试在末尾明确添加版本:
install_requires=['foo@ git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=somedir==0.3.2']
我目前在我的venv中安装了0.3.1版。
当我尝试通过pip install .
或pip install . -U
安装此setup.py时,版本未升级-甚至未签出repo:
Requirement already satisfied, skipping upgrade: foo@ git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src==0.3.2 from
git+ssh://****@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src==0.3.2 in
./venv/lib/python3.8/site-packages (from bar==0.0.0) (0.3.1)
但是,当我使用pip直接安装foo时,升级完成:
pip install git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src
Collecting git+ssh://****@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src
Cloning ssh://****@github.com/fergusmac/foo.git (to revision v0.3.2) to /tmp/pip-req-build-gxj2duq6
Running command git clone -q 'ssh://****@github.com/fergusmac/foo.git' /tmp/pip-req-build-gxj2duq6
Running command git checkout -q 40fa65eb75fc26541c90ee9e489ae6dd5538db1f
Running command git submodule update --init --recursive -q
...
Installing collected packages: foo
Attempting uninstall: foo
Found existing installation: foo0.3.1
Uninstalling foo-0.3.1:
Successfully uninstalled foo-0.3.1
Running setup.py install for foo... done
Successfully installed foo-0.3.2
我不明白为什么使用setup.py安装会产生不同的行为。我如何确保它检查回购协议并查找正确的版本
后续问题-我将如何指定“检查主分支的foo并安装高于当前安装版本的任何版本”
你问的是一个准确而有效的问题,但我不相信会有令人满意的答案。我不确定为什么您所做的工作不起作用,但是在pip和setuptools中使用直接URL依赖项是一个新的、相当复杂的特性,并且可能在setuptools方面存在缺陷/缺乏
我假设您想要做的是将包
foo
作为bar
的依赖项—实际上不需要使用PEP 508直接URL说明符格式。相反,您可以为pip
或setuptools
提供(相对)路径作为依赖项说明符,然后使用Git子模块填充这些路径。例如:这将安装添加子模块时签出的任何版本的foo。正如this answer所解释的,您可以更改子模块的签出版本,然后按如下方式安装它:
对于setuptools,您可以这样指定它:
Path(__file__).parent
是包含bar的setup.py
文件的目录。该位后面的路径(例如本例中的/foo/
)应该是foo的子模块相对于包含bar的setup.py
文件的目录的位置签出子模块中的
master
,然后通过pip install upgrade .
安装(假设.
是bar的项目目录)另见:https://softwareengineering.stackexchange.com/a/365583/271937
相关问题 更多 >
编程相关推荐