Skip to content
Merged
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
26 changes: 26 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@pip//:requirements.bzl", "requirement")
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

exports_files([
"build_defs.bzl",
"LICENSE",
])

# Black formatter binary
py_binary(
name = "black_runner",
srcs = ["scripts/black_runner.py"],
deps = [requirement("black")],
)

# Fix formatting: bazel run //:black_fix -- .
sh_binary(
name = "black_fix",
srcs = ["scripts/black_fix.sh"],
data = [":black_runner"],
)

# Check formatting: bazel run //:black_check
sh_binary(
name = "black_check",
srcs = ["scripts/black_check.sh"],
data = [":black_runner"],
)
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ bazel_dep(
)
bazel_dep(name = "rules_python", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.1.0")
bazel_dep(name = "rules_shell", version = "0.3.0")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pip",
python_version = "3.11",
requirements_lock = "//:requirements.txt",
)
use_repo(pip, "pip")
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Python dependencies for Emboss development tools
# Managed by Bazel via rules_python pip.parse extension

# Black formatter and its dependencies
black==24.8.0
click>=8.0.0
mypy_extensions>=0.4.3
packaging>=22.0
pathspec>=0.9.0
platformdirs>=2
27 changes: 27 additions & 0 deletions scripts/black_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Checks Python formatting without modifying files.
# Usage: bazel run //:black_check

# Change to workspace directory
cd "${BUILD_WORKSPACE_DIRECTORY}" || exit 1

# Find the black_runner binary in runfiles
RUNFILES_DIR="${BASH_SOURCE[0]}.runfiles"
BLACK_RUNNER="${RUNFILES_DIR}/_main/black_runner"

exec "${BLACK_RUNNER}" --check --diff .
27 changes: 27 additions & 0 deletions scripts/black_fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Runs black to fix Python formatting in-place.
# Usage: bazel run //:black_fix -- .

# Change to workspace directory
cd "${BUILD_WORKSPACE_DIRECTORY}" || exit 1

# Find the black_runner binary in runfiles
RUNFILES_DIR="${BASH_SOURCE[0]}.runfiles"
BLACK_RUNNER="${RUNFILES_DIR}/_main/black_runner"

exec "${BLACK_RUNNER}" "$@"
24 changes: 24 additions & 0 deletions scripts/black_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Entry point for running black formatter via Bazel."""

import sys

import black

if __name__ == "__main__":
sys.exit(black.main())
Loading