Python-用Azuredevops构建和释放工件

发布于 2025-01-30 03:35:06 字数 6384 浏览 4 评论 0原文

我正在尝试创建一个Azure Devops管道,以便在Azure Devops Antertains部分构建和释放Python软件包。

我已经开始创建一个名为“ UTILS”的提要,然后我创建了我的软件包,并且已经像这样结构化了:

.
src
|
    __init__.py
    class.py
test
|
    __init__.py
    test_class.py
.pypirc
azure-pipelines.yml
pyproject.toml
requirements.txt
setup.cfg

这是文件的内容:

.pypirc

[distutils]
Index-servers =
  prelios-utils

[utils]
Repository = https://pkgs.dev.azure.com/OMIT/_packaging/utils/pypi/upload/

pyproject。 toml

[build-system]
requires = [
    "setuptools>=42",
    "wheel"
]
build-backend = "setuptools.build_meta"

setup.cfg

[metadata]
name = my_utils
version = 0.1
author = Walter Tranchina
author_email = [email protected]
description = A package containing [...]
long_description = file: README.md
long_description_content_type = text/markdown
url = OMIT.com
project_urls =
classifiers =
    Programming Language :: Python :: 3
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent

[options]
package_dir =
    = src
packages = find:
python_requires = >=3.7
install_requires=

[options.packages.find]
where = src

azure-pipelines.yml

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'
strategy:
  matrix:
    Python38:
      python.version: '3.8'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    python -m pip install --upgrade pip
  displayName: 'Install dependencies'

- script: |
    pip install twine wheel
  displayName: 'Install buildtools'

- script: |
    pip install pytest pytest-azurepipelines
    pytest
  displayName: 'pytest'

- script: |
    python -m build
  displayName: 'Artifact creation'

