如何使用Poetry将Python包发布到CodeArtifact?

尝试将 Poetry 包发布到 AWS CodeArtifact。它支持pipwhich 应该表明它也支持poetry,因为poetry可以上传到 PyPi 服务器。

我已经像这样配置了域:

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain XXXX --domain-owner XXXXXXXXXXXX --query authorizationToken --output text`
poetry config repositories.the_aws_repo https://aws:$CODEARTIFACT_AUTH_TOKEN@XXXX-XXXXXXXXXXXX.d.codeartifact.eu-central-1.amazonaws.com/pypi/XXXX/simple/
poetry config pypi-token.the_aws_repo $CODEARTIFACT_AUTH_TOKEN

但是我在尝试发布包时收到 404:

? poetry publish --repository the_aws_repo -vvv

No suitable keyring backend found
No suitable keyring backends were found
Using a plaintext file to store and retrieve credentials
Publishing xxx (0.1.5) to the_aws_repo
 - Uploading xxx-0.1.5-py3-none-any.whl 100%

  Stack trace:

  7  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py:131 in run
      129?             parsed_args = resolved_command.args
      130?
    ? 131?             status_code = command.handle(parsed_args, io)
      132?         except KeyboardInterrupt:
      133?             status_code = 1

  6  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:120 in handle
      118?     def handle(self, args, io):  # type: (Args, IO) -> int
      119?         try:
    ? 120?             status_code = self._do_handle(args, io)
      121?         except KeyboardInterrupt:
      122?             if io.is_debug():

  5  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:171 in _do_handle
      169?         handler_method = self._config.handler_method
      170?
    ? 171?         return getattr(handler, handler_method)(args, io, self)
      172?
      173?     def __repr__(self):  # type: () -> str

  4  ~/.poetry/lib/poetry/_vendor/py3.8/cleo/commands/command.py:92 in wrap_handle
       90?         self._command = command
       91?
    ?  92?         return self.handle()
       93?
       94?     def handle(self):  # type: () -> Optional[int]

  3  ~/.poetry/lib/poetry/console/commands/publish.py:77 in handle
      75?         )
      76?
    ? 77?         publisher.publish(
      78?             self.option("repository"),
      79?             self.option("username"),

  2  ~/.poetry/lib/poetry/publishing/publisher.py:93 in publish
      91?         )
      92?
    ? 93?         self._uploader.upload(
      94?             url,
      95?             cert=cert or get_cert(self._poetry.config, repository_name),

  1  ~/.poetry/lib/poetry/publishing/uploader.py:119 in upload
      117?
      118?         try:
    ? 119?             self._upload(session, url, dry_run)
      120?         finally:
      121?             session.close()

  UploadError

  HTTP Error 404: Not Found

  at ~/.poetry/lib/poetry/publishing/uploader.py:216 in _upload
      212?                     self._register(session, url)
      213?                 except HTTPError as e:
      214?                     raise UploadError(e)
      215?
    ? 216?             raise UploadError(e)
      217?
      218?     def _do_upload(
      219?         self, session, url, dry_run=False
      220?     ):  # type: (requests.Session, str, Optional[bool]) -> None

我的 AWS IAM 用户有权执行此操作,因为我在存储库中为其授予了相关权限。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::XXXXXXXXXXXX:user/ShayN"
            },
            "Action": [
                "codeartifact:AssociateExternalConnection",
                "codeartifact:CopyPackageVersions",
                "codeartifact:DeletePackageVersions",
                "codeartifact:DeleteRepository",
                "codeartifact:DeleteRepositoryPermissionsPolicy",
                "codeartifact:DescribePackageVersion",
                "codeartifact:DescribeRepository",
                "codeartifact:DisassociateExternalConnection",
                "codeartifact:DisposePackageVersions",
                "codeartifact:GetPackageVersionReadme",
                "codeartifact:GetRepositoryEndpoint",
                "codeartifact:ListPackageVersionAssets",
                "codeartifact:ListPackageVersionDependencies",
                "codeartifact:ListPackageVersions",
                "codeartifact:ListPackages",
                "codeartifact:PublishPackageVersion",
                "codeartifact:PutPackageMetadata",
                "codeartifact:PutRepositoryPermissionsPolicy",
                "codeartifact:ReadFromRepository",
                "codeartifact:UpdatePackageVersionsStatus",
                "codeartifact:UpdateRepository"
            ],
            "Resource": "*"
        }
    ]
}

我错过了什么?

回答

问题是/simple/在 repo url 的末尾。这部分应该只在从该存储库中提取时添加,而不是在发布到它时添加。如果您仔细查看有关如何使用 发布的 AWS CodeArtifact 文档twine,您会发现它也不存在。

这有效:

# This will give the repo url without the /simple/ part
# Example: https://<my-domain>-<domain-owner-id>.d.codeartifact.<region>.amazonaws.com/pypi/<my-repo>/
# Note the lack of the "aws:auth-token@" part
export CODEARTIFACT_REPOSITORY_URL=`aws codeartifact get-repository-endpoint --domain my-domain --domain-owner domain-owner-id --repository my-repo --format pypi --query repositoryEndpoint --output text`

# This will give the token to access the repo
export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain my-domain --domain-owner domain-owner-id --query authorizationToken --output text`

# This specifies the user who accesses the repo
export CODEARTIFACT_USER=aws

# Now use all of these when configuring the repo in poetry
poetry config repositories.<my-repo-name-for-poetry> $CODEARTIFACT_REPOSITORY_URL
poetry config http-basic.<my-repo-name-for-poetry> $CODEARTIFACT_USER $CODEARTIFACT_AUTH_TOKEN

请注意,身份验证令牌将在您的 AWS 登录会话结束时过期。因此,http-basic.<my-repo-name-for-poetry>每次到期时,您都必须使用新令牌进行设置。

仅供参考,我遇到了同样的问题,我花了几个小时才弄明白。但最终,更仔细地阅读文档应该对我有所帮助。


以上是如何使用Poetry将Python包发布到CodeArtifact?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>