Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pip/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def _deploy_pip_impl(ctx):
"{snapshot}": ctx.attr.snapshot,
"{release}": ctx.attr.release,
"{distribution_tag}": ctx.attr.distribution_tag,
"{suffix}": ctx.attr.suffix,
"{suffix}": ctx.attr.suffix,
"{publish_args}": str(ctx.attr.publish_args),
}
)

Expand Down Expand Up @@ -327,6 +328,10 @@ _deploy_pip = rule(
default = "",
doc = "Repository name in the .pypirc profile to deploy to"
),
"publish_args": attr.string_list(
default = [],
doc = """Arguments passed to twine, e.g. ["--non-interactive", "--skip-existing"]"""
),
"distribution_tag": attr.string(
mandatory = True,
doc = "Specify tag for the package name. Format: {python tag}-{abi tag}-{platform tag} (PEP 425)",
Expand Down Expand Up @@ -380,7 +385,8 @@ _deploy_pip = rule(
"""
)

def deploy_pip(name, target, snapshot, release, suffix = "", distribution_tag = "py3-none-any"):
def deploy_pip(name, target, snapshot, release, suffix = "", distribution_tag = "py3-none-any", publish_args = []):

deploy_script_target_name = name + "__deploy"
deploy_script_name = deploy_script_target_name + "-deploy.py"
_deploy_pip(
Expand All @@ -391,6 +397,7 @@ def deploy_pip(name, target, snapshot, release, suffix = "", distribution_tag =
release = release,
suffix = suffix,
distribution_tag = distribution_tag,
publish_args = publish_args
)

native.py_binary(
Expand Down
6 changes: 4 additions & 2 deletions pip/templates/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
SNAPSHOT_KEY: "{snapshot}",
RELEASE_KEY: "{release}"
}
publish_args = {publish_args}


parser = argparse.ArgumentParser()
parser.add_argument('repo_type')
Expand All @@ -52,14 +54,14 @@ def upload_command(repo_type_key, packages):
raise Exception(f"Selected repository must be one of: {list(repositories.keys())}")

if repo_type_key == PYPIRC_KEY:
return packages + ['--repository', repositories[repo_type_key]]
return packages + ['--repository', repositories[repo_type_key]] + publish_args
elif repo_type_key == SNAPSHOT_KEY or repo_type_key == RELEASE_KEY:
pip_username, pip_password = (os.getenv(ENV_DEPLOY_PIP_USERNAME), os.getenv(ENV_DEPLOY_PIP_PASSWORD))
if not pip_username:
raise Exception(f"username should be passed via the {ENV_DEPLOY_PIP_USERNAME} environment variable")
if not pip_password:
raise Exception(f"password should be passed via the {ENV_DEPLOY_PIP_PASSWORD} environment variable")
return packages + ['-u', pip_username, '-p', pip_password, '--repository-url', repositories[repo_type_key]]
return packages + ['-u', pip_username, '-p', pip_password, '--repository-url', repositories[repo_type_key]] + publish_args
else:
raise Exception(f"Unrecognised repository selector: {repo_type_key}")

Expand Down