Skip to content

Commit 0173cb5

Browse files
authored
ci: Add pre-commit GitHub action (#500)
Follow up of #480 adding a pre-commit GH action, fixing last formatting, and remaining buildifier warnings (split in 3 commit) --- ### Changes are visible to end-users: no
1 parent e83fb49 commit 0173cb5

File tree

12 files changed

+55
-35
lines changed

12 files changed

+55
-35
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ jobs:
4040
{"folder": "e2e/smoke", "bazelversion": "8.0.0"}
4141
]
4242
43+
pre-commit:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- uses: pre-commit/[email protected]
48+
4349
verify-bcr-patches:
4450
runs-on: ubuntu-latest
4551
steps:
@@ -67,7 +73,7 @@ jobs:
6773
# For branch protection settings, this job provides a "stable" name that can be used to gate PR merges
6874
# on "all matrix jobs were successful".
6975
conclusion:
70-
needs: test
76+
needs: [test, pre-commit]
7177
runs-on: ubuntu-latest
7278
if: always()
7379
steps:

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module(
1212
# py_image_layer requires 2.x for the `tar` rule.
1313
# py_image_layer needs compute_unused_inputs attribute
1414
# py_image_layer needs repo_mapping fix.
15-
bazel_dep(name = "aspect_bazel_lib", version = "2.10.0")
15+
bazel_dep(name = "aspect_bazel_lib", version = "2.10.0")
1616
bazel_dep(name = "bazel_skylib", version = "1.4.2")
1717
bazel_dep(name = "rules_python", version = "0.29.0")
1818
bazel_dep(name = "platforms", version = "0.0.7")

e2e/repository-rule-deps/rules/import.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create the external repository under test."""
2+
13
load("@bazel_skylib//lib:paths.bzl", "paths")
24

35
def _myrepo_impl(repository_ctx):
@@ -22,7 +24,7 @@ myrepo = repository_rule(
2224
},
2325
)
2426

25-
def _importer_impl(module_ctx):
27+
def _importer_impl(_):
2628
myrepo(name = "myrepo", path = "imported")
2729

2830
importer = module_extension(

examples/pytest/BUILD.bazel

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ py_library(
88

99
py_pytest_main(
1010
name = "__test__",
11-
chdir = package_name(), # So that test fixtures are available at the correct path
11+
chdir = package_name(), # So that test fixtures are available at the correct path
1212
deps = [
1313
"@pypi_coverage//:pkg",
1414
"@pypi_pytest//:pkg",
@@ -21,13 +21,13 @@ py_test(
2121
"foo_test.py",
2222
":__test__",
2323
],
24+
data = glob([
25+
"fixtures/*.json",
26+
]),
2427
env_inherit = ["FOO"],
2528
imports = ["../.."],
2629
main = ":__test__.py",
2730
package_collisions = "warning",
28-
data = glob([
29-
"fixtures/*.json",
30-
]),
3131
deps = [
3232
":__test__",
3333
":lib",
@@ -43,13 +43,13 @@ py_test(
4343
"foo_test.py",
4444
":__test__",
4545
],
46+
data = glob([
47+
"fixtures/*.json",
48+
]),
4649
env_inherit = ["FOO"],
4750
imports = ["../.."],
4851
main = ":__test__.py",
4952
package_collisions = "warning",
50-
data = glob([
51-
"fixtures/*.json",
52-
]),
5353
deps = [
5454
":__test__",
5555
":lib",

examples/pytest/fixtures/hello.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"message": "Hello, world."
3-
}
3+
}

examples/virtual_deps/BUILD.bazel

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,50 @@ load("@pypi//:requirements.bzl", "requirement")
33

44
py_library(
55
name = "greet",
6-
imports = ["."],
76
srcs = ["greet.py"],
7+
imports = ["."],
88
virtual_deps = ["cowsay"],
99
)
1010

1111
# A library that *looks* like cowsay... but isn't!
1212
py_library(
1313
name = "cowsnake",
14-
imports = ["cowsnake"],
1514
srcs = ["cowsnake/cowsay.py"],
15+
imports = ["cowsnake"],
1616
virtual_deps = ["snakesay"],
1717
)
1818

1919
py_binary(
2020
name = "app",
2121
srcs = ["main.py"],
22-
resolutions = resolutions.from_requirements([
23-
"cowsay",
24-
], requirement),
22+
python_version = "3.8.12",
23+
resolutions = resolutions.from_requirements(
24+
[
25+
"cowsay",
26+
],
27+
requirement,
28+
),
2529
deps = [
2630
":greet",
2731
],
28-
python_version = "3.8.12",
2932
)
3033

3134
# Here we swap out the cowsay module for our own implementation
3235
py_binary(
3336
name = "app_snake",
3437
srcs = ["main.py"],
38+
python_version = "3.8.12",
39+
resolutions = resolutions.from_requirements(
40+
[
41+
"snakesay",
42+
],
43+
requirement,
44+
).override({
45+
"cowsay": ":cowsnake",
46+
}),
3547
deps = [
3648
":greet",
3749
],
38-
resolutions = resolutions.from_requirements([
39-
"snakesay",
40-
], requirement).override({
41-
"cowsay": ":cowsnake",
42-
}),
43-
python_version = "3.8.12",
4450
)
4551

4652
py_pytest_main(
@@ -55,9 +61,12 @@ py_test(
5561
],
5662
main = ":__test__.py",
5763
package_collisions = "error",
58-
resolutions = resolutions.from_requirements([
59-
"cowsay",
60-
], requirement),
64+
resolutions = resolutions.from_requirements(
65+
[
66+
"cowsay",
67+
],
68+
requirement,
69+
),
6170
deps = [
6271
requirement("pytest"),
6372
":greet",

examples/virtual_deps/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The example shows how to use `virtual_deps` feature.
44

5-
- `greet` is a library that has a virtual dependency on `cowsay`
6-
- `cowsnake` is a library that implements some of the `cowsay` API
7-
- `app` is a binary that uses `greet` and resolves the `cowsay` virtual dependency
8-
- `app_snake` is like `app`, but swaps out `cowsay` for `cowsnake`!
9-
- `pytest_test` tests `greet` using a resolved `cowsay`
5+
- `greet` is a library that has a virtual dependency on `cowsay`
6+
- `cowsnake` is a library that implements some of the `cowsay` API
7+
- `app` is a binary that uses `greet` and resolves the `cowsay` virtual dependency
8+
- `app_snake` is like `app`, but swaps out `cowsay` for `cowsnake`!
9+
- `pytest_test` tests `greet` using a resolved `cowsay`

py/private/toolchain/autodetecting.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# buildifier: disable=module-docstring
1+
"""Autodetecting Python toolchain"""
22

33
def _autodetecting_py_wrapper_impl(rctx):
44
which_python = rctx.which("python3")

py/private/toolchain/tools.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ package(default_visibility = ["//visibility:public"])
120120
if "RULES_PY_RELEASE_VERSION" in rctx.os.environ:
121121
release_version = rctx.os.environ["RULES_PY_RELEASE_VERSION"]
122122

123-
for tool, cfg in RUST_BIN_CFG.items():
123+
for tool in RUST_BIN_CFG.keys():
124124
filename = "-".join([
125125
tool,
126126
TOOLCHAIN_PLATFORMS[rctx.attr.platform].arch,

py/private/virtual.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _make_resolution(name, requirement):
6262

6363
def _from_requirements(base, requirement_fn = lambda r: r):
6464
if type(base) == "list":
65-
base = { k: None for k in base }
65+
base = {k: None for k in base}
6666
return _make_resolutions(base, requirement_fn)
6767

6868
resolutions = struct(

0 commit comments

Comments
 (0)