Skip to content

Commit

Permalink
Switch to using Args
Browse files Browse the repository at this point in the history
  • Loading branch information
jvolkman committed Oct 15, 2022
1 parent 2011aa3 commit 7064332
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 173 deletions.
80 changes: 19 additions & 61 deletions pycross/private/lock_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,91 +14,49 @@ def _pycross_lock_file_impl(ctx):
else:
repo_prefix = ctx.attr.name.lower().replace("-", "_")

args = [
"--lock-model-file",
ctx.file.lock_model_file.path,
"--repo-prefix",
repo_prefix,
"--package-prefix",
ctx.attr.package_prefix,
"--build-prefix",
ctx.attr.build_prefix,
"--environment-prefix",
ctx.attr.environment_prefix,
"--output",
out.path,
]
args = ctx.actions.args()
args.add("--lock-model-file", ctx.file.lock_model_file)
args.add("--repo-prefix", repo_prefix)
args.add("--package-prefix", ctx.attr.package_prefix)
args.add("--build-prefix", ctx.attr.build_prefix)
args.add("--environment-prefix", ctx.attr.environment_prefix)
args.add("--output", out)

for t in ctx.attr.target_environments:
args.extend([
"--target-environment",
t[PycrossTargetEnvironmentInfo].file.path,
fully_qualified_label(t.label),
])
args.add_all("--target-environment", [t[PycrossTargetEnvironmentInfo].file.path, fully_qualified_label(t.label)])

for local_wheel in ctx.files.local_wheels:
if not local_wheel.owner:
fail("Could not determine owning lable for local wheel: %s" % local_wheel)
args.extend([
"--local-wheel",
local_wheel.basename,
fully_qualified_label(local_wheel.owner),
])
args.add_all("--local-wheel", [local_wheel.basename, fully_qualified_label(local_wheel.owner)])

for remote_wheel_url, sha256 in ctx.attr.remote_wheels.items():
args.extend([
"--remote-wheel",
remote_wheel_url,
sha256,
])
args.add_all("--remote-wheel", [remote_wheel_url, sha256])

if ctx.attr.package_prefix != None:
args.extend([
"--package-prefix",
ctx.attr.package_prefix,
])
args.add("--package-prefix", ctx.attr.package_prefix)

if ctx.attr.build_prefix != None:
args.extend([
"--build-prefix",
ctx.attr.build_prefix,
])
args.add("--build-prefix", ctx.attr.build_prefix)

if ctx.attr.environment_prefix != None:
args.extend([
"--environment-prefix",
ctx.attr.environment_prefix,
])
args.add("--environment-prefix", ctx.attr.environment_prefix)

if ctx.attr.default_alias_single_version:
args.append("--default-alias-single-version")
args.add("--default-alias-single-version")

for k, t in ctx.attr.build_target_overrides.items():
args.extend([
"--build-target-override",
k,
t,
])
args.add_all("--build-target-override", [k, t])

for k in ctx.attr.always_build_packages:
args.extend([
"--always-build-package",
k
])
args.add("--always-build-package", k)

for k, d in ctx.attr.package_build_dependencies.items():
for dep in d:
args.extend([
"--build-dependency",
k,
dep,
])
args.add_all("--build-dependency", [k, dep])

if ctx.attr.pypi_index:
args.extend([
"--pypi-index",
ctx.attr.pypi_index,
])
args.add("--pypi-index", ctx.attr.pypi_index)

ctx.actions.run(
inputs = (
Expand All @@ -107,7 +65,7 @@ def _pycross_lock_file_impl(ctx):
),
outputs = [out],
executable = ctx.executable._tool,
arguments = args,
arguments = [args],
)

