Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def get_pr_checks(pr_number):
stderr=subprocess.DEVNULL,
)
except FileNotFoundError:
print(
"Error: 'gh' (GitHub CLI) is not installed or not in PATH.", file=sys.stderr
)
print("Error: 'gh' (GitHub CLI) is not installed or not in PATH.", file=sys.stderr)
sys.exit(1)
except subprocess.CalledProcessError:
print("Error: 'gh' command failed. Is it installed?", file=sys.stderr)
Expand Down Expand Up @@ -165,15 +163,18 @@ def main():

build_state = data.get("state", "Unknown")
print(f"Build State: {build_state}")

jobs = data.get("jobs", [])
jobs_count = data.get("statistics", {}).get("jobs_count", 0)

print(f"Total jobs reported: {jobs_count}")
print(f"Jobs found in data: {len(jobs)}")

if jobs_count != len(jobs):
print(f"WARNING: Reported job count ({jobs_count}) does not match jobs found ({len(jobs)}).", file=sys.stderr)
print(
f"WARNING: Reported job count ({jobs_count}) does not match jobs found ({len(jobs)}).",
file=sys.stderr,
)

print("-" * 40)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def make_request(url, method="GET", data=None, token=None):


def main():
parser = argparse.ArgumentParser(
description="Retry failed jobs in a Buildkite build."
)
parser = argparse.ArgumentParser(description="Retry failed jobs in a Buildkite build.")
parser.add_argument("org", help="Organization slug")
parser.add_argument("pipeline", help="Pipeline slug")
parser.add_argument("build", help="Build number")
Expand All @@ -46,9 +44,7 @@ def main():
token = os.environ.get("BUILDKITE_API_TOKEN")

if not token:
print(
"Please set the BUILDKITE_API_TOKEN environment variable.", file=sys.stderr
)
print("Please set the BUILDKITE_API_TOKEN environment variable.", file=sys.stderr)
sys.exit(1)

url = f"https://api.buildkite.com/v2/organizations/{args.org}/pipelines/{args.pipeline}/builds/{args.build}"
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ruff

on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize

defaults:
run:
shell: bash

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install ruff
run: pip install ruff==0.15.13
- name: Run ruff check
run: ruff check --output-format=github
- name: Run ruff format check
run: ruff format --check

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Comment on lines +18 to +26
18 changes: 7 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ repos:
- --warnings=all
- id: buildifier-lint
args: *args
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.13
Comment thread
dougthor42 marked this conversation as resolved.
hooks:
- id: isort
name: isort (python)
args:
- --profile
- black
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: ^(gazelle/python/testdata|tests/pypi/whl_library/testdata)
- id: ruff-format
exclude: ^(gazelle/python/testdata|tests/pypi/whl_library/testdata)
- repo: local
hooks:
- id: update-deleted-packages
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ If you did `pre-commit install`, various tools are run when you do `git commit`.
This might show as an error such as:

```
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ...
```

