Skip to content

Commit

Permalink
feat: get bzlmod working in root and examples folders
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Feb 27, 2024
1 parent a99f1c3 commit 6469c46
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 64 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build --//:mypy=//third_party:mypy
common --enable_bzlmod
13 changes: 13 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
fail-fast: false
matrix:
bzlmodEnabled: [true, false]
folder: [".", "examples"]
exclude:
# No point keeping the root workspace compatible with --noenable_bzlmod
- folder: "."
bzlmodEnabled: false
defaults:
run:
working-directory: ${{ matrix.folder }}

steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it
Expand All @@ -22,5 +30,10 @@ jobs:
bazelrc: common --announce_rc --color=yes --enable_bzlmod=${{ matrix.bzlmodEnabled }}
- name: Run tests
run: bazel test //...

integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run integration tests
run: ./test.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Remove after the lockfile format is more stable
MODULE.bazel.lock

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
28 changes: 28 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"Bazel dependencies under bzlmod"

module(
name = "mypy_integration",
# Replaced with the tag during BCR publishing
version = "0.0.0",
compatibility_level = 1,
)

# Lower-bound dependency versions.
# Only increase these when needed, otherwise users get warnings from Bazel about how the selected
# version is greater than the one they specified.
bazel_dep(name = "rules_python", version = "0.27.1")
bazel_dep(name = "bazel_skylib", version = "1.5.0")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)

python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(python_version = "3.8")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True)
pip.parse(
hub_name = "pypi",
python_version = "3.8",
requirements_lock = "//third_party:requirements.txt",
)

use_repo(pip, "pypi")
65 changes: 2 additions & 63 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,63 +1,2 @@
workspace(name = "bazel_mypy_integration")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//repositories:repositories.bzl", mypy_integration_repositories = "repositories")

mypy_integration_repositories()

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
name = "python3_8",
python_version = "3.8",
)

load("@python3_8//:defs.bzl", python_interpreter = "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "mypy_integration_pip_deps",
python_interpreter_target = python_interpreter,
requirements_lock = "//third_party:requirements.txt",
)

load("@mypy_integration_pip_deps//:requirements.bzl", install_mypy_deps = "install_deps")

install_mypy_deps()

http_archive(
name = "buildifier_prebuilt",
sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e",
strip_prefix = "buildifier-prebuilt-6.4.0",
urls = [
"http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz",
],
)

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()

http_archive(
name = "com_google_protobuf",
sha256 = "d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e",
strip_prefix = "protobuf-25.3",
urls = [
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v25.3.tar.gz",
"https://github.com/protocolbuffers/protobuf/archive/v25.3.tar.gz",
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
# Marker file that this is the root of a Bazel workspace.
# Dependencies appear in MODULE.bazel
1 change: 1 addition & 0 deletions examples/.bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build --@mypy_integration//:mypy=//tools/typing:mypy
common --java_runtime_version=remotejdk_11
32 changes: 32 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"Bazel dependencies, used under --enable_bzlmod"

module(
name = "mypy-integration-examples",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "mypy_integration", version = "0.0.0")
bazel_dep(name = "rules_java", version = "7.4.0")
bazel_dep(name = "rules_python", version = "0.27.1")

local_path_override(
module_name = "mypy_integration",
path = "..",
)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.8")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "my_deps",
python_version = "3.8",
requirements_lock = "//third_party:requirements.txt",
)
pip.parse(
hub_name = "my_mypy_deps",
python_version = "3.8",
requirements_lock = "//tools/typing:mypy_requirements.txt",
)
use_repo(pip, "my_deps", "my_mypy_deps")
1 change: 1 addition & 0 deletions examples/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Under --enable_bzlmod, this file shadows WORKSPACE
2 changes: 1 addition & 1 deletion third_party/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@mypy_integration_pip_deps//:requirements.bzl", "requirement")
load("@pypi//:requirements.bzl", "requirement")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

alias(
Expand Down

0 comments on commit 6469c46

Please sign in to comment.