Skip to content

Use ruff Python formatter #150

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions .github/workflows/ruff-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruff Checks

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install UV
uses: astral-sh/setup-uv@v6

- name: Set up Python
run: uv python install

- name: Install dependencies
run: uv sync --locked --dev

- name: Run Ruff
run: uv run ruff check .
35 changes: 19 additions & 16 deletions builder/build_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pathlib import Path
import argparse
import subprocess
import sys
import requests
import json
import time
Expand All @@ -21,6 +20,7 @@
SPEC_CHECKSUM_URL = "https://rust-lang.github.io/fls/paragraph-ids.json"
SPEC_LOCKFILE = "spec.lock"


def build_docs(
root: Path,
builder: str,
Expand Down Expand Up @@ -68,15 +68,15 @@ def build_docs(
# Add configuration options as needed
if not spec_lock_consistency_check:
conf_opt_values.append("enable_spec_lock_consistency=0")
if offline:
if offline:
conf_opt_values.append("offline=1")
if debug:
if debug:
conf_opt_values.append("debug=1")

# Only add the --define argument if there are options to define
if conf_opt_values:
for opt in conf_opt_values:
args.append("--define") # each option needs its own --define
args.append("--define") # each option needs its own --define
args.append(opt)

if serve:
Expand All @@ -89,7 +89,6 @@ def build_docs(
args += ["-W", "--keep-going"]

try:

# Tracking build time
timer_start = time.perf_counter()
subprocess.run(
Expand All @@ -111,24 +110,24 @@ def build_docs(
print(f"\nBuild finished in {timer_end - timer_start:.2f} seconds.")
return dest / builder

def update_spec_lockfile(spec_checksum_location, lockfile_location):

def update_spec_lockfile(spec_checksum_location, lockfile_location):
try:
response = requests.get(spec_checksum_location, stream=True)

response.raise_for_status()

with open(lockfile_location, 'wb') as file:
with open(lockfile_location, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
file.write(chunk)

with open(lockfile_location, 'r') as file:
with open(lockfile_location, "r") as file:
data = json.load(file)

print("-- read in --")

with open(lockfile_location, 'w') as outfile:
with open(lockfile_location, "w") as outfile:
json.dump(data, outfile, indent=4, sort_keys=True)

print("-- wrote back out --")
Expand All @@ -139,6 +138,7 @@ def update_spec_lockfile(spec_checksum_location, lockfile_location):
print(f"Error downloading file: {e}")
return False


def main(root):
root = Path(root)

Expand All @@ -156,12 +156,10 @@ def main(root):
"--ignore-spec-lock-diff",
help="ignore spec.lock file differences with live release -- for WIP branches only",
default=False,
action="store_true"
action="store_true",
)
parser.add_argument(
"--update-spec-lock-file",
help="update spec.lock file",
action="store_true"
"--update-spec-lock-file", help="update spec.lock file", action="store_true"
)
group.add_argument(
"-s",
Expand Down Expand Up @@ -191,7 +189,12 @@ def main(root):
if args.update_spec_lock_file:
update_spec_lockfile(SPEC_CHECKSUM_URL, root / "src" / SPEC_LOCKFILE)

rendered = build_docs(
root, "xml" if args.xml else "html", args.clear, args.serve, args.debug, args.offline, not args.ignore_spec_lock_diff,
build_docs(
root,
"xml" if args.xml else "html",
args.clear,
args.serve,
args.debug,
args.offline,
not args.ignore_spec_lock_diff,
)

75 changes: 38 additions & 37 deletions exts/coding_guidelines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# SPDX-License-Identifier: MIT OR Apache-2.0
# SPDX-FileCopyrightText: The Coding Guidelines Subcommittee Contributors

from . import fls_checks
from . import write_guidelines_ids
from . import std_role
from . import fls_linking
from . import guidelines_checks

from .common import logger, get_tqdm, bar_format, logging
from sphinx.domains import Domain

from . import (
common,
fls_checks,
fls_linking,
guidelines_checks,
std_role,
write_guidelines_ids,
)
from .common import bar_format, get_tqdm, logger, logging


class CodingGuidelinesDomain(Domain):
name = "coding-guidelines"
label = "Rust Standard Library"
Expand All @@ -19,17 +23,17 @@ class CodingGuidelinesDomain(Domain):
directives = {}
object_types = {}
indices = {}

def get_objects(self):
return []

def merge_domaindata(self, docnames, other):
pass # No domain data to merge


def on_build_finished(app, exception):
print("\nFinalizing build:")
for _ in get_tqdm(iterable=range(1), desc="Finalizing",bar_format=bar_format):
for _ in get_tqdm(iterable=range(1), desc="Finalizing", bar_format=bar_format):
pass

outdir = app.outdir
Expand All @@ -39,47 +43,44 @@ def on_build_finished(app, exception):
if not app.config.debug:
print(f" + Build complete -> {outdir}")


def setup(app):

app.add_domain(CodingGuidelinesDomain)
app.add_config_value(
name = "offline",
default=False,
rebuild= "env"
) # register the offline option
name="offline", default=False, rebuild="env"
) # register the offline option
app.add_config_value(
name="spec_std_docs_url",
default="https://doc.rust-lang.org/stable/std",
rebuild="env", # Rebuild the environment when this changes
types=[str],
)
app.add_config_value(name='debug',
default=False,
rebuild='env'
app.add_config_value(name="debug", default=False, rebuild="env")
app.add_config_value(
name="fls_paragraph_ids_url",
default="https://rust-lang.github.io/fls/paragraph-ids.json",
rebuild="env",
)
app.add_config_value(
name="enable_spec_lock_consistency", default=True, rebuild="env"
)
app.add_config_value(name='fls_paragraph_ids_url',
default='https://rust-lang.github.io/fls/paragraph-ids.json',
rebuild='env')
app.add_config_value(name='enable_spec_lock_consistency',
default=True,
rebuild='env')
app.add_config_value(
name='required_guideline_fields',
default=['release', 'fls', 'decidability', 'scope'],
rebuild='env',
name="required_guideline_fields",
default=["release", "fls", "decidability", "scope"],
rebuild="env",
types=[list],
)
if app.config.debug:
logger.setLevel(logging.INFO)
common.disable_tqdm = True
app.connect('env-check-consistency', guidelines_checks.validate_required_fields)
app.connect('env-check-consistency', fls_checks.check_fls)
app.connect('build-finished', write_guidelines_ids.build_finished)
app.connect('build-finished', fls_linking.build_finished)
app.connect('build-finished', on_build_finished)
common.disable_tqdm = True

app.connect("env-check-consistency", guidelines_checks.validate_required_fields)
app.connect("env-check-consistency", fls_checks.check_fls)
app.connect("build-finished", write_guidelines_ids.build_finished)
app.connect("build-finished", fls_linking.build_finished)
app.connect("build-finished", on_build_finished)

return {
'version': '0.1',
'parallel_read_safe': True,
"version": "0.1",
"parallel_read_safe": True,
}
15 changes: 9 additions & 6 deletions exts/coding_guidelines/common.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import logging

from tqdm import tqdm
import logging

# This is a wrapper around tqdm that allows us to disable it with this global variable
disable_tqdm = False
disable_tqdm = False


def get_tqdm(**kwargs):
kwargs['disable'] = disable_tqdm
kwargs["disable"] = disable_tqdm
return tqdm(**kwargs)


# Get the Sphinx logger
logger = logging.getLogger('sphinx')
logger.setLevel(logging.WARNING)
logger = logging.getLogger("sphinx")
logger.setLevel(logging.WARNING)

# This is what controls the progress bar format
bar_format = "{l_bar}{bar}| {n_fmt}/{total_fmt} {postfix}"

Loading
Loading