Skip to content

Commit

Permalink
chore: minimal changes required to upgrade to Bazel 7 and bzlmod
Browse files Browse the repository at this point in the history
In a follow-up change I'll try to empty out the WORKSPACE file.
  • Loading branch information
alexeagle committed Dec 21, 2023
1 parent ca2c008 commit 5b89ee0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
4 changes: 0 additions & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ test --test_output=errors
# Define value used by tests
build --define=SOME_VAR=SOME_VALUE

# Use local rules_python
# Enable with --config=dev
common:dev --override_repository=rules_python=~/workspace/rules_python

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
6.3.2
7.0.0
# The first line of this file is used by Bazelisk and Bazel to be sure
# the right version of Bazel is used to build and test this repo.
# This also defines which version is used on CI.
Expand Down
11 changes: 10 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ module(
# When bumping, add a comment explaining what's required from the newer release.
bazel_dep(name = "aspect_bazel_lib", version = "1.38.1")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "rules_python", version = "0.19.0")
# This is the minimum version that includes
# feat(pip): provide pypi -> whl target mapping in requirements.bzl by @alexeagle in #1532
bazel_dep(name = "rules_python", version = "0.27.0")

bazel_dep(name = "rules_testing", version = "0.5.0", dev_dependency = True)

python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(
python_version = "3.9",
)
3 changes: 1 addition & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Declare the local Bazel workspace.
workspace(name = "aspect_rules_py")
# Marker that this folder is the root of a Bazel workspace.

load(":internal_deps.bzl", "rules_py_internal_deps")

Expand Down
6 changes: 4 additions & 2 deletions py/tests/external-deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ genrule(
cmd = "|".join([
"$(execpath pathing)",
"""sed "s#$$(pwd)#(pwd)#" """,
"sed 's#^.*execroot/aspect_rules_py/external/python_toolchain_%s#(py_toolchain)#'" % host_platform,
"sed 's#bazel-out/[_a-z0-9-]*-exec-[A-Z0-9]*/bin/#bazel-out/[exec]/bin/#'",
# scrub various platform-specific paths, so our expected_pathing file is portable
"sed 's#^.*execroot/_main/external/rules_python~[0-9.]*~python~python_3_9_%s#(py_toolchain)#'" % host_platform,
"sed 's#^/tmp/bazel-source-roots/[0-9]#(py_toolchain)#'",
"sed 's#bazel-out/[_a-z0-9-]*-exec-[A-Za-f0-9-]*/bin/#bazel-out/[exec]/bin/#'",
"sed 's#(main, .*)#(main, REDACTED)#'",
]) + "> $@",
tools = ["pathing"],
Expand Down
8 changes: 4 additions & 4 deletions py/tests/external-deps/expected_pathing
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ sys path:
(py_toolchain)/lib/python3.9/lib-dynload
(pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/pathing.venv/lib/python3.9/site-packages
(pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles
(pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py/py/tests/external-deps
(pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py
(pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/_main/py/tests/external-deps
(pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/_main

Entrypoint Path: (pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py/py/tests/external-deps/pathing.py
Entrypoint Path: (pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/_main/py/tests/external-deps/pathing.py

Django location: (pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/pathing.venv/lib/python3.9/site-packages/django/__init__.py
Django version: 4.2.7

From lib with wheel dependency: Hello Matt
lib filepath: (pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py/py/tests/external-deps/lib.py
lib filepath: (pwd)/bazel-out/[exec]/bin/py/tests/external-deps/pathing.runfiles/_main/py/tests/external-deps/lib.py
2 changes: 1 addition & 1 deletion py/tests/import-pathing/tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _can_resolve_path_in_workspace_test_impl(ctx):
# Transitive imports are included in depset
fake_ctx = _ctx_with_imports([".."], [ctx.attr.import_dep])
imports = py_library.make_imports_depset(fake_ctx).to_list()
asserts.equals(env, "aspect_rules_py/py/tests/import-pathing/baz", imports[0])
asserts.equals(env, "_main/py/tests/import-pathing/baz", imports[0])
asserts.equals(env, "aspect_rules_py/foo", imports[1])

return unittest.end(env)
Expand Down
9 changes: 8 additions & 1 deletion py/tests/py-test/test_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ def test_env(env, expected):
test_env('LOCATION', "py/tests/py-test/test_env_vars.py")
test_env('DEFINE', "SOME_VALUE")
test_env('BAZEL_TARGET', "//py/tests/py-test:test_env_vars")
test_env('BAZEL_WORKSPACE', "aspect_rules_py")
# With bzlmod enabled, the main workspace has this hard-coded name.
# See https://bazelbuild.slack.com/archives/C014RARENH0/p1702318129963129?thread_ts=1702288944.560349&cid=C014RARENH0
# Xudong Yang:
# the 'workspace name' is an unfortunate concept laden with historical baggage.
# The better question here might be -- what do you intend to do with the 'workspace name'?
# the name of the execution root directory will always be _main when Bzlmod is enabled.
# similarly, the runfiles dir prefix for the main repo will always be _main.
test_env('BAZEL_WORKSPACE', "_main")
test_env('BAZEL_TARGET_NAME', "test_env_vars")

0 comments on commit 5b89ee0

Please sign in to comment.