Skip to content

chore: turn on bzlmod #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

test --test_output=errors

# TODO(alex): enable
common --noenable_bzlmod

# Define value used by tests
build --define=SOME_VAR=SOME_VALUE

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
# NB: the root folder is tested with Aspect Workflows on BuildKite, see /.aspect/workflows/config.yaml
folders: '["e2e/smoke", "e2e/repository-rule-deps", "e2e/system-interpreter", "examples/uv_pip_compile"]'
# TODO: Build Windows tools and add to toolchain
# TODO(alex): switch the root folder to bzlmod
# TODO: fix remaining folders on Bazel 8
exclude: |
[
Expand Down
22 changes: 0 additions & 22 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@pypi//:requirements.bzl", "all_whl_requirements")
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")
load("@rules_python_gazelle_plugin//:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS")
load("@rules_python_gazelle_plugin//manifest:defs.bzl", "gazelle_python_manifest")
Expand Down Expand Up @@ -43,24 +42,3 @@ modules_mapping(
name = "modules_map",
wheels = all_whl_requirements,
)

py_runtime(
name = "container_py3_runtime",
interpreter_path = "/usr/bin/python",
python_version = "PY3",
)

py_runtime_pair(
name = "container_py_runtime_pair",
py2_runtime = None,
py3_runtime = ":container_py3_runtime",
)

toolchain(
name = "container_py_toolchain",
exec_compatible_with = [
"@io_bazel_rules_docker//platforms:run_in_container",
],
toolchain = ":container_py_runtime_pair",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)
19 changes: 18 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bazel_dep(name = "platforms", version = "0.0.7")
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(
is_default = False,
python_version = "3.8.12",
python_version = "3.9",
)

tools = use_extension("//py:extensions.bzl", "py_tools")
Expand Down Expand Up @@ -82,3 +82,20 @@ crate.from_cargo(
],
)
use_repo(crate, "crate_index")

# For building test images with py_image_layer
bazel_dep(name = "container_structure_test", version = "1.19.1", dev_dependency = True)
bazel_dep(name = "rules_oci", version = "2.0.1", dev_dependency = True)

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci", dev_dependency = True)
oci.pull(
name = "ubuntu",
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
image = "ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
tag = "latest",
)
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")
45 changes: 26 additions & 19 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ load("//py:toolchains.bzl", "rules_py_toolchains")

rules_py_toolchains()

# Load the Python toolchain for rules_docker
register_toolchains("//:container_py_toolchain")

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

python_register_toolchains(
Expand Down Expand Up @@ -139,22 +136,6 @@ load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_se

bazel_skylib_gazelle_plugin_setup(register_go_toolchains = False)

############################################
# rules_docker dependencies for containers
load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
container_repositories = "repositories",
)

container_repositories()

load(
"@io_bazel_rules_docker//python3:image.bzl",
_py_image_repos = "repositories",
)

_py_image_repos()

############################################
# rules_rust dependencies for building tools
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set")
Expand Down Expand Up @@ -306,3 +287,29 @@ crates_repository(
load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")

rules_oci_dependencies()

load("@rules_oci//oci:repositories.bzl", "oci_register_toolchains")

oci_register_toolchains(name = "oci")

# You can pull your base images using oci_pull like this:
load("@rules_oci//oci:pull.bzl", "oci_pull")

oci_pull(
name = "ubuntu",
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
image = "ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
tag = "latest",
)

load("@container_structure_test//:repositories.bzl", "container_structure_test_register_toolchain")

container_structure_test_register_toolchain(name = "cst")
21 changes: 14 additions & 7 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,27 @@ def rules_py_internal_deps():
],
)

http_archive(
name = "io_bazel_rules_docker",
sha256 = "9d41cbe09688d4de137b19091f162de05be9a629a4355bfc1a993f378231730a",
strip_prefix = "rules_docker-3040e1fd74659a52d1cdaff81359f57ee0e2bb41",
urls = ["https://github.com/bazelbuild/rules_docker/archive/3040e1fd74659a52d1cdaff81359f57ee0e2bb41.zip"],
)

http_archive(
name = "rules_python_gazelle_plugin",
sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311",
strip_prefix = "rules_python-0.31.0/gazelle",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz",
)

http_archive(
name = "rules_oci",
sha256 = "1bd16e455278d523f01326e0c3964cd64d7840a7e99cdd6e2617e59f698f3504",
strip_prefix = "rules_oci-2.2.0",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v2.2.0/rules_oci-v2.2.0.tar.gz",
)

http_archive(
name = "container_structure_test",
integrity = "sha256-TLs4LT1+3JcSn3n4MZbJXmAG2QY9ntuzOiMRupNyrTk=",
strip_prefix = "container-structure-test-1.19.3",
url = "https://github.com/GoogleContainerTools/container-structure-test/archive/refs/tags/v1.19.3.zip",
)

http_archive(
name = "rules_rust",
integrity = "sha256-heIBNyerJvsiq9/+SyrAwnotW2KWFnumPY9uExQPUfk=",
Expand Down
38 changes: 0 additions & 38 deletions py/tests/containers/BUILD.bazel

This file was deleted.

8 changes: 0 additions & 8 deletions py/tests/containers/branding/BUILD.bazel

This file was deleted.

14 changes: 0 additions & 14 deletions py/tests/containers/py_image_test.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion py/tests/internal-deps/adder/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ py_library(
# This library contributes to the container test, testing we can pull in and use a library from another
# package in the repo.
visibility = [
"//py/tests/containers:__pkg__",
"//py/tests/internal-deps:__pkg__",
"//py/tests/py_image_layer:__pkg__",
],
)
34 changes: 32 additions & 2 deletions py/tests/py_image_layer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("//py:defs.bzl", "py_binary", "py_image_layer")
load("asserts.bzl", "assert_tar_listing")

Expand All @@ -9,10 +11,15 @@ platform(
],
)

