Skip to content
Draft
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
8 changes: 0 additions & 8 deletions examples/demo/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,3 @@ pip.parse(
},
)
use_repo(pip, "pip")

types = use_extension("@rules_mypy//mypy:types.bzl", "types")
types.requirements(
name = "pip_types",
pip_requirements = "@pip//:requirements.bzl",
requirements_txt = "//:requirements.txt",
)
use_repo(types, "pip_types")
13 changes: 13 additions & 0 deletions examples/demo/manual_stubs/explicit/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@rules_python//python:py_library.bzl", "py_library")

py_library(
name = "lib",
srcs = glob(["lib/**/*.py"]),
deps = [":foo-stubs"],
)

py_library(
name = "foo-stubs",
imports = ["."],
pyi_srcs = glob(["foo/**/*.pyi"]),
)
2 changes: 2 additions & 0 deletions examples/demo/manual_stubs/explicit/foo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Foo:
pass
1 change: 1 addition & 0 deletions examples/demo/manual_stubs/explicit/lib/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from foo import Foo
19 changes: 19 additions & 0 deletions examples/demo/manual_stubs/implicit/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@pip//:requirements.bzl", "requirement")
load("@rules_python//python:py_library.bzl", "py_library")

py_library(
name = "lib",
srcs = glob(["lib/**/*.py"]),
deps = [
# actual dependency here doesn't matter, we just need some dependency
# to implicitly provide stubs for; see `py.bzl` for the hook-up
requirement("six"),
],
)

py_library(
name = "foo-stubs",
imports = ["."],
pyi_srcs = glob(["foo/**/*.pyi"]),
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions examples/demo/manual_stubs/implicit/foo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Foo:
pass
1 change: 1 addition & 0 deletions examples/demo/manual_stubs/implicit/lib/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from foo import Foo
14 changes: 11 additions & 3 deletions examples/demo/py.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"Custom py_library rule that also runs mypy."

load("@pip_types//:types.bzl", "types")
load("@rules_mypy//mypy:mypy.bzl", "mypy")
load("@pip//:requirements.bzl", "all_requirements", "requirement")
load("@rules_mypy//mypy:mypy.bzl", "load_stubs", "mypy")

mypy_aspect = mypy(types = types)
stubs = load_stubs(
requirements = all_requirements,
overrides = {
# See manual_stubs/implicit/
requirement("six"): "@@//manual_stubs/implicit:foo-stubs",
},
)

mypy_aspect = mypy(stubs = stubs)
6 changes: 5 additions & 1 deletion examples/demo/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
cachetools~=5.4.0
# ----- thm/ dependencies ----- #
numpy~=1.26.4
cachetools~=5.4.0
types-cachetools~=5.4.0.20240717

# ---- manual_stubs/ dependencies ----- #
six==1.17.0
4 changes: 4 additions & 0 deletions examples/demo/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ numpy==1.26.4 \
--hash=sha256:f870204a840a60da0b12273ef34f7051e98c3b5961b61b0c2c1be6dfd64fbcd3 \
--hash=sha256:ffa75af20b44f8dba823498024771d5ac50620e6915abac414251bd971b4529f
# via -r requirements.in
six==1.17.0 \
--hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \
--hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81
# via -r requirements.in
types-cachetools==5.4.0.20240717 \
--hash=sha256:1eae90c48760bac44ab89108be938e8ce1d740910f2d4b68446dcdc82763f186 \
--hash=sha256:67c84c26df988039be68344b162afd2dd7cd3741dc08e7d67aa1954782fd2d2a
Expand Down
8 changes: 8 additions & 0 deletions examples/demo/thm/b/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ py_library(
requirement("numpy"),
],
)

# test external dependency in a transitive dependency
py_library(
name = "b2",
srcs = ["b2.py"],
visibility = ["//visibility:public"],
deps = ["b"],
)
Empty file added examples/demo/thm/b/b2.py
Empty file.
8 changes: 0 additions & 8 deletions examples/opt-in/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,3 @@ pip.parse(
},
)
use_repo(pip, "pip")

types = use_extension("@rules_mypy//mypy:types.bzl", "types")
types.requirements(
name = "pip_types",
pip_requirements = "@pip//:requirements.bzl",
requirements_txt = "//:requirements.txt",
)
use_repo(types, "pip_types")
8 changes: 5 additions & 3 deletions examples/opt-in/py.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"Custom py_library rule that also runs mypy."

load("@pip_types//:types.bzl", "types")
load("@rules_mypy//mypy:mypy.bzl", "mypy")
load("@pip//:requirements.bzl", "all_requirements")
load("@rules_mypy//mypy:mypy.bzl", "load_stubs", "mypy")

stubs = load_stubs(requirements = all_requirements)

mypy_aspect = mypy(
# only run mypy on targets with the typecheck tag
opt_in_tags = ["typecheck"],
types = types,
stubs = stubs,
)
12 changes: 0 additions & 12 deletions mypy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,3 @@ bzl_library(
srcs = ["mypy.bzl"],
visibility = ["//visibility:public"],
)

bzl_library(
name = "py_type_library",
srcs = ["py_type_library.bzl"],
visibility = ["//visibility:public"],
)

bzl_library(
name = "types",
srcs = ["types.bzl"],
visibility = ["//visibility:public"],
)
9 changes: 8 additions & 1 deletion mypy/mypy.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"Public API for interacting with the mypy rule."

load("//mypy/private:mypy.bzl", _mypy = "mypy", _mypy_cli = "mypy_cli")
load(
"//mypy/private:mypy.bzl",
_load_stubs = "load_stubs",
_mypy = "mypy",
_mypy_cli = "mypy_cli",
)

load_stubs = _load_stubs

# re-export mypy aspect factory
mypy = _mypy
Expand Down
25 changes: 0 additions & 25 deletions mypy/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_mypy_pip//:requirements.bzl", "requirement")
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_uv//uv:pip.bzl", "pip_compile")
load("@rules_uv//uv:venv.bzl", "create_venv")
load(":mypy.bzl", "mypy_cli")
Expand All @@ -16,18 +14,6 @@ bzl_library(
visibility = ["//mypy:__subpackages__"],
)

bzl_library(
name = "py_type_library_rules",
srcs = ["py_type_library.bzl"],
visibility = ["//mypy:__subpackages__"],
)

bzl_library(
name = "types_rules",
srcs = ["types.bzl"],
visibility = ["//mypy:__subpackages__"],
)

pip_compile(
name = "generate_requirements_lock",
requirements_in = "requirements.in",
Expand All @@ -40,14 +26,3 @@ create_venv(
)

mypy_cli(name = "mypy")

py_binary(
name = "py_type_library",
srcs = ["py_type_library.py"],
main = "py_type_library.py",
python_version = "3.12",
visibility = ["//visibility:public"],
deps = [
requirement("click"),
],
)
Loading
Loading