Skip to content

Commit

Permalink
copy paste pdm related files
Browse files Browse the repository at this point in the history
  • Loading branch information
ewianda committed Jul 3, 2024
1 parent a070389 commit dc2dbbd
Show file tree
Hide file tree
Showing 9 changed files with 1,199 additions and 1,020 deletions.
726 changes: 329 additions & 397 deletions e2e/bzlmod/uv.lock

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions pycross/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,16 @@ bzl_library(
],
)

bzl_library(
name = "lock_model",
srcs = ["lock_model.bzl"],
deps = [":internal_repo"],
)

bzl_library(
name = "pdm_lock_model",
srcs = ["pdm_lock_model.bzl"],
deps = [":lock_model"],
deps = [":internal_repo"],
)

bzl_library(
name = "uv_lock_model",
srcs = ["uv_lock_model.bzl"],
deps = [":lock_model"],
deps = [":internal_repo"],
)

bzl_library(
Expand Down
103 changes: 0 additions & 103 deletions pycross/private/lock_model.bzl

This file was deleted.

105 changes: 85 additions & 20 deletions pycross/private/pdm_lock_model.bzl
Original file line number Diff line number Diff line change
@@ -1,22 +1,88 @@
"""Implementation of the pycross_pdm_lock_model rule."""

load(":internal_repo.bzl", "exec_internal_tool")
load(":lock_attrs.bzl", "PDM_IMPORT_ATTRS")
load(":lock_model.bzl", "lock_model")

TRANSLATOR_TOOL = Label("//pycross/private/tools:pdm_translator.py")

def _handle_args(attrs, project_file, lock_file, output):
args = []
args.extend(["--project-file", project_file])
args.extend(["--lock-file", lock_file])
args.extend(["--output", output])

if attrs.default:
args.append("--default")

for group in attrs.optional_groups:
args.extend(["--optional-group", group])

if attrs.all_optional_groups:
args.append("--all-optional-groups")

for group in attrs.development_groups:
args.extend(["--development-group", group])

if attrs.all_development_groups:
args.append("--all-development-groups")

if attrs.require_static_urls:
args.append("--require-static-urls")

return args

def _pycross_pdm_lock_model_impl(ctx):
out = ctx.actions.declare_file(ctx.attr.name + ".json")

args = ctx.actions.args().use_param_file("--flagfile=%s")
args.add_all(
_handle_args(
ctx.attr,
ctx.file.project_file.path,
ctx.file.lock_file.path,
out.path,
),
)

ctx.actions.run(
inputs = (
ctx.files.project_file +
ctx.files.lock_file
),
outputs = [out],
executable = ctx.executable._tool,
arguments = [args],
)

return [
DefaultInfo(
files = depset([out]),
),
]

pycross_pdm_lock_model = rule(
implementation = _pycross_pdm_lock_model_impl,
attrs = {
"_tool": attr.label(
default = Label("//pycross/private/tools:pdm_translator"),
cfg = "exec",
executable = True,
),
} | PDM_IMPORT_ATTRS,
)

def lock_repo_model_pdm(*, project_file, lock_file, default = True, optional_groups = [], all_optional_groups = False, development_groups = [], all_development_groups = False, require_static_urls = True):
return lock_model.lock_repo_model(
return json.encode(dict(
model_type = "pdm",
project_file = project_file,
lock_file = lock_file,
project_file = str(project_file),
lock_file = str(lock_file),
default = default,
optional_groups = optional_groups,
all_optional_groups = all_optional_groups,
development_groups = development_groups,
all_development_groups = all_development_groups,
require_static_urls = require_static_urls,
)
))

def repo_create_pdm_model(rctx, params, output):
"""Run the pdm lock translator.
Expand All @@ -26,20 +92,19 @@ def repo_create_pdm_model(rctx, params, output):
params: a struct or dict containing the same attrs as the pycross_pdm_lock_model rule.
output: the output file.
"""
lock_model.repo_create_model(
rctx = rctx,
params = params,
output = output,
translator_tool = TRANSLATOR_TOOL,
if type(params) == "dict":
attrs = struct(**params)
else:
attrs = params
args = _handle_args(
attrs,
str(rctx.path(Label(attrs.project_file))),
str(rctx.path(Label(attrs.lock_file))),
output,
)

pycross_pdm_lock_model = rule(
implementation = lock_model.implementation,
attrs = {
"_tool": attr.label(
default = Label("//pycross/private/tools:pdm_translator"),
cfg = "exec",
executable = True,
),
} | PDM_IMPORT_ATTRS,
)
exec_internal_tool(
rctx,
TRANSLATOR_TOOL,
args,
)
14 changes: 2 additions & 12 deletions pycross/private/tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ py_binary(
imports = ["../../.."],
visibility = ["//visibility:public"],
deps = [
":args",
":lock_model",
":translation_utils",
"@rules_pycross_internal//deps:tomli",
],
)

Expand All @@ -117,17 +118,6 @@ py_binary(
srcs = ["uv_translator.py"],
imports = ["../../.."],
visibility = ["//visibility:public"],
deps = [
":lock_model",
":translation_utils",
],
)

py_library(
name = "translation_utils",
srcs = ["translation_utils.py"],
imports = ["../../.."],
visibility = ["//visibility:public"],
deps = [
":args",
":lock_model",
Expand Down
Loading

0 comments on commit dc2dbbd

Please sign in to comment.