在 setup.py 中指定私有 git 存储库的版本 [英] Specify version for private git repos in setup.py
问题描述
如何在我的 setup.py 文件中为私有存储库指定一个版本,以便仅使用该版本?
How can I specify a version for private repos in my setup.py file so that only this version is used?
from setuptools import setup, find_packages
setup(
name="my_module"
version="1.0.4"
install_requires=[
"requests==2.20.0",
"test @ git+ssh://git@xxxx/xxxxx/test.git",
],
// etc.
)
我的测试 git 项目是否必须具有任何属性才能读取版本?目前我只使用 setup.py 中的 version 字段
Does my test git project have to have any properties so that I can read out the version? At the moment I only use the version field in setup.py
from setuptools import find_packages, setup
setup(
name="test",
version="0.5.1",
//etc.
)
推荐答案
不完全确定,但如果我在 install_requires
中没有弄错的话,您可能会遇到以下情况:
Not entirely sure, but if I am not mistaken in install_requires
you could have something like the following:
MyProject@git://git.example.com/MyProject.git@v1.0
当项目必须从 git 存储库(或其他代码版本控制系统)安装时,您无法像在索引上托管项目时那样真正指向版本号(例如 PyPI),但接下来最好的事情是您可以指向特定的 git 标签(或 branch,或任何其他类型的类似的参考,但 tag 可能是此用例的最佳选择).
When the project has to be installed from a git repository (or other code versioning systems) you can't really point at a version number like you can when the project is hosted on an index (such as PyPI), but the next best thing is that you can point at a specific git tag (or a branch, or any other kind of similar reference, but tag is probably the best choice for this use case).
另外,我可能是错的,但纯 setuptools 可能不支持这种表示法.这意味着您很可能无法使用 python setup.py develop
或 python setup.py install
,但应该使用 python -m pip install -e .
或 python -m pip install .
代替.
Also, I might be wrong, but this notation might not be supported by pure setuptools. This means you most likely won't be able to use python setup.py develop
or python setup.py install
, but should use python -m pip install -e .
or python -m pip install .
instead.
参考文献:
- https://pip.pypa.io/en/stable/参考/pip_install/#examples
- https://www.python.org/dev/peps/pep-0508/
- https://www.python.org/dev/peps/pep-0440/#direct-references
- https://github.com/pypa/setuptools/issues/1983#issuecomment-584130062
- https://stackoverflow.com/a/60372954/11138259
这篇关于在 setup.py 中指定私有 git 存储库的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!