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
10 changes: 10 additions & 0 deletions examples/demo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_uv//uv:pip.bzl", "pip_compile")
load("@rules_uv//uv:venv.bzl", "create_venv")

Expand All @@ -11,3 +12,12 @@ create_venv(
name = "venv",
requirements_txt = "requirements.txt",
)

bzl_library(
name = "py",
srcs = ["py.bzl"],
deps = [
"@pip_types//:types",
"@rules_mypy//mypy",
],
)
20 changes: 20 additions & 0 deletions mypy/private/types.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,31 @@ def _render_build(rctx, types):
pip_requirements = rctx.attr.pip_requirements,
)
content += """load("@rules_mypy//mypy:py_type_library.bzl", "py_type_library")\n"""
content += 'load({bzl_library_bzl}, "bzl_library")\n'.format(
bzl_library_bzl = repr(str(Label("@bazel_skylib//:bzl_library.bzl"))),
)
for requirement in types:
content += _PY_TYPE_LIBRARY_TEMPLATE.format(
requirement = requirement,
raw = requirement.removeprefix("types-").removesuffix("-stubs"),
) + "\n"
content += '''bzl_library(
name = "types",
srcs = ["types.bzl"],
deps = [":requirements"],
visibility = ["//visibility:public"],
)

bzl_library(
name = "requirements",
srcs = [{requirements_bzl}],
deps = [{pip_bzl}],
visibility = ["//visibility:private"],
)
'''.format(
requirements_bzl = repr(str(rctx.attr.pip_requirements)),
pip_bzl = repr(str(Label("@rules_python//python:pip_bzl"))),
)
return content

def _render_types_bzl(rctx, types):
Expand Down