我是使用 Poetry 和 Azure 的新手,所以请提前原谅我的任何语法错误和缺乏术语
我构建了一个名为“npipack”的 python 包,存储在 Azure DevOps 中:https://dev.azure.com/NPIDemandPlanning/npipack
现在,我创建了一个本地(我的意思是,在我的笔记本电脑本地)基于 python 的项目,其中依赖项和 venv 由 Poetry 管理。我也想在项目中添加“npipack”包。
这是我遵循的步骤:
echo $AZURE_DEVOPS_PAT
返回正确的 PATpyproject.toml
文件,并添加了以下代码[[tool.poetry.source]]
name = "azure"
url = "https://${AZURE_DEVOPS_PAT}@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple/"
default = false
poetry config repositories.azure https://<MY_PAT>@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple
poetry config http-basic.azure <MY_USERNAME> <MY_PAT>
artifacts-keyring
安装了
poetry self add artifacts-keyring
poetry add npipack --source azure
。这是我收到授权错误(base) (update sales & forecast report-py3.11) bash-3.2$ poetry add npipack --source azure
Source (azure): Authorization error accessing https://${AZURE_DEVOPS_PAT}@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple/npipack/
这里还有其他有用的信息:
你有没有经历过类似的事情?请帮我解决授权错误吗?
我设法使用 Poetry 将 Python 包从我的 Azure Artifacts feed 之一添加到我的 Python 项目中。
这是我的样本供您参考。您可以尝试使用
https://pkgs.dev.azure.com/<MyADOOrgName>/_packaging/npi-pack-feed/pypi/simple/
而不是 https://<MY_PAT>@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple
的源 URL。
# Initialize Poetry with existing python project
poetry init
# Add Azure Artifacts as Poetry source
poetry source add --priority=explicit azure https://pkgs.dev.azure.com/<MyADOOrgName>/_packaging/npi-pack-feed/pypi/simple/
# Add Poetry config
poetry config repositories.azure https://pkgs.dev.azure.com/<MyADOOrgName>/_packaging/npi-pack-feed/pypi/simple/
poetry config http-basic.azure <MyEmailAccount> <MyPAT>
# Add package from source
poetry add npipack --source azure
pyproject.toml
[tool.poetry]
name = "python-hello-world"
version = "1.0.0"
description = "Test Python hellow-world package with poetry"
authors = ["Alvin Zhao <[email protected]>"]
license = "MIT"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9.1"
[[tool.poetry.source]]
name = "azure"
url = "https://pkgs.dev.azure.com/xxxMyADOOrgNamexxx/_packaging/npi-pack-feed/pypi/simple/"
priority = "explicit"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"