Skip to content

Commit afadf76

Browse files
committed
initial ruff config, format
1 parent 303fa89 commit afadf76

File tree

11 files changed

+556
-398
lines changed

11 files changed

+556
-398
lines changed

builder/build_cli.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pathlib import Path
1111
import argparse
1212
import subprocess
13-
import sys
1413
import requests
1514
import json
1615
import time
@@ -21,6 +20,7 @@
2120
SPEC_CHECKSUM_URL = "https://rust-lang.github.io/fls/paragraph-ids.json"
2221
SPEC_LOCKFILE = "spec.lock"
2322

23+
2424
def build_docs(
2525
root: Path,
2626
builder: str,
@@ -68,15 +68,15 @@ def build_docs(
6868
# Add configuration options as needed
6969
if not spec_lock_consistency_check:
7070
conf_opt_values.append("enable_spec_lock_consistency=0")
71-
if offline:
71+
if offline:
7272
conf_opt_values.append("offline=1")
73-
if debug:
73+
if debug:
7474
conf_opt_values.append("debug=1")
7575

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

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

9191
try:
92-
9392
# Tracking build time
9493
timer_start = time.perf_counter()
9594
subprocess.run(
@@ -111,24 +110,24 @@ def build_docs(
111110
print(f"\nBuild finished in {timer_end - timer_start:.2f} seconds.")
112111
return dest / builder
113112

114-
def update_spec_lockfile(spec_checksum_location, lockfile_location):
115113

114+
def update_spec_lockfile(spec_checksum_location, lockfile_location):
116115
try:
117116
response = requests.get(spec_checksum_location, stream=True)
118117

119118
response.raise_for_status()
120119

121-
with open(lockfile_location, 'wb') as file:
120+
with open(lockfile_location, "wb") as file:
122121
for chunk in response.iter_content(chunk_size=8192):
123122
if chunk:
124123
file.write(chunk)
125124

126-
with open(lockfile_location, 'r') as file:
125+
with open(lockfile_location, "r") as file:
127126
data = json.load(file)
128127

129128
print("-- read in --")
130129

131-
with open(lockfile_location, 'w') as outfile:
130+
with open(lockfile_location, "w") as outfile:
132131
json.dump(data, outfile, indent=4, sort_keys=True)
133132

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

141+
142142
def main(root):
143143
root = Path(root)
144144

@@ -156,12 +156,10 @@ def main(root):
156156
"--ignore-spec-lock-diff",
157157
help="ignore spec.lock file differences with live release -- for WIP branches only",
158158
default=False,
159-
action="store_true"
159+
action="store_true",
160160
)
161161
parser.add_argument(
162-
"--update-spec-lock-file",
163-
help="update spec.lock file",
164-
action="store_true"
162+
"--update-spec-lock-file", help="update spec.lock file", action="store_true"
165163
)
166164
group.add_argument(
167165
"-s",
@@ -191,7 +189,12 @@ def main(root):
191189
if args.update_spec_lock_file:
192190
update_spec_lockfile(SPEC_CHECKSUM_URL, root / "src" / SPEC_LOCKFILE)
193191

194-
rendered = build_docs(
195-
root, "xml" if args.xml else "html", args.clear, args.serve, args.debug, args.offline, not args.ignore_spec_lock_diff,
192+
build_docs(
193+
root,
194+
"xml" if args.xml else "html",
195+
args.clear,
196+
args.serve,
197+
args.debug,
198+
args.offline,
199+
not args.ignore_spec_lock_diff,
196200
)
197-

exts/coding_guidelines/__init__.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# SPDX-License-Identifier: MIT OR Apache-2.0
22
# SPDX-FileCopyrightText: The Coding Guidelines Subcommittee Contributors
3-
4-
from . import fls_checks
5-
from . import write_guidelines_ids
6-
from . import std_role
7-
from . import fls_linking
8-
from . import guidelines_checks
93

10-
from .common import logger, get_tqdm, bar_format, logging
114
from sphinx.domains import Domain
125

6+
from . import (
7+
common,
8+
fls_checks,
9+
fls_linking,
10+
guidelines_checks,
11+
std_role,
12+
write_guidelines_ids,
13+
)
14+
from .common import bar_format, get_tqdm, logger, logging
15+
16+
1317
class CodingGuidelinesDomain(Domain):
1418
name = "coding-guidelines"
1519
label = "Rust Standard Library"
@@ -19,17 +23,17 @@ class CodingGuidelinesDomain(Domain):
1923
directives = {}
2024
object_types = {}
2125
indices = {}
22-
26+
2327
def get_objects(self):
2428
return []
25-
29+
2630
def merge_domaindata(self, docnames, other):
2731
pass # No domain data to merge
2832

2933

3034
def on_build_finished(app, exception):
3135
print("\nFinalizing build:")
32-
for _ in get_tqdm(iterable=range(1), desc="Finalizing",bar_format=bar_format):
36+
for _ in get_tqdm(iterable=range(1), desc="Finalizing", bar_format=bar_format):
3337
pass
3438

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

46+
4247
def setup(app):
43-
4448
app.add_domain(CodingGuidelinesDomain)
4549
app.add_config_value(
46-
name = "offline",
47-
default=False,
48-
rebuild= "env"
49-
) # register the offline option
50+
name="offline", default=False, rebuild="env"
51+
) # register the offline option
5052
app.add_config_value(
5153
name="spec_std_docs_url",
5254
default="https://doc.rust-lang.org/stable/std",
5355
rebuild="env", # Rebuild the environment when this changes
5456
types=[str],
5557
)
56-
app.add_config_value(name='debug',
57-
default=False,
58-
rebuild='env'
58+
app.add_config_value(name="debug", default=False, rebuild="env")
59+
app.add_config_value(
60+
name="fls_paragraph_ids_url",
61+
default="https://rust-lang.github.io/fls/paragraph-ids.json",
62+
rebuild="env",
63+
)
64+
app.add_config_value(
65+
name="enable_spec_lock_consistency", default=True, rebuild="env"
5966
)
60-
app.add_config_value(name='fls_paragraph_ids_url',
61-
default='https://rust-lang.github.io/fls/paragraph-ids.json',
62-
rebuild='env')
63-
app.add_config_value(name='enable_spec_lock_consistency',
64-
default=True,
65-
rebuild='env')
6667
app.add_config_value(
67-
name='required_guideline_fields',
68-
default=['release', 'fls', 'decidability', 'scope'],
69-
rebuild='env',
68+
name="required_guideline_fields",
69+
default=["release", "fls", "decidability", "scope"],
70+
rebuild="env",
7071
types=[list],
7172
)
7273
if app.config.debug:
7374
logger.setLevel(logging.INFO)
74-
common.disable_tqdm = True
75-
76-
app.connect('env-check-consistency', guidelines_checks.validate_required_fields)
77-
app.connect('env-check-consistency', fls_checks.check_fls)
78-
app.connect('build-finished', write_guidelines_ids.build_finished)
79-
app.connect('build-finished', fls_linking.build_finished)
80-
app.connect('build-finished', on_build_finished)
81-
75+
common.disable_tqdm = True
76+
77+
app.connect("env-check-consistency", guidelines_checks.validate_required_fields)
78+
app.connect("env-check-consistency", fls_checks.check_fls)
79+
app.connect("build-finished", write_guidelines_ids.build_finished)
80+
app.connect("build-finished", fls_linking.build_finished)
81+
app.connect("build-finished", on_build_finished)
82+
8283
return {
83-
'version': '0.1',
84-
'parallel_read_safe': True,
84+
"version": "0.1",
85+
"parallel_read_safe": True,
8586
}

exts/coding_guidelines/common.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import logging
12

23
from tqdm import tqdm
3-
import logging
44

55
# This is a wrapper around tqdm that allows us to disable it with this global variable
6-
disable_tqdm = False
6+
disable_tqdm = False
7+
8+
79
def get_tqdm(**kwargs):
8-
kwargs['disable'] = disable_tqdm
10+
kwargs["disable"] = disable_tqdm
911
return tqdm(**kwargs)
12+
13+
1014
# Get the Sphinx logger
11-
logger = logging.getLogger('sphinx')
12-
logger.setLevel(logging.WARNING)
15+
logger = logging.getLogger("sphinx")
16+
logger.setLevel(logging.WARNING)
1317

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

0 commit comments

Comments
 (0)