Skip to content

Commit ced0c10

Browse files
authored
chore: use rules_shell (bazel-contrib#2305)
Summary: - move bazelversion sh_test to //tests - add rules_shell dev dependency - use sh_test for the sh_py_run_test - use rules_shell in examples/bzlmod - use rules_shell in multi_python_versions example Fixes bazel-contrib#2299.
1 parent f22f39c commit ced0c10

File tree

14 files changed

+86
-36
lines changed

14 files changed

+86
-36
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, execute
66
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
7-
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
8-
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
7+
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
8+
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
99

1010
test --test_output=errors
1111

BUILD.bazel

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16-
load(":version.bzl", "BAZEL_VERSION")
1716

1817
package(default_visibility = ["//visibility:public"])
1918

@@ -24,6 +23,11 @@ exports_files([
2423
"version.bzl",
2524
])
2625

26+
exports_files(
27+
[".bazelversion"],
28+
visibility = ["//tests:__subpackages__"],
29+
)
30+
2731
exports_files(
2832
glob(["*.md"]),
2933
visibility = ["//docs:__subpackages__"],
@@ -69,29 +73,3 @@ filegroup(
6973
],
7074
visibility = ["//visibility:public"],
7175
)
72-
73-
genrule(
74-
name = "assert_bazelversion",
75-
srcs = [".bazelversion"],
76-
outs = ["assert_bazelversion_test.sh"],
77-
cmd = """\
78-
set -o errexit -o nounset -o pipefail
79-
current=$$(cat "$(execpath .bazelversion)")
80-
cat > "$@" <<EOF
81-
#!/usr/bin/env bash
82-
set -o errexit -o nounset -o pipefail
83-
if [[ \"$${{current}}\" != \"{expected}\" ]]; then
84-
>&2 echo "ERROR: current bazel version '$${{current}}' is not the expected '{expected}'"
85-
exit 1
86-
fi
87-
EOF
88-
""".format(
89-
expected = BAZEL_VERSION,
90-
),
91-
executable = True,
92-
)
93-
94-
sh_test(
95-
name = "assert_bazelversion_test",
96-
srcs = [":assert_bazelversion_test.sh"],
97-
)

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ A brief description of the categories of changes:
6363
enables (or disables) using pyc files from targets transitively
6464
* (pip) Skip patching wheels not matching `pip.override`'s `file`
6565
([#2294](https://github.com/bazelbuild/rules_python/pull/2294)).
66+
* (chore): Add a `rules_shell` dev dependency and moved a `sh_test` target
67+
outside of the `//:BUILD.bazel` file.
68+
Fixes [#2299](https://github.com/bazelbuild/rules_python/issues/2299).
6669

6770
### Added
6871
* (py_wheel) Now supports `compress = (True|False)` to allow disabling

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ bazel_dep(name = "stardoc", version = "0.6.2", repo_name = "io_bazel_stardoc")
7272
# ===== DEV ONLY DEPS AND SETUP BELOW HERE =====
7373
bazel_dep(name = "rules_bazel_integration_test", version = "0.20.0", dev_dependency = True)
7474
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
75+
bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True)
7576

7677
# Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests.
7778
# We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides.

examples/bzlmod/MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,6 @@ local_path_override(
256256
module_name = "other_module",
257257
path = "other_module",
258258
)
259+
260+
# example test dependencies
261+
bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True)

examples/bzlmod/MODULE.bazel.lock

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bzlmod/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@python_versions//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9
44
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING")
55
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
66
load("@rules_python//python/config_settings:transition.bzl", py_versioned_binary = "py_binary", py_versioned_test = "py_test")
7+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
78

89
py_binary(
910
name = "version_default",

examples/multi_python_versions/MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ pip.parse(
5555
python_version = "3.11",
5656
requirements_lock = "//requirements:requirements_lock_3_11.txt",
5757
)
58+
59+
# example test dependencies
60+
bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True)

examples/multi_python_versions/WORKSPACE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,19 @@ multi_pip_parse(
4545
load("@pypi//:requirements.bzl", "install_deps")
4646

4747
install_deps()
48+
49+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
50+
51+
# See https://github.com/bazelbuild/rules_shell/releases/tag/v0.2.0
52+
http_archive(
53+
name = "rules_shell",
54+
sha256 = "410e8ff32e018b9efd2743507e7595c26e2628567c42224411ff533b57d27c28",
55+
strip_prefix = "rules_shell-0.2.0",
56+
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.2.0/rules_shell-v0.2.0.tar.gz",
57+
)
58+
59+
load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")
60+
61+
rules_shell_dependencies()
62+
63+
rules_shell_toolchains()

examples/multi_python_versions/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@python//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_
44
load("@python//3.8:defs.bzl", py_binary_3_8 = "py_binary", py_test_3_8 = "py_test")
55
load("@python//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test")
66
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
7+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
78

89
copy_file(
910
name = "copy_version",

0 commit comments

Comments
 (0)