无法使用 twine 将 PIP 包上传到 Google Artifact 注册表,错误:KeyError:'license'

问题描述 投票:0回答:1

我正在构建一个 Python PIP 包以存储在 Google Artifact 注册表中。

pyproject.toml
如下:

[build-system]
requires = ["setuptools>=68.0.0,<69.0.0", "setuptools-scm>=8.0.1,<8.1.0"]
build-backend = "setuptools.build_meta"

[project]
name = "my-sdk"
version = "0.1.3"
license = {text = "Some Solution"}
readme = "README.md"
requires-python = ">=3.8,<3.11"
dependencies = [
    "google-cloud-storage>=2.6.0"
]
[project.optional-dependencies]
ci = [
    "flake8==6.0.0",
    "Flake8-pyproject==1.2.3",
    "pytest-cov==4.1.0",
    "pytest==7.2.2"
]

[tool.setuptools.packages.find]
include = ["*"]
namespaces = false

[tool.pytest]
norecursedirs = [".git", ".tox"," venv*"]
addopts = "-rsxX -q -p no:warnings"
python_files = ["*_test.py", "test_*.py"]
log_cli = true
log_cli_level = "INFO"

[tool.flake8]
max-line-length = 100
select = ["E", "W", "F", "C", "B"]
ignore = ["E203", "W503", "E731"]
per-file-ignores = ["__init__.py: F401", "test_*.py: D103"]

包的命令序列:

python -m pip install \
            keyring==24.3.0 \
            keyrings.google-artifactregistry-auth==1.1.2 \
            build==1.0.3 \
            twine==4.0.2
python -m build
python -m twine upload \
            --repository-url https://<hidden>.pkg.dev/my-project/my-artifacts \
            dist/*

只有最后一步失败,即

twine upload
,错误信息如下:

Traceback (most recent call last):
  File "/miniconda/envs/pip_env/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/miniconda/envs/pip_env/lib/python3.10/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/miniconda/envs/pip_env/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/miniconda/envs/pip_env/lib/python3.10/site-packages/twine/__init__.py", line 43, in <module>
    __license__ = metadata["license"]
  File "/miniconda/envs/pip_env/lib/python3.10/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'license'

我在 pyproject.toml 中尝试了不同类型的

license
,但每次都会遇到相同的错误。 还有其他人面临过这一挑战吗?

python-3.x google-artifact-registry twine
1个回答
0
投票

广泛查看

twine
问题后,我找不到任何相关答案。 然而,我确实在 pypi.org 中看到,5.1.0 版本由于类似的错误而被撤下:
KeyError
。 因此我决定升级到
5.1.1
,然后
twine upload
就成功了。

python -m pip install \
            keyring==24.3.0 \
            keyrings.google-artifactregistry-auth==1.1.2 \
            build==1.0.3 \
            twine==5.1.1
© www.soinside.com 2019 - 2024. All rights reserved.