From c297f876f405cf1f1da10709d8d6a83b1d45edc4 Mon Sep 17 00:00:00 2001 From: Tom Solberg Date: Sun, 18 Jun 2023 21:42:55 +0200 Subject: [PATCH] publish fixes (#50) --- pants-plugins/bitwarden/BUILD | 1 - pants-plugins/k8s/BUILD | 1 - pants-plugins/kustomize/BUILD | 1 - pants-plugins/mdbook/BUILD | 1 - pants-plugins/oci/BUILD | 1 - pants-plugins/secrets/BUILD | 1 - .../publish_secret_python.py | 20 +++++++++---------- 7 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pants-plugins/bitwarden/BUILD b/pants-plugins/bitwarden/BUILD index 9e46dd5..bde362f 100644 --- a/pants-plugins/bitwarden/BUILD +++ b/pants-plugins/bitwarden/BUILD @@ -15,6 +15,5 @@ python_distribution_with_secret( ), long_description_path="pants-plugins/bitwarden/README.md", wheel_config_settings={"--global-option": ["--python-tag", "py38.py39"]}, - repositories=["@pypi"], repo_secrets={"@pypi": "//examples/bitwarden:pypi_token"}, ) diff --git a/pants-plugins/k8s/BUILD b/pants-plugins/k8s/BUILD index 0e5023d..b7713be 100644 --- a/pants-plugins/k8s/BUILD +++ b/pants-plugins/k8s/BUILD @@ -15,6 +15,5 @@ python_distribution_with_secret( ), long_description_path="pants-plugins/k8s/README.md", wheel_config_settings={"--global-option": ["--python-tag", "py38.py39"]}, - repositories=["@pypi"], repo_secrets={"@pypi": "//examples/bitwarden:pypi_token"}, ) diff --git a/pants-plugins/kustomize/BUILD b/pants-plugins/kustomize/BUILD index f91d845..66313d8 100644 --- a/pants-plugins/kustomize/BUILD +++ b/pants-plugins/kustomize/BUILD @@ -15,6 +15,5 @@ python_distribution_with_secret( ), long_description_path="pants-plugins/kustomize/README.md", wheel_config_settings={"--global-option": ["--python-tag", "py38.py39"]}, - repositories=["@pypi"], repo_secrets={"@pypi": "//examples/bitwarden:pypi_token"}, ) diff --git a/pants-plugins/mdbook/BUILD b/pants-plugins/mdbook/BUILD index 3e36540..d8c7a84 100644 --- a/pants-plugins/mdbook/BUILD +++ b/pants-plugins/mdbook/BUILD @@ -15,6 +15,5 @@ python_distribution_with_secret( ), long_description_path="pants-plugins/mdbook/README.md", wheel_config_settings={"--global-option": ["--python-tag", "py38.py39"]}, - repositories=["@pypi"], repo_secrets={"@pypi": "//examples/bitwarden:pypi_token"}, ) diff --git a/pants-plugins/oci/BUILD b/pants-plugins/oci/BUILD index cd55277..b24dc07 100644 --- a/pants-plugins/oci/BUILD +++ b/pants-plugins/oci/BUILD @@ -13,7 +13,6 @@ python_distribution_with_secret( ), long_description_path="pants-plugins/oci/README.md", wheel_config_settings={"--global-option": ["--python-tag", "py38.py39"]}, - repositories=["@pypi"], repo_secrets={"@pypi": "//examples/bitwarden:pypi_token"}, ) diff --git a/pants-plugins/secrets/BUILD b/pants-plugins/secrets/BUILD index 59f2a63..c18e25b 100644 --- a/pants-plugins/secrets/BUILD +++ b/pants-plugins/secrets/BUILD @@ -15,6 +15,5 @@ python_distribution_with_secret( ), long_description_path="pants-plugins/secrets/README.md", wheel_config_settings={"--global-option": ["--python-tag", "py38.py39"]}, - repositories=["@pypi"], repo_secrets={"@pypi": "//examples/bitwarden:pypi_token"}, ) diff --git a/pants-plugins/secrets/pants_backend_secrets/publish_secret_python.py b/pants-plugins/secrets/pants_backend_secrets/publish_secret_python.py index 07765d5..c604c99 100644 --- a/pants-plugins/secrets/pants_backend_secrets/publish_secret_python.py +++ b/pants-plugins/secrets/pants_backend_secrets/publish_secret_python.py @@ -1,9 +1,8 @@ from dataclasses import dataclass from pants.backend.python.goals.publish import ( - PublishPythonPackageFieldSet, PublishPythonPackageRequest, - PythonRepositoriesField, + SkipTwineUploadField, twine_upload_args, ) from pants.backend.python.subsystems.twine import TwineSubsystem @@ -60,9 +59,10 @@ class PublishPythonWithSecretPackageRequest(PublishPythonPackageRequest): @dataclass(frozen=True) class PublishPythonWithSecretPackageFieldSet(PublishFieldSet): publish_request_type = PublishPythonWithSecretPackageRequest - required_fields = PublishPythonPackageFieldSet.required_fields + (PublishSecretsField,) + required_fields = (PublishSecretsField,) - secrets: PublishSecretsField + repositories: PublishSecretsField + skip_twine: SkipTwineUploadField def get_output_data(self) -> PublishOutputData: return PublishOutputData( @@ -88,7 +88,6 @@ class PythonDistributionWithSecret(Target): SDistConfigSettingsField, BuildBackendEnvVarsField, LongDescriptionPathField, - PythonRepositoriesField, PublishSecretsField, ) help = softwrap(f""" @@ -145,14 +144,15 @@ async def twine_upload_with_secret( pex_proc_requests = [] secret_requests = [] - for repo in request.field_set.repositories.value: - secret = request.field_set.secrets.value[repo] + repositories = [] + for repo, secret in request.field_set.repositories.value.items(): + repositories.append(repo) secret_address = await Get( Addresses, UnparsedAddressInputs( [secret], owning_address=request.field_set.address, - description_of_origin=f"the `{secret}` from the target {request.field_set.secrets}", + description_of_origin=f"the `{secret}` from the target {request.field_set.repositories}", ), ) wrapped_target = await Get( @@ -171,7 +171,7 @@ async def twine_upload_with_secret( fallible_secrets = await MultiGet(*secret_requests) secrets = [] - for repo, maybe_secret in zip(request.field_set.repositories.value, fallible_secrets): + for repo, maybe_secret in zip(repositories, fallible_secrets): if maybe_secret.exit_code != 0: raise FailedDecryptException( f"Failed decrypting secret for repo: {repo}", @@ -182,7 +182,7 @@ async def twine_upload_with_secret( assert maybe_secret.response is not None, "cannot be None if exit_code is 0" secrets.append(maybe_secret.response.value) - for repo, secret in zip(request.field_set.repositories.value, secrets): + for repo, secret in zip(repositories, secrets): pex_proc_requests.append( VenvPexProcess( twine_pex,