To fix, you'll need to figure out what command is failing and why. Because these
are tools that run locally, its likely you'll need to fix something with your
environment or the installation of the tools. For Python tools (e.g. black or
isort), you can try using a different Python version in your shell by using
tools such as [pyenv](https://github.com/pyenv/pyenv).
environment or the installation of the tools. For Python tools (e.g. ruff), you
can try using a different Python version in your shell by using tools such as
[pyenv](https://github.com/pyenv/pyenv).
46 changes: 23 additions & 23 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@
"api/python/defs": "/api/rules_python/python/defs.html",
"api/python/index": "/api/rules_python/python/index.html",
"api/python/py_runtime_info": "/api/rules_python/python/py_runtime_info.html",
"api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/py_library_rule.html",
"api/python/private/common/py_test_rule_bazel": "/api/rules_python/python/private/py_test_rule_bazel.html",
"api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/py_binary_rule.html",
"api/python/private/common/py_runtime_rule": "/api/rules_python/python/private/py_runtime_rule.html",
"api/python/extensions/pip": "/api/rules_python/python/extensions/pip.html",
"api/python/extensions/python": "/api/rules_python/python/extensions/python.html",
"api/python/entry_points/py_console_script_binary": "/api/rules_python/python/entry_points/py_console_script_binary.html",
"api/python/cc/py_cc_toolchain_info": "/api/rules_python/python/cc/py_cc_toolchain_info.html",
"api/python/cc/index": "/api/rules_python/python/cc/index.html",
"api/python/py_cc_link_params_info": "/api/rules_python/python/py_cc_link_params_info.html",
"api/python/runtime_env_toolchains/index": "/api/rules_python/python/runtime_env_toolchains/index.html",
"api/python/pip": "/api/rules_python/python/pip.html",
"api/python/config_settings/index": "/api/rules_python/python/config_settings/index.html",
"api/python/packaging": "/api/rules_python/python/packaging.html",
"api/python/py_runtime": "/api/rules_python/python/py_runtime.html",
"api/sphinxdocs/sphinx": "/api/sphinxdocs/sphinxdocs/sphinx.html",
"api/sphinxdocs/sphinx_stardoc": "/api/sphinxdocs/sphinxdocs/sphinx_stardoc.html",
"api/sphinxdocs/readthedocs": "/api/sphinxdocs/sphinxdocs/readthedocs.html",
"api/sphinxdocs/index": "sphinxdocs/index.html",
"api/sphinxdocs/private/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/private/sphinx_docs_library.html",
"api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/py_library_rule.html", # noqa: E501
"api/python/private/common/py_test_rule_bazel": "/api/rules_python/python/private/py_test_rule_bazel.html", # noqa: E501
"api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/py_binary_rule.html", # noqa: E501
"api/python/private/common/py_runtime_rule": "/api/rules_python/python/private/py_runtime_rule.html", # noqa: E501
"api/python/extensions/pip": "/api/rules_python/python/extensions/pip.html", # noqa: E501
"api/python/extensions/python": "/api/rules_python/python/extensions/python.html", # noqa: E501
"api/python/entry_points/py_console_script_binary": "/api/rules_python/python/entry_points/py_console_script_binary.html", # noqa: E501
"api/python/cc/py_cc_toolchain_info": "/api/rules_python/python/cc/py_cc_toolchain_info.html", # noqa: E501
"api/python/cc/index": "/api/rules_python/python/cc/index.html", # noqa: E501
"api/python/py_cc_link_params_info": "/api/rules_python/python/py_cc_link_params_info.html", # noqa: E501
"api/python/runtime_env_toolchains/index": "/api/rules_python/python/runtime_env_toolchains/index.html", # noqa: E501
"api/python/pip": "/api/rules_python/python/pip.html", # noqa: E501
"api/python/config_settings/index": "/api/rules_python/python/config_settings/index.html", # noqa: E501
"api/python/packaging": "/api/rules_python/python/packaging.html", # noqa: E501
"api/python/py_runtime": "/api/rules_python/python/py_runtime.html", # noqa: E501
"api/sphinxdocs/sphinx": "/api/sphinxdocs/sphinxdocs/sphinx.html", # noqa: E501
"api/sphinxdocs/sphinx_stardoc": "/api/sphinxdocs/sphinxdocs/sphinx_stardoc.html", # noqa: E501
"api/sphinxdocs/readthedocs": "/api/sphinxdocs/sphinxdocs/readthedocs.html", # noqa: E501
"api/sphinxdocs/index": "sphinxdocs/index.html", # noqa: E501
"api/sphinxdocs/private/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/private/sphinx_docs_library.html", # noqa: E501
"api/sphinxdocs/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/sphinx_docs_library.html",
"api/sphinxdocs/inventories/index": "/api/sphinxdocs/sphinxdocs/inventories/index.html",
"pip.html": "pypi/index.html",
Expand Down Expand Up @@ -133,11 +133,11 @@
# --- Extlinks configuration
extlinks = {
"gh-issue": (
f"https://github.com/bazel-contrib/rules_python/issues/%s",
"https://github.com/bazel-contrib/rules_python/issues/%s",
"#%s issue",
),
"gh-path": (f"https://github.com/bazel-contrib/rules_python/tree/main/%s", "%s"),
"gh-pr": (f"https://github.com/bazel-contrib/rules_python/pull/%s", "#%s PR"),
"gh-path": ("https://github.com/bazel-contrib/rules_python/tree/main/%s", "%s"),
"gh-pr": ("https://github.com/bazel-contrib/rules_python/pull/%s", "#%s PR"),
}

# --- MyST configuration
Expand Down
21 changes: 10 additions & 11 deletions examples/bzlmod/entry_points/tests/pylint_deps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os
import pathlib
import subprocess
import tempfile
import unittest

from python.runfiles import runfiles
Expand All @@ -29,17 +28,17 @@ def __init__(self, *args, **kwargs):

def test_pylint_entry_point(self):
rlocation_path = os.environ.get("ENTRY_POINT")
assert (
rlocation_path is not None
), "expected 'ENTRY_POINT' env variable to be set to rlocation of the tool"
assert rlocation_path is not None, (
"expected 'ENTRY_POINT' env variable to be set to rlocation of the tool"
)

entry_point = pathlib.Path(runfiles.Create().Rlocation(rlocation_path))
self.assertTrue(entry_point.exists(), f"'{entry_point}' does not exist")

# Let's run the entrypoint and check the tool version.
#
# NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start
# passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the
# NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start # noqa: E501
# passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the # noqa: E501
# entry_point cannot be found. However, just calling `--version` seems to be fine.
proc = subprocess.run(
[str(entry_point), "--version"],
Expand All @@ -51,20 +50,20 @@ def test_pylint_entry_point(self):
"",
proc.stderr.decode("utf-8").strip(),
)
self.assertRegex(proc.stdout.decode("utf-8").strip(), "^pylint 2\.15\.9")
self.assertRegex(proc.stdout.decode("utf-8").strip(), r"^pylint 2\.15\.9")

def test_pylint_report_has_expected_warnings(self):
rlocation_path = os.environ.get("PYLINT_REPORT")
assert (
rlocation_path is not None
), "expected 'PYLINT_REPORT' env variable to be set to rlocation of the report"
assert rlocation_path is not None, (
"expected 'PYLINT_REPORT' env variable to be set to rlocation of the report"
)

pylint_report = pathlib.Path(runfiles.Create().Rlocation(rlocation_path))
self.assertTrue(pylint_report.exists(), f"'{pylint_report}' does not exist")

self.assertRegex(
pylint_report.read_text().strip(),
"W8201: Logging should be used instead of the print\(\) function\. \(print-function\)",
r"W8201: Logging should be used instead of the print\(\) function\. \(print-function\)",
)


Expand Down
12 changes: 6 additions & 6 deletions examples/bzlmod/entry_points/tests/pylint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def __init__(self, *args, **kwargs):

def test_pylint_entry_point(self):
rlocation_path = os.environ.get("ENTRY_POINT")
assert (
rlocation_path is not None
), "expected 'ENTRY_POINT' env variable to be set to rlocation of the tool"
assert rlocation_path is not None, (
"expected 'ENTRY_POINT' env variable to be set to rlocation of the tool"
)

entry_point = pathlib.Path(runfiles.Create().Rlocation(rlocation_path))
self.assertTrue(entry_point.exists(), f"'{entry_point}' does not exist")

# Let's run the entrypoint and check the tool version.
#
# NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start
# passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the
# NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start # noqa: E501
# passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the # noqa: E501
# entry_point cannot be found. However, just calling `--version` seems to be fine.
proc = subprocess.run(
[str(entry_point), "--version"],
Expand All @@ -50,7 +50,7 @@ def test_pylint_entry_point(self):
"",
proc.stderr.decode("utf-8").strip(),
)
self.assertRegex(proc.stdout.decode("utf-8").strip(), "^pylint 2\.15\.9")
self.assertRegex(proc.stdout.decode("utf-8").strip(), r"^pylint 2\.15\.9")


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions examples/bzlmod/entry_points/tests/yamllint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def __init__(self, *args, **kwargs):

def test_yamllint_entry_point(self):
rlocation_path = os.environ.get("ENTRY_POINT")
assert (
rlocation_path is not None
), "expected 'ENTRY_POINT' env variable to be set to rlocation of the tool"
assert rlocation_path is not None, (
"expected 'ENTRY_POINT' env variable to be set to rlocation of the tool"
)

entry_point = pathlib.Path(runfiles.Create().Rlocation(rlocation_path))
self.assertTrue(entry_point.exists(), f"'{entry_point}' does not exist")

# Let's run the entrypoint and check the tool version.
#
# NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start
# passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the
# NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start # noqa: E501
# passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the # noqa: E501
# entry_point cannot be found. However, just calling `--version` seems to be fine.
proc = subprocess.run(
[str(entry_point), "--version"],
Expand Down
4 changes: 1 addition & 3 deletions examples/bzlmod/runfiles/runfiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def testRunfileWithRlocationpath(self):
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")

def testRunfileInOtherModuleWithOurRepoMapping(self):
data_path = runfiles.Create().Rlocation(
"our_other_module/other_module/pkg/data/data.txt"
)
data_path = runfiles.Create().Rlocation("our_other_module/other_module/pkg/data/data.txt")
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

Expand Down
3 changes: 1 addition & 2 deletions examples/bzlmod/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import os
import pathlib
import re
import sys
import unittest
Expand Down Expand Up @@ -59,7 +58,7 @@ def test_coverage_sys_path(self):
f"sys.path has {len(sys.path)} items:\n {all_paths}",
)

first_item, last_item = sys.path[0], sys.path[-1]
first_item, _ = sys.path[0], sys.path[-1]
self.assertFalse(
first_item.endswith("coverage"),
f"Expected the first item in sys.path '{first_item}' to not be related to coverage",
Expand Down
6 changes: 5 additions & 1 deletion examples/bzlmod/tests/cross_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

if subprocess_current != subprocess_expected:
print(
f"expected subprocess version '{subprocess_expected}' is different than returned '{subprocess_current}'"
(
"expected subprocess version"
f" '{subprocess_expected}'"
f" is different than returned '{subprocess_current}'"
)
)
sys.exit(1)

Expand Down
1 change: 0 additions & 1 deletion examples/bzlmod/tests/my_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

import libs.my_lib as my_lib
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Regression test for https://github.com/bazel-contrib/rules_python/issues/3563"""

import os
import subprocess
import sys


def main():
# The rlocation path for the bin_zipapp. It is in the "our_other_module" repository.
zipapp_path = os.environ.get("ZIPAPP_PATH")
Expand All @@ -18,5 +20,6 @@ def main():
print(f"bin_zippapp failed with return code {result.returncode}")
sys.exit(result.returncode)


if __name__ == "__main__":
main()
8 changes: 2 additions & 6 deletions examples/bzlmod/whl_mods/pip_whl_mods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def test_copy_files(self):
self.assertEqual(content, "Hello world from copied file")

def test_copy_executables(self):
executable_name = (
"executable.exe" if platform.system() == "windows" else "executable.py"
)
executable_name = "executable.exe" if platform.system() == "windows" else "executable.py"

r = runfiles.Create()
rpath = r.Rlocation(
Expand Down Expand Up @@ -111,9 +109,7 @@ def test_data_exclude_glob(self):
wheel_path = r.Rlocation("{}/WHEEL".format(dist_info_dir))

self.assertTrue(Path(metadata_path).exists(), f"Could not find {metadata_path}")
self.assertFalse(
Path(wheel_path).exists(), f"Expected to not find {wheel_path}"
)
self.assertFalse(Path(wheel_path).exists(), f"Expected to not find {wheel_path}")

def test_extra(self):
# This test verifies that annotations work correctly for pip packages with extras
Expand Down
Loading