- script: |
    twine upload -r utils --config-file ./.pypirc dist/*
  displayName: 'Artifact Upload'

我面临的问题是,管道停留在工件上传阶段数小时而无需完成。

请问有人可以帮我了解这是什么问题吗?

谢谢!

[更新] 我已经按照答案的建议更新了我的YML文件:

- task: TwineAuthenticate@1
  displayName: 'Twine Authenticate'
  inputs:
    artifactFeed: 'utils'

现在我有一个错误:

2022-05-19T09:20:50.6726960Z ##[section]Starting: Artifact Upload
2022-05-19T09:20:50.6735745Z ==============================================================================
2022-05-19T09:20:50.6736081Z Task         : Command line
2022-05-19T09:20:50.6736434Z Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-05-19T09:20:50.6736788Z Version      : 2.201.1
2022-05-19T09:20:50.6737008Z Author       : Microsoft Corporation
2022-05-19T09:20:50.6737375Z Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-05-19T09:20:50.6737859Z ==============================================================================
2022-05-19T09:20:50.8090380Z Generating script.
2022-05-19T09:20:50.8100662Z Script contents:
2022-05-19T09:20:50.8102321Z twine upload -r utils --config-file ./.pypirc dist/*
2022-05-19T09:20:50.8102824Z ========================== Starting Command Output ===========================
2022-05-19T09:20:50.8129029Z [command]/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/706c12ef-da25-44b0-b1fc-5ab83e7e0bf9.sh
2022-05-19T09:20:51.1178721Z Uploading distributions to 
2022-05-19T09:20:51.1180490Z https://pkgs.dev.azure.com/OMIT/_packaging/utils/pypi/upload/
2022-05-19T09:20:27.0860014Z Traceback (most recent call last):
2022-05-19T09:20:27.0861203Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/bin/twine", line 8, in <module>
2022-05-19T09:20:27.0862081Z     sys.exit(main())
2022-05-19T09:20:27.0863965Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/__main__.py", line 33, in main
2022-05-19T09:20:27.0865080Z     error = cli.dispatch(sys.argv[1:])
2022-05-19T09:20:27.0866638Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/cli.py", line 124, in dispatch
2022-05-19T09:20:27.0867670Z     return main(args.args)
2022-05-19T09:20:27.0869183Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/commands/upload.py", line 198, in main
2022-05-19T09:20:27.0870362Z     return upload(upload_settings, parsed_args.dists)
2022-05-19T09:20:27.0871990Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/commands/upload.py", line 127, in upload
2022-05-19T09:20:27.0873239Z     repository = upload_settings.create_repository()
2022-05-19T09:20:27.0875392Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/settings.py", line 329, in create_repository
2022-05-19T09:20:27.0876447Z     self.username,
2022-05-19T09:20:27.0877911Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/settings.py", line 131, in username
2022-05-19T09:20:27.0879043Z     return cast(Optional[str], self.auth.username)
2022-05-19T09:20:27.0880583Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/auth.py", line 34, in username
2022-05-19T09:20:27.0881640Z     return utils.get_userpass_value(
2022-05-19T09:20:27.0883208Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/utils.py", line 248, in get_userpass_value
2022-05-19T09:20:27.0884302Z     value = prompt_strategy()
2022-05-19T09:20:27.0886234Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/auth.py", line 85, in username_from_keyring_or_prompt
2022-05-19T09:20:27.0887440Z     return self.prompt("username", input)
2022-05-19T09:20:27.0888964Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/auth.py", line 96, in prompt
2022-05-19T09:20:27.0890017Z     return how(f"Enter your {what}: ")
2022-05-19T09:20:27.0890786Z EOFError: EOF when reading a line
2022-05-19T09:20:27.1372189Z ##[error]Bash exited with code 'null'.
2022-05-19T09:20:27.1745024Z ##[error]The operation was canceled.
2022-05-19T09:20:27.1749049Z ##[section]Finishing: Artifact Upload

好像麻烦正在等待某些东西...:/

I'm trying to create an Azure DevOps Pipeline in order to build and release a Python package under the Azure DevOps Artifacts section.

I've started creating a feed called "utils", then I've created my package and I've structured it like that:

.
src
|
    __init__.py
    class.py
test
|
    __init__.py
    test_class.py
.pypirc
azure-pipelines.yml
pyproject.toml
requirements.txt
setup.cfg

And this is the content of files:

.pypirc

[distutils]
Index-servers =
  prelios-utils

[utils]
Repository = https://pkgs.dev.azure.com/OMIT/_packaging/utils/pypi/upload/

pyproject.toml

[build-system]
requires = [
    "setuptools>=42",
    "wheel"
]
build-backend = "setuptools.build_meta"

setup.cfg

[metadata]
name = my_utils
version = 0.1
author = Walter Tranchina
author_email = [email protected]
description = A package containing [...]
long_description = file: README.md
long_description_content_type = text/markdown
url = OMIT.com
project_urls =
classifiers =
    Programming Language :: Python :: 3
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent

[options]
package_dir =
    = src
packages = find:
python_requires = >=3.7
install_requires=

[options.packages.find]
where = src

azure-pipelines.yml

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'
strategy:
  matrix:
    Python38:
      python.version: '3.8'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    python -m pip install --upgrade pip
  displayName: 'Install dependencies'

- script: |
    pip install twine wheel
  displayName: 'Install buildtools'

- script: |
    pip install pytest pytest-azurepipelines
    pytest
  displayName: 'pytest'

- script: |
    python -m build
  displayName: 'Artifact creation'

- script: |
    twine upload -r utils --config-file ./.pypirc dist/*
  displayName: 'Artifact Upload'

The problem I'm facing is that the pipeline stucks in the Artifact Upload stage for hours without completing.

Can please someone help me understand what it's wrong?

Thanks!

[UPDATE]
I've updated my yml file as suggested in the answers:

- task: TwineAuthenticate@1
  displayName: 'Twine Authenticate'
  inputs:
    artifactFeed: 'utils'

And now I have this error:

2022-05-19T09:20:50.6726960Z ##[section]Starting: Artifact Upload
2022-05-19T09:20:50.6735745Z ==============================================================================
2022-05-19T09:20:50.6736081Z Task         : Command line
2022-05-19T09:20:50.6736434Z Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-05-19T09:20:50.6736788Z Version      : 2.201.1
2022-05-19T09:20:50.6737008Z Author       : Microsoft Corporation
2022-05-19T09:20:50.6737375Z Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-05-19T09:20:50.6737859Z ==============================================================================
2022-05-19T09:20:50.8090380Z Generating script.
2022-05-19T09:20:50.8100662Z Script contents:
2022-05-19T09:20:50.8102321Z twine upload -r utils --config-file ./.pypirc dist/*
2022-05-19T09:20:50.8102824Z ========================== Starting Command Output ===========================
2022-05-19T09:20:50.8129029Z [command]/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/706c12ef-da25-44b0-b1fc-5ab83e7e0bf9.sh
2022-05-19T09:20:51.1178721Z Uploading distributions to 
2022-05-19T09:20:51.1180490Z https://pkgs.dev.azure.com/OMIT/_packaging/utils/pypi/upload/
2022-05-19T09:20:27.0860014Z Traceback (most recent call last):
2022-05-19T09:20:27.0861203Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/bin/twine", line 8, in <module>
2022-05-19T09:20:27.0862081Z     sys.exit(main())
2022-05-19T09:20:27.0863965Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/__main__.py", line 33, in main
2022-05-19T09:20:27.0865080Z     error = cli.dispatch(sys.argv[1:])
2022-05-19T09:20:27.0866638Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/cli.py", line 124, in dispatch
2022-05-19T09:20:27.0867670Z     return main(args.args)
2022-05-19T09:20:27.0869183Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/commands/upload.py", line 198, in main
2022-05-19T09:20:27.0870362Z     return upload(upload_settings, parsed_args.dists)
2022-05-19T09:20:27.0871990Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/commands/upload.py", line 127, in upload
2022-05-19T09:20:27.0873239Z     repository = upload_settings.create_repository()
2022-05-19T09:20:27.0875392Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/settings.py", line 329, in create_repository
2022-05-19T09:20:27.0876447Z     self.username,
2022-05-19T09:20:27.0877911Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/settings.py", line 131, in username
2022-05-19T09:20:27.0879043Z     return cast(Optional[str], self.auth.username)
2022-05-19T09:20:27.0880583Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/auth.py", line 34, in username
2022-05-19T09:20:27.0881640Z     return utils.get_userpass_value(
2022-05-19T09:20:27.0883208Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/utils.py", line 248, in get_userpass_value
2022-05-19T09:20:27.0884302Z     value = prompt_strategy()
2022-05-19T09:20:27.0886234Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/auth.py", line 85, in username_from_keyring_or_prompt
2022-05-19T09:20:27.0887440Z     return self.prompt("username", input)
2022-05-19T09:20:27.0888964Z   File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/twine/auth.py", line 96, in prompt
2022-05-19T09:20:27.0890017Z     return how(f"Enter your {what}: ")
2022-05-19T09:20:27.0890786Z EOFError: EOF when reading a line
2022-05-19T09:20:27.1372189Z ##[error]Bash exited with code 'null'.
2022-05-19T09:20:27.1745024Z ##[error]The operation was canceled.
2022-05-19T09:20:27.1749049Z ##[section]Finishing: Artifact Upload

Seems like twine is waiting for something... :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2025-02-06 03:35:06

我想这是因为您缺少 python twine上传身份验证任务

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: 'MyTestFeed'

如果您使用的是项目级供稿,则artifactfeed的值应为{project name}/{feed name}

如果您使用的是组织级供稿,则artifactfeed的值应为{feed name}

一种更简单的方法是单击任务下的灰色“设置”按钮,然后从下拉列表中选择您的提要。

I guess this is because you are missing a Python Twine Upload Authenticate task.

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: 'MyTestFeed'

If you are using a project level feed, the value of artifactFeed should be {project name}/{feed name}.

If you are using an organization level feed, the value of artifactFeed should be {feed name}.

A simpler way is to click the gray "setting" button under the task and select your feed from the drop-down list.

山有枢 2025-02-06 03:35:06

我找到了多次暂定的解决方案...

首先,我在Azure Devops与Python建立了服务连接,其中包含先前生成的API密钥。

然后,我已经编辑了YAML文件:

- task: TwineAuthenticate@1
  displayName: 'Twine Authenticate'
  inputs:
    pythonUploadServiceConnection: 'PythonUpload'

- script: |
    python -m twine upload --skip-existing --verbose -r utils --config-file  $(PYPIRC_PATH) dist/*
  displayName: 'Artifact Upload'

他们密钥使用了由上一个任务自动设置的变量$(PYPIRC_PATH)。该过程忽略了.pypirc文件,因此可以将其删除!

希望它会有所帮助!

I've found the solution after many tentatives...

First I've created a Service Connection in Azure DevOps to Python, containing an API key previously generated.

Then I've edited the yaml file:

- task: TwineAuthenticate@1
  displayName: 'Twine Authenticate'
  inputs:
    pythonUploadServiceConnection: 'PythonUpload'

- script: |
    python -m twine upload --skip-existing --verbose -r utils --config-file  $(PYPIRC_PATH) dist/*
  displayName: 'Artifact Upload'

They key was using the variable $(PYPIRC_PATH) that is automatically set by the previous task. The .pypirc file is ignored by the process, so it can be deleted!

Hope it will help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文