return [
Expand Down
20 changes: 8 additions & 12 deletions pycross/private/pdm_lock_model.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
def _pycross_pdm_lock_model_impl(ctx):
out = ctx.actions.declare_file(ctx.attr.name + ".json")

args = [
"--project-file",
ctx.file.project_file.path,
"--lock-file",
ctx.file.lock_file.path,
"--output",
out.path,
]
args = ctx.actions.args()
args.add("--project-file", ctx.file.project_file)
args.add("--lock-file", ctx.file.lock_file)
args.add("--output", out)

if ctx.attr.default:
args.append("--default")
args.add("--default")

if ctx.attr.dev:
args.append("--dev")
args.add("--dev")

for group in ctx.attr.groups:
args.extend(["--group", group])
args.add("--group", group)

ctx.actions.run(
inputs = (
Expand All @@ -28,7 +24,7 @@ def _pycross_pdm_lock_model_impl(ctx):
),
outputs = [out],
executable = ctx.executable._tool,
arguments = args,
arguments = [args],
)

return [
Expand Down
14 changes: 5 additions & 9 deletions pycross/private/poetry_lock_model.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
def _pycross_poetry_lock_model_impl(ctx):
out = ctx.actions.declare_file(ctx.attr.name + ".json")

args = [
"--poetry-project-file",
ctx.file.poetry_project_file.path,
"--poetry-lock-file",
ctx.file.poetry_lock_file.path,
"--output",
out.path,
]
args = ctx.actions.args()
args.add("--poetry-project-file", ctx.file.poetry_project_file)
args.add("--poetry-lock-file", ctx.file.poetry_lock_file)
args.add("--output", out)

ctx.actions.run(
inputs = (
Expand All @@ -19,7 +15,7 @@ def _pycross_poetry_lock_model_impl(ctx):
),
outputs = [out],
executable = ctx.executable._tool,
arguments = args,
arguments = [args],
)

return [
Expand Down
62 changes: 20 additions & 42 deletions pycross/private/target_environment.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,28 @@ def fully_qualified_label(label):
def _target_python_impl(ctx):
f = ctx.actions.declare_file(ctx.attr.name + ".json")

args = [
"--name",
ctx.attr.name,
"--output",
f.path,
"--implementation",
ctx.attr.implementation,
"--version",
ctx.attr.version,
]
args = ctx.actions.args()
args.add("--name", ctx.attr.name)
args.add("--output", f)
args.add("--implementation", ctx.attr.implementation)
args.add("--version", ctx.attr.version)

for abi in ctx.attr.abis:
args.extend(["--abi", abi])
args.add("--abi", abi)

for platform in ctx.attr.platforms:
args.extend(["--platform", platform])
args.add("--platform", platform)

for constraint in ctx.attr.python_compatible_with:
args.extend([
"--python-compatible-with",
fully_qualified_label(constraint.label),
])
args.add("--python-compatible-with", fully_qualified_label(constraint.label))

for key, val in ctx.attr.envornment_markers.items():
args.extend([
"--environment-marker",
"%s=%s" % (key, val),
])
args.add("--environment-marker", "%s=%s" % (key, val))

ctx.actions.run(
outputs = [f],
executable = ctx.executable._tool,
arguments = args,
arguments = [args],
)

return [
Expand Down Expand Up @@ -104,39 +93,28 @@ pycross_target_environment = rule(
def _macos_target_python_impl(ctx):
f = ctx.actions.declare_file(ctx.attr.name + ".json")

args = [
"--name",
ctx.attr.name,
"--output",
f.path,
"--implementation",
ctx.attr.implementation,
"--version",
ctx.attr.version,
]
args = ctx.actions.args()
args.add("--name", ctx.attr.name)
args.add("--output", f)
args.add("--implementation", ctx.attr.implementation)
args.add("--version", ctx.attr.version)

for abi in ctx.attr.abis:
args.extend(["--abi", abi])
args.add("--abi", abi)

for platform in ctx.attr.platforms:
args.extend(["--platform", platform])
args.add("--platform", platform)

for constraint in ctx.attr.python_compatible_with:
args.extend([
"--python-compatible-with",
fully_qualified_label(constraint.label),
])
args.add("--python-compatible-with", fully_qualified_label(constraint.label))

for key, val in ctx.attr.envornment_markers.items():
args.extend([
"--environment-marker",
"%s=%s" % (key, val),
])
args.add("--environment-marker", "%s=%s" % (key, val))

ctx.actions.run(
outputs = [f],
executable = ctx.executable._tool,
arguments = args,
arguments = [args],
)

return [
Expand Down
Loading

0 comments on commit 7064332

Please sign in to comment.