Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/pre-commit
1 result
Show changes
Commits on Source (9)
include:
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/ruleset@v1.2.1"
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/ruleset@v1.5.0"
inputs:
oses:
- linux
......
## [1.0.7](https://git.gitlab.arm.com/bazel/pre-commit/compare/v1.0.6...v1.0.7) (2025-06-03)
### Bug Fixes
- correct temporary output move when using YAML `SafeDumper` ([ba670a0](https://git.gitlab.arm.com/bazel/pre-commit/commit/ba670a0709a4160595e9d496081692aac0927194))
- pip cross platform build ([b4fecbe](https://git.gitlab.arm.com/bazel/pre-commit/commit/b4fecbec073a75779638e089650a03ed074ecc15))
- redundant print ([c79de8d](https://git.gitlab.arm.com/bazel/pre-commit/commit/c79de8d8edfed62afc9437d8bf6363495a94501c))
## [1.0.6](https://git.gitlab.arm.com/bazel/pre-commit/compare/v1.0.5...v1.0.6) (2025-05-12)
### Bug Fixes
......
module(
name = "pre-commit",
version = "1.0.6",
version = "1.0.7",
compatibility_level = 1,
)
......@@ -34,6 +34,7 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
[
(
pip.parse(
experimental_index_url = "https://pypi.org/simple",
hub_name = "pre-commit-{}".format(version),
python_version = version,
requirements_lock = "//pre-commit/requirements:lock.txt",
......@@ -47,6 +48,7 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
},
),
pip.parse(
experimental_index_url = "https://pypi.org/simple",
hub_name = "pre-commit-config-{}".format(version),
python_version = version,
requirements_lock = "//pre-commit/config/requirements:lock.txt",
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -27,26 +27,37 @@ repos:
entry: bazel run --config=pre-commit -- //pre-commit/hook/buildifier:lint
types_or:
- bazel
- id: //pre-commit/hook/check-newline-at-end-of-file
name: Validate newline at the end of text files
description: Uses Python `mmap` function to efficiently load the last character
of the file and validate it is an end-of-line character (\r|\n)
- id: //pre-commit/hook/ruff:check
name: Check Python files with `ruff`
description: Performs checks with `ruff` against Python files. Will read a `ruff.toml`
for configuration.
language: system
require_serial: true
stages:
- pre-commit
entry: bazel run --config=pre-commit -- //pre-commit/hook/check-newline-at-end-of-file
- id: //pre-commit/hook/ruff
name: Check Python files with `ruff`
description: Performs checks with `ruff` against Python files. Will read a `ruff.toml`
for configuration.
entry: bazel run --config=pre-commit -- //pre-commit/hook/ruff:check
types:
- python
- id: //pre-commit/hook/ruff:format
name: Format Python files with `ruff`
description: Performs formatting with `ruff` against Python files. Will read a
`ruff.toml` for configuration.
language: system
require_serial: true
stages:
- pre-commit
entry: bazel run --config=pre-commit -- //pre-commit/hook/ruff
entry: bazel run --config=pre-commit -- //pre-commit/hook/ruff:format
types:
- python
- id: //pre-commit/hook/check-newline-at-end-of-file
name: Validate newline at the end of text files
description: Uses Python `mmap` function to efficiently load the last character
of the file and validate it is an end-of-line character (\r|\n)
language: system
require_serial: true
stages:
- pre-commit
entry: bazel run --config=pre-commit -- //pre-commit/hook/check-newline-at-end-of-file
- id: //hooks:config
name: Update `pre-commit` config
description: Keeps the `.pre-commit-config.yaml` in sync with any changes to the
......
......@@ -144,55 +144,35 @@ def SupportsFlushClose(Protocol):
def close(self) -> None: ...
class Closer:
class TemporaryRedirectFile:
def __init__(
self,
src: PurePath,
dst: PurePath,
file: SupportsFlushClose,
activate: bool = True,
path: PurePath,
mode: Literal["w"] = "w",
encoding: Literal["utf-8"] = "utf-8",
):
self.__src = src
self.__dst = dst
self.__file = file
self.__path = path
self.__tmp = NamedTemporaryFile(mode=mode, encoding=encoding)
self.__closing = False
self.activate = activate
def close(self) -> None:
if not self.activate:
return
if self.__closing:
return
self.__closing = True
self.__file.flush()
copy(self.__src, self.__dst)
self.__file.close()
self.__tmp.flush()
copy(self.__tmp.name, self.__path)
self.__tmp.close()
def __del__(self):
self.close()
class Output(SupportsWriteFlush[str]):
def __init__(
self,
path: PurePath,
mode: Literal["w"] = "w",
encoding: Literal["utf-8"] = "utf-8",
):
self.__tmp = NamedTemporaryFile(mode=mode, encoding=encoding)
self.__closer = Closer(
dst=path, src=PurePath(self.__tmp.name), file=self.__tmp, activate=False
)
def flush(self) -> None:
return self.__tmp.flush()
def write(self, data: AnyStrContravariant, /) -> int:
self.__closer.activate = True
return self.__tmp.write(data)
def flush(self) -> None:
return self.__tmp.flush()
def __del__(self):
self.close()
def output(value: str) -> SupportsWriteFlush[str]:
......@@ -208,7 +188,7 @@ def output(value: str) -> SupportsWriteFlush[str]:
if not Path(bsd).joinpath(".git").is_dir():
raise ArgumentTypeError("current workspace is not the repository root")
return Output(path, "w", encoding="utf-8")
return TemporaryRedirectFile(path, "w", encoding="utf-8")
def hook(value: str) -> Hook:
......@@ -229,7 +209,7 @@ def arguments(prsr: ArgumentParser) -> None:
"--comment",
help="A command that can be ran to regenerate the configuration file.",
default="This file is generated with Bazel `@pre-commit` module. Do not edit.",
),
)
prsr.add_argument(
"--input",
help="An input file to be copied to the output file..",
......
......@@ -175,7 +175,6 @@ def representer(dumper: Dumper, data: Hook) -> Node:
}
if data.pass_filenames is not None:
print(data.pass_filenames)
map["pass_filenames"] = data.pass_filenames
if data.args is not None:
......
load("@pre-commit//pre-commit/hook:defs.bzl", "pre_commit_hook")
load("@pre-commit//pre-commit/hooks:defs.bzl", "pre_commit_hooks")
load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target")
alias(
......@@ -22,15 +23,40 @@ toolchain_symlink_target(
)
pre_commit_hook(
name = "ruff",
name = "check",
src = ":cli",
args = [
"check",
"--cache-dir=.cache/ruff",
"--fix",
],
description = "Performs checks with `ruff` against Python files. Will read a `ruff.toml` for configuration.",
stages = ["@pre-commit//pre-commit/stage:pre-commit"],
summary = "Check Python files with `ruff`",
types = ["@pre-commit//pre-commit/tag:python"],
visibility = ["//visibility:public"],
)
pre_commit_hook(
name = "format",
src = ":cli",
args = [
"format",
"--cache-dir=.cache/ruff",
],
description = "Performs formatting with `ruff` against Python files. Will read a `ruff.toml` for configuration.",
stages = ["@pre-commit//pre-commit/stage:pre-commit"],
summary = "Format Python files with `ruff`",
types = ["@pre-commit//pre-commit/tag:python"],
visibility = ["//visibility:public"],
)
pre_commit_hooks(
name = "ruff",
srcs = [
# do not sort
":check",
":format",
],
visibility = ["//:__subpackages__"],
)