Skip to content

Commit ce32226

Browse files
committed
Switch over to getting rules_python from bzlmod when using bzlmod
Progress toward #157
1 parent f41ec09 commit ce32226

File tree

6 files changed

+52
-64
lines changed

6 files changed

+52
-64
lines changed

MODULE.bazel

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
module(name = "hedron_compile_commands")
22

3-
use_extension("//:workspace_setup.bzl", "hedron_compile_commands_extension")
4-
use_extension("//:workspace_setup_transitive.bzl", "hedron_compile_commands_extension")
5-
use_extension("//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_extension")
6-
use_extension("//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_extension")
3+
p = use_extension("//:workspace_setup.bzl", "hedron_compile_commands_extension")
4+
pt = use_extension("//:workspace_setup_transitive.bzl", "hedron_compile_commands_extension")
5+
ptt = use_extension("//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_extension")
6+
pttt = use_extension("//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_extension")
77

8-
# While we're supporting the WORKSPACE, we need to load rules_python through its WORKSPACE mechanism because the (currently unstable) bzlmod APIs differ just enough that loads would fail if you tried to support both at the same time.
9-
# But this is how you'd load rules_python from bzlmod:
10-
# bazel_dep(name = "rules_python", version = "0.27.1")
11-
# python = use_extension("@rules_python//python/extensions:python.bzl", "python")
12-
# python.toolchain(
13-
# python_version = "3.11",
14-
# )
15-
# use_repo(python, "python_versions")
16-
# pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
17-
# pip.parse(
18-
# hub_name = "hedron_compile_commands_pip",
19-
# # Available versions are listed in @rules_python//python:versions.bzl.
20-
# python_version = "3.11",
21-
# requirements_lock = "//:requirements.txt",
22-
# )
23-
# use_repo(pip, "hedron_compile_commands_pip")
8+
9+
bazel_dep(name = "rules_python", version = "0.27.1")
10+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
11+
python.toolchain(
12+
python_version = "3.11",
13+
)
14+
use_repo(python, "python_3_11")
15+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
16+
pip.parse(
17+
hub_name = "hedron_compile_commands_pip",
18+
# Available versions are listed in @rules_python//python:versions.bzl.
19+
python_version = "3.11",
20+
requirements_lock = "//:requirements.txt",
21+
)
22+
use_repo(pip, "hedron_compile_commands_pip")

WORKSPACE

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
# This file existed originally to enable quick local development via local_repository.
1+
# This file existed originally to enable quick local development via local_repository from WORKSPACE-based projects.
22
# See ./ImplementationReadme.md for details on local development.
33
# Why? local_repository doesn't work without a WORKSPACE, and new_local_repository requires overwriting the BUILD file (as of Bazel 7).
44

55
workspace(name = "hedron_compile_commands")
66

7-
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
8-
hedron_compile_commands_setup()
9-
load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive")
10-
hedron_compile_commands_setup_transitive()
11-
load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive")
12-
hedron_compile_commands_setup_transitive_transitive()
13-
load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive")
14-
hedron_compile_commands_setup_transitive_transitive_transitive()
7+
# Note that we're now using Bzlmod inside this repo during development, so things should be added to MODULE.bazel or, if needed, workspace_setup.bzl.