# Case 1: Basic usage
py_binary(
name = "my_app_bin",
srcs = ["main.py"],
srcs = ["__main__.py"],
tags = ["manual"],
deps = [
"//py/tests/internal-deps/adder",
"//py/tests/py_image_layer/branding",
"@pypi_colorama//:pkg",
],
)

py_image_layer(
Expand All @@ -26,3 +33,26 @@ assert_tar_listing(
actual = [":my_app_layers"],
expected = ":my_app_layers.listing",
)

oci_image(
name = "image",
# This is defined by an oci.pull() call in /MODULE.bazel
base = "@ubuntu",
entrypoint = ["/{}/my_app_bin".format(package_name())],
tars = [":my_app_layers"],
)

# To build the image and load it into it into a local runtime:
# $ bazel run //py/tests/py_image_layer:image_load
# $ docker run --rm gcr.io/oci_python_hello_world:latest
oci_load(
name = "image_load",
image = ":image",
repo_tags = ["gcr.io/oci_python_hello_world:latest"],
)

container_structure_test(
name = "py_image_test",
configs = ["py_image_test.yaml"],
image = ":image",
)
File renamed without changes.
1 change: 0 additions & 1 deletion py/tests/py_image_layer/asserts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ def assert_tar_listing(name, actual, expected):
in_file = actual_listing,
out_file = expected,
testonly = True,
tags = ["skip-on-bazel6"],
)
8 changes: 8 additions & 0 deletions py/tests/py_image_layer/branding/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@aspect_rules_py//py:defs.bzl", "py_library")

py_library(
name = "branding",
srcs = ["__init__.py"],
imports = [".."],
visibility = ["//py/tests/py_image_layer:__pkg__"],
)
1 change: 0 additions & 1 deletion py/tests/py_image_layer/main.py

This file was deleted.

42 changes: 36 additions & 6 deletions py/tests/py_image_layer/my_app_layers.listing
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,29 @@ drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app
-rwxr-xr-x 0 0 0 3697 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/lib/python3.9/site-packages/setuptools/warnings.py
-rwxr-xr-x 0 0 0 8628 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/lib/python3.9/site-packages/setuptools/wheel.py
-rwxr-xr-x 0 0 0 719 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/lib/python3.9/site-packages/setuptools/windows_support.py
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/
-rwxr-xr-x 0 0 0 149 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/__init__.py
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/
-rwxr-xr-x 0 0 0 266 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/__init__.py
-rwxr-xr-x 0 0 0 2522 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/ansi.py
-rwxr-xr-x 0 0 0 11128 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/ansitowin32.py
-rwxr-xr-x 0 0 0 3325 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/initialise.py
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/
-rwxr-xr-x 0 0 0 75 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/__init__.py
-rwxr-xr-x 0 0 0 2839 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/ansi_test.py
-rwxr-xr-x 0 0 0 10678 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/ansitowin32_test.py
-rwxr-xr-x 0 0 0 6741 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/initialise_test.py
-rwxr-xr-x 0 0 0 1866 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/isatty_test.py
-rwxr-xr-x 0 0 0 1079 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/utils.py
-rwxr-xr-x 0 0 0 3709 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/winterm_test.py
-rwxr-xr-x 0 0 0 6181 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/win32.py
-rwxr-xr-x 0 0 0 7134 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/winterm.py
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/
-rwxr-xr-x 0 0 0 42 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/INSTALLER
-rwxr-xr-x 0 0 0 17158 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/METADATA
-rwxr-xr-x 0 0 0 105 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/WHEEL
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/licenses/
-rwxr-xr-x 0 0 0 1491 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/licenses/LICENSE.txt
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/bin/
-rwxr-xr-x 0 0 0 20960 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/bin/python3
Expand Down Expand Up @@ -2438,20 +2461,27 @@ drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/
-rwxr-xr-x 0 0 0 2887 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin
-rwxr-xr-x 0 0 0 16 Jan 1 2023 ./py/tests/py_image_layer/main.py
-rwxr-xr-x 0 0 0 40 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.venv.pth
-rwxr-xr-x 0 0 0 2895 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin
-rwxr-xr-x 0 0 0 204 Jan 1 2023 ./py/tests/py_image_layer/__main__.py
-rwxr-xr-x 0 0 0 183 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.venv.pth
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/adder/
-rwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/adder/__init__.py
-rwxr-xr-x 0 0 0 32 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/adder/add.py
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/
-rwxr-xr-x 0 0 0 16 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/main.py
-rwxr-xr-x 0 0 0 40 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin.venv.pth
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/branding/
-rwxr-xr-x 0 0 0 42 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/branding/__init__.py
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/
-rwxr-xr-x 0 0 0 204 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/__main__.py
-rwxr-xr-x 0 0 0 183 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin.venv.pth
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/bash/
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/bash/runfiles/
-rwxr-xr-x 0 0 0 21622 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tools/
-rwxr-xr-x 0 0 0 2887 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin
-rwxr-xr-x 0 0 0 2895 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin
12 changes: 12 additions & 0 deletions py/tests/py_image_layer/py_image_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
schemaVersion: 2.0.0

fileExistenceTests:
- name: __main__ is present
path: /py/tests/py_image_layer/__main__.py
- name: runfiles dependencies are present
path: /py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/__init__.py
commandTests:
- name: can run binary
exitCode: 0
command: /py/tests/py_image_layer/my_app_bin
expectedOutput: ["Hello rules_py - 3.14"]
Loading