feat: Have `pip_compile` generate a `*.test` target; deprecate `*_test` (#2812)
Fixes #2794.
The `pip_compile` macro generates `*_test` and `*.update` targets. This
pattern does not match with other macros that generate similar targets,
namely `gazelle_python_manifest` and uv `lock` (though that's `.run`
instead of `.test` but either way, it uses a dot `.` instead of
underscore
`_`).
Adjust the macro so that a `.test` target is made. The `_test` target is
aliased with a deprecation warning, to be removed in the next major
version.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f696cef..b176766 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -57,6 +57,9 @@
* (rules) On Windows, {obj}`--bootstrap_impl=system_python` is forced. This
allows setting `--bootstrap_impl=script` in bazelrc for mixed-platform
environments.
+* (rules) {obj}`pip_compile` now generates a `.test` target. The `_test` target is deprecated
+ and will be removed in the next major release.
+ ([#2794](https://github.com/bazel-contrib/rules_python/issues/2794)
{#v0-0-0-fixed}
### Fixed
diff --git a/python/private/pypi/pip_compile.bzl b/python/private/pypi/pip_compile.bzl
index 7edbf7d..e5b62c4 100644
--- a/python/private/pypi/pip_compile.bzl
+++ b/python/private/pypi/pip_compile.bzl
@@ -47,7 +47,7 @@
It also generates two targets for running pip-compile:
- - validate with `bazel test [name]_test`
+ - validate with `bazel test [name].test`
- update with `bazel run [name].update`
If you are using a version control system, the requirements.txt generated by this rule should
@@ -166,7 +166,7 @@
timeout = kwargs.pop("timeout", "short")
py_test(
- name = name + "_test",
+ name = name + ".test",
timeout = timeout,
# setuptools (the default python build tool) attempts to find user
# configuration in the user's home direcotory. This seems to work fine on
@@ -180,3 +180,9 @@
# kwargs could contain test-specific attributes like size
**dict(attrs, **kwargs)
)
+
+ native.alias(
+ name = "{}_test".format(name),
+ actual = ":{}.test".format(name),
+ deprecation = "Use '{}.test' instead. The '*_test' target will be removed in the next major release.".format(name),
+ )