workspace_setup.bzl

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@ def hedron_compile_commands_setup(module_ctx = None):
1414
# Unified setup for users' WORKSPACES and this workspace when used standalone.
1515
# See invocations in:
1616
# README.md (for WORKSPACE users)
17-
# MODULE.bazel (for bzlmod users)
18-
# WORKSPACE (for working on this repo standalone)
19-
20-
# If adding dependencies available via bzlmod, consider adding them to MODULE.bazel, too, and only loading them the WORKSPACE way when needed.
21-
# if not module_ctx:
22-
# # Load bzlmod-available packages.
23-
24-
# rules_python cannot be loaded this way because the WORKSPACE and (currently unstable) bzlmod APIs differ just enough that loads would fail if you tried to support both at the same time.
25-
maybe(
26-
http_archive,
27-
name = "rules_python",
28-
sha256 = "e85ae30de33625a63eca7fc40a94fea845e641888e52f32b6beea91e8b1b2793",
29-
strip_prefix = "rules_python-0.27.1",
30-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.1/rules_python-0.27.1.tar.gz",
31-
)
17+
# MODULE.bazel (for bzlmod users and for working on this repo standalone)
18+
19+
# If adding dependencies available via bzlmod, consider adding them to MODULE.bazel, too, and only loading them the WORKSPACE way when needed. For example:
20+
if not module_ctx:
21+
maybe(
22+
http_archive,
23+
name = "rules_python",
24+
sha256 = "e85ae30de33625a63eca7fc40a94fea845e641888e52f32b6beea91e8b1b2793",
25+
strip_prefix = "rules_python-0.27.1",
26+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.1/rules_python-0.27.1.tar.gz",
27+
)
3228

3329

3430
hedron_compile_commands_extension = module_extension( # Note: Doesn't break loading from WORKSPACE as far back as Bazel 5.0.0

workspace_setup_transitive.bzl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ def hedron_compile_commands_setup_transitive(module_ctx = None):
2424
# Unified setup for users' WORKSPACES and this workspace when used standalone.
2525
# See invocations in:
2626
# README.md (for WORKSPACE users)
27-
# MODULE.bazel (for bzlmod users)
28-
# WORKSPACE (for working on this repo standalone)
29-
30-
py_repositories()
31-
python_register_toolchains(
32-
name = "python_3_11",
33-
# Available versions are listed in @rules_python//python:versions.bzl.
34-
python_version = "3.11",
35-
)
27+
# MODULE.bazel (for bzlmod users and for working on this repo standalone)
28+
29+
if not module_ctx:
30+
py_repositories()
31+
python_register_toolchains(
32+
name = "python_3_11",
33+
# Available versions are listed in @rules_python//python:versions.bzl.
34+
python_version = "3.11",
35+
)
3636

3737
hedron_compile_commands_extension = module_extension( # Note: Doesn't break loading from WORKSPACE as far back as Bazel 5.0.0
3838
implementation = hedron_compile_commands_setup_transitive,

workspace_setup_transitive_transitive.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ def hedron_compile_commands_setup_transitive_transitive(module_ctx = None):
2727
# Unified setup for users' WORKSPACES and this workspace when used standalone.
2828
# See invocations in:
2929
# README.md (for WORKSPACE users)
30-
# MODULE.bazel (for bzlmod users)
31-
# WORKSPACE (for working on this repo standalone)
32-
33-
pip_parse(
34-
name = "hedron_compile_commands_pip",
35-
python_interpreter_target = interpreter,
36-
requirements_lock = "@hedron_compile_commands//:requirements.txt",
37-
)
30+
# MODULE.bazel (for bzlmod users and for working on this repo standalone)
31+
32+
if not module_ctx:
33+
pip_parse(
34+
name = "hedron_compile_commands_pip",
35+
python_interpreter_target = interpreter,
36+
requirements_lock = "@hedron_compile_commands//:requirements.txt",
37+
)
3838

3939

4040
hedron_compile_commands_extension = module_extension( # Note: Doesn't break loading from WORKSPACE as far back as Bazel 5.0.0

workspace_setup_transitive_transitive_transitive.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def hedron_compile_commands_setup_transitive_transitive_transitive(module_ctx =
2626
# Unified setup for users' WORKSPACES and this workspace when used standalone.
2727
# See invocations in:
2828
# README.md (for WORKSPACE users)
29-
# MODULE.bazel (for bzlmod users)
30-
# WORKSPACE (for working on this repo standalone)
29+
# MODULE.bazel (for bzlmod users and for working on this repo standalone)
3130

32-
install_deps()
31+
if not module_ctx:
32+
install_deps()
3333

3434

3535
hedron_compile_commands_extension = module_extension( # Note: Doesn't break loading from WORKSPACE as far back as Bazel 5.0.0

0 commit comments

Comments
 (0)