Update to support newer rules_python (#73)
rules_python now is replacing the repo specific python version setup
with setting python_version on the py_binary target.
This newer version requires bazel 7.1.x because of
https://github.com/bazelbuild/rules_python/issues/2606
```
WARNING: .../rules_mypy++types+pip_types/BUILD.bazel:25:16: in py_type_library rule @@rules_mypy++types+pip_types//:types-setuptools: target '@@rules_mypy++types+pip_types//:types-setuptools' depends on deprecated target '@@rules_mypy+//mypy/private:py_type_library':
The py_binary symbol in @rules_python//python/config_settings:transition.bzl
is deprecated. It is an alias to the regular rule; use it directly instead:
load("@rules_python//python:py_binary.bzl", "py_binary")
```diff --git a/.bazelversion b/.bazelversion
index 66ce77b..a3fcc71 100644
--- a/.bazelversion
+++ b/.bazelversion
@@ -1 +1 @@
-7.0.0
+7.1.0
diff --git a/MODULE.bazel b/MODULE.bazel
index 4689de9..11e0a65 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -8,25 +8,21 @@
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
bazel_dep(name = "platforms", version = "0.0.8")
-bazel_dep(name = "rules_python", version = "0.34.0")
+bazel_dep(name = "rules_python", version = "1.1.0")
bazel_dep(name = "rules_uv", version = "0.21.0")
# configuration
PYTHON_VERSION = "3.12"
-PYTHON_VERSION_SNAKE = PYTHON_VERSION.replace(".", "_")
-
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
is_default = True,
python_version = PYTHON_VERSION,
)
-use_repo(python, "python_" + PYTHON_VERSION_SNAKE, "python_versions")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
enable_implicit_namespace_pkgs = True,
- experimental_index_url = "https://pypi.org/simple", # use Bazel downloader
hub_name = "rules_mypy_pip",
python_version = PYTHON_VERSION,
requirements_by_platform = {
diff --git a/examples/demo/.bazelversion b/examples/demo/.bazelversion
deleted file mode 100644
index 66ce77b..0000000
--- a/examples/demo/.bazelversion
+++ /dev/null
@@ -1 +0,0 @@
-7.0.0
diff --git a/examples/demo/.bazelversion b/examples/demo/.bazelversion
new file mode 120000
index 0000000..96cf949
--- /dev/null
+++ b/examples/demo/.bazelversion
@@ -0,0 +1 @@
+../../.bazelversion
\ No newline at end of file
diff --git a/examples/opt-in/.bazelversion b/examples/opt-in/.bazelversion
deleted file mode 100644
index 66ce77b..0000000
--- a/examples/opt-in/.bazelversion
+++ /dev/null
@@ -1 +0,0 @@
-7.0.0
diff --git a/examples/opt-in/.bazelversion b/examples/opt-in/.bazelversion
new file mode 120000
index 0000000..96cf949
--- /dev/null
+++ b/examples/opt-in/.bazelversion
@@ -0,0 +1 @@
+../../.bazelversion
\ No newline at end of file
diff --git a/mypy/private/BUILD.bazel b/mypy/private/BUILD.bazel
index 4af6287..47aa854 100644
--- a/mypy/private/BUILD.bazel
+++ b/mypy/private/BUILD.bazel
@@ -1,6 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-load("@python_versions//3.12:defs.bzl", "py_binary")
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")
@@ -45,6 +45,7 @@
name = "py_type_library",
srcs = ["py_type_library.py"],
main = "py_type_library.py",
+ python_version = "3.12",
visibility = ["//visibility:public"],
deps = [
requirement("click"),
diff --git a/mypy/private/mypy.bzl b/mypy/private/mypy.bzl
index 3408c63..5500685 100644
--- a/mypy/private/mypy.bzl
+++ b/mypy/private/mypy.bzl
@@ -7,8 +7,8 @@
directories.
"""
-load("@python_versions//3.12:defs.bzl", py312_binary = "py_binary")
load("@rules_mypy_pip//:requirements.bzl", "requirement")
+load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_info.bzl", RulesPythonPyInfo = "PyInfo")
load(":py_type_library.bzl", "PyTypeLibraryInfo")
@@ -263,7 +263,7 @@
} | additional_attrs,
)
-def mypy_cli(name, deps = None, mypy_requirement = None, py_binary = py312_binary, tags = None):
+def mypy_cli(name, deps = None, mypy_requirement = None, python_version = "3.12", tags = None):
"""
Produce a custom mypy executable for use with the mypy build rule.
@@ -273,7 +273,8 @@
(note: must match the Python version of py_binary)
mypy_requirement: (optional) a replacement mypy requirement
(note: must match the Python version of py_binary)
- py_binary: (optional) the py_binary rule to use when constructing this target
+ python_version: (optional) the python_version to use for this target.
+ Pass None to use the default
(defaults to a rules_mypy specified version, currently Python 3.12)
tags: (optional) tags to include in the binary target
"""
@@ -287,5 +288,6 @@
main = "@rules_mypy//mypy/private:mypy.py",
visibility = ["//visibility:public"],
deps = [mypy_requirement] + deps,
+ python_version = python_version,
tags = tags,
)