mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-25 09:28:14 +00:00
Merge 9ab5e06bcc into dc64c08633
This commit is contained in:
commit
135063f89e
3 changed files with 126 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -227,3 +227,5 @@ cython_debug/
|
|||
!crates/ruff_python_resolver/resources/test/airflow/venv/lib
|
||||
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/_watchdog_fsevents.cpython-311-darwin.so
|
||||
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/orjson/orjson.cpython-311-darwin.so
|
||||
|
||||
clones
|
||||
67
scripts/pgo.py
Normal file
67
scripts/pgo.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
"""
|
||||
Creates Profile-Guided-Optimized binaries for ruff.
|
||||
Ensure `cargo-pgo` is installed and configured to run this code.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
PROJECTS_JSON = "./scripts/pgo_profile.json"
|
||||
CLONE_DIR = Path("clones")
|
||||
TRIPLE = "x86_64-unknown-linux-gnu"
|
||||
|
||||
env = os.environ.copy()
|
||||
env["LLVM_PROFILE_FILE"] = f"{os.getcwd()}/target/pgo-profiles/ruff_%m_%p.profraw"
|
||||
|
||||
|
||||
def run_command(cmd, env, cwd=None, check=False):
|
||||
print(f">>> {cmd}")
|
||||
subprocess.run(
|
||||
cmd,
|
||||
shell=True,
|
||||
check=check,
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
CLONE_DIR.mkdir(exist_ok=True)
|
||||
|
||||
with open(PROJECTS_JSON, "r") as f:
|
||||
projects = json.load(f)
|
||||
|
||||
run_command("cargo pgo clean", env=env)
|
||||
run_command("cargo pgo instrument build --keep-profiles -- -q", env=env)
|
||||
|
||||
for project in projects:
|
||||
name = project["name"]
|
||||
url = project["url"]
|
||||
branch = project["branch"]
|
||||
dest = CLONE_DIR / name
|
||||
|
||||
print(f">> collecting data on {name}.")
|
||||
|
||||
if not dest.exists():
|
||||
run_command(
|
||||
f"git clone --depth 1 --quiet --branch {branch} {url} {dest}", env=env
|
||||
)
|
||||
|
||||
run_command(
|
||||
f"../../target/{TRIPLE}/release/ruff check -n -e --diff .",
|
||||
env=env,
|
||||
cwd=dest,
|
||||
)
|
||||
run_command(
|
||||
f"../../target/{TRIPLE}/release/ruff format -n --check .", env=env, cwd=dest
|
||||
)
|
||||
|
||||
run_command("cargo pgo optimize", env=env)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
57
scripts/pgo_profile.json
Normal file
57
scripts/pgo_profile.json
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
[
|
||||
{
|
||||
"name": "mypy",
|
||||
"url": "https://github.com/python/mypy.git",
|
||||
"branch": "master"
|
||||
},
|
||||
{
|
||||
"name": "pandas",
|
||||
"url": "https://github.com/pandas-dev/pandas.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "django",
|
||||
"url": "https://github.com/django/django.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "openstack",
|
||||
"url": "https://opendev.org/openstack/nova.git",
|
||||
"branch": "master"
|
||||
},
|
||||
{
|
||||
"name": "polars",
|
||||
"url": "https://github.com/pola-rs/polars.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "pytorch",
|
||||
"url": "https://github.com/pytorch/pytorch.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "cpython",
|
||||
"url": "https://github.com/python/cpython.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "zulip",
|
||||
"url": "https://github.com/zulip/zulip.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "matplotlib",
|
||||
"url": "https://github.com/matplotlib/matplotlib.git",
|
||||
"branch": "main"
|
||||
},
|
||||
{
|
||||
"name": "core",
|
||||
"url": "https://github.com/home-assistant/core.git",
|
||||
"branch": "master"
|
||||
},
|
||||
{
|
||||
"name": "fastapi",
|
||||
"url": "https://github.com/fastapi/fastapi.git",
|
||||
"branch": "master"
|
||||
}
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue