使用testpypi

TestPyPI is a separate instance of the Python Package Index (PyPI) that allows you to try out the distribution tools and process without worrying about affecting the real index. TestPyPI is hosted at test.pypi.org

注册您的帐户

因为testpypi与活动的pypi有一个单独的数据库,所以您需要一个单独的用户帐户,专门用于testpypi。转到https://test.pypi.org/account/register/注册您的帐户。

注解

testpypi的数据库可能会被定期修剪,因此删除用户帐户并不少见。

将testpypi用于绳线

您可以使用 twine 通过 --repository-url 旗帜

$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*

这个 legacy 在上面的URL中,引用了pypi的遗留API,该API可能随着仓库项目的进展而更改。

通过导航到URL,可以查看包是否已成功上载 https://test.pypi.org/project/<sampleproject> 在哪里? sampleproject 是您上载的项目的名称。您的项目可能需要一两分钟才能出现在网站上。

使用testpypi和pip

通过指定 --index-url 旗帜

$ pip install --index-url https://test.pypi.org/simple/ your-package

如果您希望允许pip从pypi中提取其他包,可以指定 --extra-index-url 指向Pypi。当正在测试的包具有依赖项时,这很有用:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple your-package

在pypirc中设置testpypi

如果要避免输入testpypi URL和用户名,可以在 $HOME/.pypirc .

创建或修改 $HOME/.pypirc 包括以下内容:

[distutils]
index-servers=
    pypi
    testpypi

[testpypi]
repository: https://test.pypi.org/legacy/
username: your testpypi username

警告

不要在pypirc文件中存储密码。以纯文本格式存储密码从来都不是一个好主意。

你就可以知道 twine 通过指定 --repository 旗帜:

$ twine upload --repository testpypi dist/*