~/.pypirc 中 distutils 的多服务器配置中的默认服务器
我希望在我的 ~/.pypirc
文件中拥有多个 PyPI 服务器,以便我可以根据项目轻松发布到不同的服务器。
我的用例是这样的,我有一些内部项目想要发布到内部 PyPI 服务器 (https://pypi.internal
),并且我有一些想要发布的公共项目到公共 PyPI。
这是我目前的尝试,但它不起作用。我想默认为 internal
,并且如果我想发布,则需要添加 -r pypi
(到 setup.py
命令)到公共服务器。
[distutils]
index-servers =
internal
pypi
[internal]
repository: https://pypi.internal
username: brad
[pypi]
username: brad
我哪里错了?
I want to have multiple PyPI servers in my ~/.pypirc
file so I can easily publish to different servers, depending on the project.
My use-case is this, I have some internal projects that I want to publish to an internal PyPI server (https://pypi.internal
), and I have some public projects that I want to publish to the public PyPI.
This is my current attempt, but it doesn't work. I want to default to internal
, and be required to add the -r pypi
(to the setup.py
command) if I want to publish to the public server.
[distutils]
index-servers =
internal
pypi
[internal]
repository: https://pypi.internal
username: brad
[pypi]
username: brad
Where am I going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
奇怪的是,没有内置支持设置默认值,但这里有两个选项可以帮助您解决这个问题。
选项 1: 最简单的解决方案可能是保持 ~/.pypirc 脚本不变,并为内部和公共上传创建 shell 别名。这可以让您更好地控制工作流程的自定义内容。
给定这个.pypirc文件:
创建一些shell别名(将这些定义放在shell的rc文件中,例如~/.bashrc):
用法:
选项2: 黑客:您可以通过修补默认值来解决默认值
setup.py 脚本顶部的存储库名称。
输出:
背景:如果您在.pypirc中定义[distutils]键,则上传命令默认为pypi url当省略 -r [repo] 参数时。相关代码位于 distutils.config.PyPIRCCommand 中:
.pypirc 的旧格式需要一个 [server-login] 部分,这与不太灵活,因为它只定义了一个目标存储库。这不是一个可行的选项,因为下面的 [pypi] 部分将不可用:
现在默认情况下 distutils 将使用此目标:
但您无法访问任何其他存储库:它默认为[服务器登录]属性:
It's strange that there isn't built-in support for setting a default, but here are two options which may help you work around it.
Option 1: Probably the simplest solution would be to leave your ~/.pypirc script intact and create shell aliases for your internal and public uploads. This may give you more control over customizing things for your workflow.
Given this .pypirc file:
Create some shell aliases (place these definitions in your shell's rcfile, e.g. ~/.bashrc):
Usage:
Option 2: A hack: you can work around the default by patching the default
repository name at the top of your setup.py scripts.
Output:
Background: If you define the [distutils] key in .pypirc, the upload command defaults to the pypi url when the -r [repo] argument is omitted. The relevant code is in distutils.config.PyPIRCCommand:
The old format of .pypirc expected a [server-login] section, which was far less flexible since it only defines a single target repository. This isn't a workable option since the [pypi] section below will be unusable:
Now by default distutils will use this target:
But you can't access the any other repos: it silently defaults to the [server-login] properties:
当您想要从内部安装 PyPI 包存储库时,也会遇到类似的问题。在这种情况下,使用
pip install -e .
而不是python setup.pydevelop
可以完全回避这个问题。请参阅我可以使用 `pip` 而不是 `easy_install` 来解析 `python setup.py install` 依赖项吗?A similar problem is when you want to have an internal PyPI package repository to install from. In this scenario using
pip install -e .
rather thanpython setup.py develop
completely side-steps this problem. See Can I use `pip` instead of `easy_install` for `python setup.py install` dependency resolution?