Skip to content
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

chore: fix ruff mirroring #306

Merged
merged 2 commits into from
Jul 2, 2024
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
5 changes: 3 additions & 2 deletions docs/ruff.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ bzl_library(
deps = _BAZEL_TOOLS + [
":ruff_versions",
"//lint/private:lint_aspect",
"@bazel_skylib//lib:versions",
],
)

Expand Down
2 changes: 1 addition & 1 deletion lint/mirror_ruff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JQ_FILTER=\
"value": .assets
| map(select((.name | contains("ruff-")) and (.name | contains("sha256") | not) ))
| map({
"key": .name | capture("ruff-[0-9\\.]+-(?<platform>.*)\\.(tar\\.gz|zip)") | .platform,
"key": .name | capture("ruff-(?<platform>.*)\\.(tar\\.gz|zip)") | .platform,
"value": (.browser_download_url + ".sha256"),
})
| from_entries
Expand Down
16 changes: 13 additions & 3 deletions lint/ruff.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ruff = ruff_aspect(
```
"""

load("@bazel_skylib//lib:versions.bzl", "versions")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//lint/private:lint_aspect.bzl", "LintOptionsInfo", "dummy_successful_lint_action", "filter_srcs", "patch_and_report_files", "report_files")
Expand Down Expand Up @@ -175,7 +176,10 @@ def _ruff_workaround_20269_impl(rctx):
# To workaround, we fetch the file and then use the BSD tar on the system to extract it.
# TODO: remove for users on Bazel 8 (or maybe sooner if that fix is cherry-picked)
rctx.download(sha256 = rctx.attr.sha256, url = rctx.attr.url, output = "ruff.tar.gz")
result = rctx.execute([rctx.which("tar"), "xzf", "ruff.tar.gz"])
tar_cmd = [rctx.which("tar"), "xzf", "ruff.tar.gz"]
if rctx.attr.strip_prefix:
tar_cmd.append("--strip-components=1")
result = rctx.execute(tar_cmd)
if result.return_code:
fail("Couldn't extract ruff: \nSTDOUT:\n{}\nSTDERR:\n{}".format(result.stdout, result.stderr))
rctx.file("BUILD", rctx.attr.build_file_content)
Expand All @@ -186,6 +190,7 @@ ruff_workaround_20269 = repository_rule(
attrs = {
"build_file_content": attr.string(),
"sha256": attr.string(),
"strip_prefix": attr.string(doc = "unlike http_archive, any value causes us to pass --strip-components=1 to tar"),
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
"url": attr.string(),
},
)
Expand All @@ -199,11 +204,15 @@ def fetch_ruff(tag = RUFF_VERSIONS.keys()[0]):
version = tag.lstrip("v")

# ruff changed their release artifact naming starting with v0.1.8, so that's the minimum version we support
url = "https://github.com/astral-sh/ruff/releases/download/{tag}/ruff-{version}-{plat}.{ext}"
# they changed it again in 0.5.0, removing the version from the filename.
if versions.is_at_least("0.5.0", version):
url = "https://github.com/astral-sh/ruff/releases/download/{tag}/ruff-{plat}.{ext}"
else:
url = "https://github.com/astral-sh/ruff/releases/download/{tag}/ruff-{version}-{plat}.{ext}"

for plat, sha256 in RUFF_VERSIONS[tag].items():
fetch_rule = http_archive
if plat.endswith("darwin"):
if plat.endswith("darwin") and not versions.is_at_least("7.2.0", versions.get()):
fetch_rule = ruff_workaround_20269
is_windows = plat.endswith("windows-msvc")

Expand All @@ -216,6 +225,7 @@ def fetch_ruff(tag = RUFF_VERSIONS.keys()[0]):
version = version,
ext = "zip" if is_windows else "tar.gz",
),
strip_prefix = "ruff-" + plat if versions.is_at_least("0.5.0", version) else None,
sha256 = sha256,
build_file_content = """exports_files(["ruff", "ruff.exe"])""",
)
19 changes: 19 additions & 0 deletions lint/ruff_versions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
"This file is automatically updated by mirror_ruff.sh"
RUFF_VERSIONS = {
"0.5.0": {
"aarch64-apple-darwin": "a9203ee067703ef9589cae0d78e3def76e855650d721f77057a3b60638302b36",
"aarch64-pc-windows-msvc": "bb1fc1540ac591b0f0405c472291a98697ccbd4c31f7d2af371943008a890ec4",
"aarch64-unknown-linux-gnu": "6348b52aa618cb24bebab733da923ac4289cd04bbf32e6557b3b0f75ecf2e885",
"aarch64-unknown-linux-musl": "bc47a3ecff865b38385774fd6191347ecebc201b3a5c0fb56b6e75bc67757ff0",
"arm-unknown-linux-musleabihf": "c1490b68ead60c44c870fb944e2099e7f01446b3327fb8b16e5ae079b83b3029",
"armv7-unknown-linux-gnueabihf": "741ea90fa58471c84be92e75d97e13510722adabfc5160838f228fca444b0b97",
"armv7-unknown-linux-musleabihf": "d39bda906724f0c9b9c07055a37b0fbf156a637a2b42967578c8f6c7e655d460",
"i686-pc-windows-msvc": "757430f6bac31b8d4ec08a6ca600cd4afb0dda0a2e78cb48054380895e70b8de",
"i686-unknown-linux-gnu": "57863fad533914bb0a90e3ea29d861d5665c8b44cb5e97c79713b1139b1f7d7b",
"i686-unknown-linux-musl": "bb28233b18db28b4e65c387c3a4ba195c44425154f8d1f900b1599005531be3a",
"powerpc64-unknown-linux-gnu": "97d19ada60f37763437c41d8bd3b47a1d560841634abecd435438b89bce978a6",
"powerpc64le-unknown-linux-gnu": "b9c0d1465a494db8babcafe1a4f31046d3af26b83ded6693d7c60fd0bc6ae806",
"s390x-unknown-linux-gnu": "552efa4f0577622fb377f54c8dfd49adf9be316f59c199b60cda38ea2725ef89",
"x86_64-apple-darwin": "283a2d23af7d3b05173e34aade53c4d04694e44ca240b61e5b95c887a379eaf1",
"x86_64-pc-windows-msvc": "3c5305938a44803ea5b2aafe896c1edbbd721d648a768dbd061bc66a18caee98",
"x86_64-unknown-linux-gnu": "f8a054683586cb3edc3ba072d4916d7c3962910b0d46bc6d4e70b4894d70f6cc",
"x86_64-unknown-linux-musl": "32f4dce258b73f350dd4aab46e7ab54ff74ffb31f3ab2c46e7168f2afd624c78",
},
"v0.4.10": {
"aarch64-apple-darwin": "5a4ff81270eee1efa7901566719aca705a3e8d0f1abead96c01caa4678a7762e",
"aarch64-pc-windows-msvc": "6b526e4da0d45589dc1247615e418d5e82490e25f8234b45551b2737f14ca5a1",
Expand Down
Loading