Skip to content

Commit 121fc62

Browse files
committed
ruff format --exclude */source/conf.py
1 parent f83134a commit 121fc62

File tree

12 files changed

+565
-240
lines changed

12 files changed

+565
-240
lines changed

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ ignore =
88
E226,
99
# E261 at least two spaces before inline comment
1010
E261,
11-
# W504 line break after binary operator
12-
W504,
11+
# W503 line break before binary operator
12+
W503,
1313
# E203 whitespace before ':'
1414
E203,
1515
# E221 multiple spaces before operator

.pre-commit-config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ repos:
88
- repo: https://github.com/pycqa/flake8
99
rev: 7.3.0
1010
hooks:
11-
- id: flake8
11+
- id: flake8
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.15.5
14+
hooks:
15+
- id: ruff-format

build_parameters.py

Lines changed: 193 additions & 69 deletions
Large diffs are not rendered by default.

common_conf.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
'sphinx.ext.autodoc',
1010
'sphinx.ext.intersphinx',
1111
'sphinx.ext.todo',
12-
'sphinx.ext.mathjax', # For :math: element rendering
12+
'sphinx.ext.mathjax', # For :math: element rendering
1313
'sphinx.ext.ifconfig',
1414
'sphinxcontrib.youtube', # For youtube embedding
1515
'sphinxcontrib.jquery',
16-
'sphinx_tabs.tabs' # For clickable tabs
16+
'sphinx_tabs.tabs', # For clickable tabs
1717
]
1818

1919
# Set False to re-enable warnings for non-local images.
@@ -32,29 +32,19 @@
3232
# This needs to change to the actual URL root once the theme updated.
3333

3434
# Example configuration for intersphinx: refer to the Python standard library.
35-
intersphinx_mapping = {'copter': (intersphinx_base_url % 'copter',
36-
None),
37-
'plane': (intersphinx_base_url % 'plane',
38-
None), # noqa: E127
39-
'rover': (intersphinx_base_url % 'rover',
40-
None), # noqa: E127
41-
'sub': (intersphinx_base_url % 'sub',
42-
None), # noqa: E127
43-
'planner': (intersphinx_base_url % 'planner',
44-
None), # noqa: E128
45-
'planner2': (intersphinx_base_url % 'planner2',
46-
None), # noqa: E128
47-
'dev': (intersphinx_base_url % 'dev',
48-
None), # noqa: E127
49-
'antennatracker': (intersphinx_base_url % 'antennatracker',
50-
None), # noqa: E128
51-
'ardupilot': (intersphinx_base_url % 'ardupilot',
52-
None), # noqa: E128
53-
'mavproxy': (intersphinx_base_url % 'mavproxy',
54-
None), # noqa: E128
55-
'blimp': (intersphinx_base_url % 'blimp',
56-
None), # noqa: E127
57-
} # noqa: E124
35+
intersphinx_mapping = {
36+
'copter': (intersphinx_base_url % 'copter', None),
37+
'plane': (intersphinx_base_url % 'plane', None),
38+
'rover': (intersphinx_base_url % 'rover', None),
39+
'sub': (intersphinx_base_url % 'sub', None),
40+
'planner': (intersphinx_base_url % 'planner', None),
41+
'planner2': (intersphinx_base_url % 'planner2', None),
42+
'dev': (intersphinx_base_url % 'dev', None),
43+
'antennatracker': (intersphinx_base_url % 'antennatracker', None),
44+
'ardupilot': (intersphinx_base_url % 'ardupilot', None),
45+
'mavproxy': (intersphinx_base_url % 'mavproxy', None),
46+
'blimp': (intersphinx_base_url % 'blimp', None),
47+
}
5848

5949
# PATCH REMOVE NON-LOCAL IMAGE WARNINGS
6050
# From:

frontend/scripts/get_discourse_posts.py

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
Script to get last blog entries on Discourse (https://discuss.ardupilot.org/)
44
"""
5+
56
import argparse
67
import json
78
import re
@@ -41,25 +42,29 @@ def __init__(self, blog_url: str, news_url: str):
4142
self.news_url = news_url
4243
base_dir = Path.cwd()
4344
if str(base_dir).endswith('frontend'):
44-
base_dir = base_dir.parent # move one level up in the directory tree if needed
45+
base_dir = (
46+
base_dir.parent
47+
) # move one level up in the directory tree if needed
4548

4649
self.files_names = {
4750
self.blog_url: (base_dir / "./frontend/blog_posts.json").resolve(),
48-
self.news_url: (base_dir / "./frontend/news_posts.json").resolve()
51+
self.news_url: (base_dir / "./frontend/news_posts.json").resolve(),
4952
}
5053
# Configure session with proper cookie handling
5154
self.session = requests.Session()
52-
self.session.headers.update({
53-
'User-Agent': 'Mozilla/5.0 (compatible; ArduPilotPostGrabber/1.0)',
54-
'Accept': 'application/json',
55-
"Connection": "keep-alive",
56-
})
55+
self.session.headers.update(
56+
{
57+
'User-Agent': 'Mozilla/5.0 (compatible; ArduPilotPostGrabber/1.0)',
58+
'Accept': 'application/json',
59+
"Connection": "keep-alive",
60+
}
61+
)
5762
# Add retry logic for 429 and other errors
5863
retries = Retry(
5964
total=5,
6065
backoff_factor=2,
6166
status_forcelist=[429, 500, 502, 503, 504],
62-
allowed_methods=["HEAD", "GET", "OPTIONS"]
67+
allowed_methods=["HEAD", "GET", "OPTIONS"],
6368
)
6469
adapter = HTTPAdapter(max_retries=retries)
6570
self.session.mount("https://", adapter)
@@ -68,8 +73,16 @@ def __init__(self, blog_url: str, news_url: str):
6873
@staticmethod
6974
def get_arguments() -> Any:
7075
parser = argparse.ArgumentParser(description="python3 get_discourse_posts.py")
71-
parser.add_argument("--n_posts", dest='n_posts', default="9", help="Number of posts to retrieve")
72-
parser.add_argument("--verbose", dest='verbose', action='store_false', default=True, help="show debugging output")
76+
parser.add_argument(
77+
"--n_posts", dest='n_posts', default="9", help="Number of posts to retrieve"
78+
)
79+
parser.add_argument(
80+
"--verbose",
81+
dest='verbose',
82+
action='store_false',
83+
default=True,
84+
help="show debugging output",
85+
)
7386
args, unknown = parser.parse_known_args()
7487
return args
7588

@@ -119,27 +132,41 @@ def get_single_post_text(self, content: Any) -> str:
119132

120133
@staticmethod
121134
def get_first_youtube_or_img_link(request: str) -> Tuple[str, bool]:
122-
""" Returns the first YouTube link or image link in the request, if any.
123-
True if the link is a Youtube link."""
135+
"""Returns the first YouTube link or image link in the request, if any.
136+
True if the link is a Youtube link."""
124137
request_lines = request.splitlines()
125138
# Join the first 5 lines back together
126139
first_five_lines = '\n'.join(request_lines[:5])
127140

128141
# Regular expression to find URLs that contain 'YouTube' or image links
129142
url_pattern = re.compile(r'href=[\'"]?(https?://www\.youtube[^\'" >]+)')
130-
img_pattern = re.compile(r'(?i)(?:href|src)=[\'"]?(https?://[^\'" >]+\.(?:jpg|jpeg|png|gif|svg|bmp|webp))')
131-
img_pattern2 = re.compile(r'img src=[\'"]?(https?://[^\'" >]+)') # catch google link and such
143+
img_pattern = re.compile(
144+
r'(?i)(?:href|src)=[\'"]?(https?://[^\'" >]+\.(?:jpg|jpeg|png|gif|svg|bmp|webp))'
145+
)
146+
img_pattern2 = re.compile(
147+
r'img src=[\'"]?(https?://[^\'" >]+)'
148+
) # catch google link and such
132149

133150
# Find all matches
134151
youtube_links = url_pattern.findall(first_five_lines)
135-
img_links = img_pattern.findall(first_five_lines)[0] if img_pattern.findall(first_five_lines) else None
152+
img_links = (
153+
img_pattern.findall(first_five_lines)[0]
154+
if img_pattern.findall(first_five_lines)
155+
else None
156+
)
136157
if img_links is None:
137-
img_links = img_pattern2.findall(first_five_lines)[0] if img_pattern2.findall(
138-
first_five_lines) else None
158+
img_links = (
159+
img_pattern2.findall(first_five_lines)[0]
160+
if img_pattern2.findall(first_five_lines)
161+
else None
162+
)
139163

140164
# If there are image links before YouTube links, return empty string
141-
if img_links and (not youtube_links or
142-
first_five_lines.index(img_links) < first_five_lines.index(youtube_links[0])):
165+
if img_links and (
166+
not youtube_links
167+
or first_five_lines.index(img_links)
168+
< first_five_lines.index(youtube_links[0])
169+
):
143170
if 'github.com' in img_links:
144171
img_links = img_links + "?raw=true"
145172
return img_links, False
@@ -155,18 +182,32 @@ def get_first_youtube_or_img_link(request: str) -> Tuple[str, bool]:
155182

156183
@staticmethod
157184
def youtube_link_to_embed_link(url: str) -> str:
158-
return url.replace('https://www.youtube.com/watch?v=', 'https://www.youtube-nocookie.com/embed/')
185+
return url.replace(
186+
'https://www.youtube.com/watch?v=',
187+
'https://www.youtube-nocookie.com/embed/',
188+
)
159189

160190
def get_post_data(self, content: Any, i: int, verbose: bool) -> Post:
161191
item = content['topic_list']['topics'][i]
162-
single_post_link = str('https://discuss.ardupilot.org/t/' + str(item['slug']) + '/' + str(item['id'])) + '.json'
192+
single_post_link = (
193+
str(
194+
'https://discuss.ardupilot.org/t/'
195+
+ str(item['slug'])
196+
+ '/'
197+
+ str(item['id'])
198+
)
199+
+ '.json'
200+
)
163201
self.debug(f"Requesting post text {single_post_link} ... ", verbose)
164202
post_content_raw = self.execute_http_request_json(single_post_link)
165203
post_content = str(post_content_raw['post_stream']['posts'][0]['cooked'])
166204
single_post_text = self.get_single_post_text(post_content)
167205

168206
has_image = False
169-
self.debug(f"Requesting post text {single_post_link} to look for youtube link... ", verbose)
207+
self.debug(
208+
f"Requesting post text {single_post_link} to look for youtube link... ",
209+
verbose,
210+
)
170211
thing_link, isyoutube = self.get_first_youtube_or_img_link(post_content)
171212
youtube_link = self.youtube_link_to_embed_link(thing_link) if isyoutube else ''
172213
if youtube_link == '':
@@ -178,8 +219,14 @@ def get_post_data(self, content: Any, i: int, verbose: bool) -> Post:
178219
youtube_link = 'nops'
179220
item['image_url'] = thing_link
180221

181-
return Post(item['title'], item['image_url'], has_image, youtube_link, single_post_link.rsplit('.', 1)[0],
182-
single_post_text.strip())
222+
return Post(
223+
item['title'],
224+
item['image_url'],
225+
has_image,
226+
youtube_link,
227+
single_post_link.rsplit('.', 1)[0],
228+
single_post_text.strip(),
229+
)
183230

184231
def save_posts_to_json(self, url: str, n_posts: int, verbose: bool) -> None:
185232
content = self.execute_http_request_json(url)
@@ -194,7 +241,9 @@ def write_to_json(self, url: str, data: List[Post]) -> None:
194241
with open(self.files_names[url], 'w', encoding='utf-8') as f:
195242
json.dump(post_data, f, ensure_ascii=False, indent=4)
196243
except Exception as e:
197-
raise WriteToFileError(f"Exception occurred while writing to file with message {e}")
244+
raise WriteToFileError(
245+
f"Exception occurred while writing to file with message {e}"
246+
)
198247

199248
def fetch(self, args: Any) -> None:
200249
try:

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool.ruff]
2+
format.exclude = ["*/source/conf.py"]
3+
format.quote-style="preserve"
4+

rst_table.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ def tablify_row(rowheading, row, widths, height):
1717
out_line = ""
1818
if rowheading is not None:
1919
rowheading_line = rowheading_lines[i]
20-
out_line += joiner + " " + rowheading_line + " " * (widths[0] - len(rowheading_line) - 1)
20+
out_line += (
21+
joiner
22+
+ " "
23+
+ rowheading_line
24+
+ " " * (widths[0] - len(rowheading_line) - 1)
25+
)
2126
joiner = "#"
2227
j = 0
2328
for item in row_lines:

scripts/build_motor_diagrams.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def get_motors_json():
140140
if not motors_json or not display_json:
141141
return {}
142142

143-
existing_layouts = {(layout["Class"], layout["Type"]) for layout in motors_json["layouts"]}
143+
existing_layouts = {
144+
(layout["Class"], layout["Type"]) for layout in motors_json["layouts"]
145+
}
144146

145147
# append additional layouts from display json
146148
for layout in display_json["layouts"]:
@@ -222,7 +224,7 @@ def get_translated_coordinates(x, y, radius):
222224
scale motor vector (Roll/Pitch) output to svg coordinates
223225
"""
224226
θ = math.atan2(-y, -x)
225-
r = math.sqrt(y ** 2 + x ** 2) * radius
227+
r = math.sqrt(y**2 + x**2) * radius
226228
x_translated = r * math.cos(θ)
227229
y_translated = r * math.sin(θ)
228230
return x_translated, y_translated, r, θ
@@ -912,8 +914,8 @@ def clean(directory="."):
912914
generate_all_diagrams()
913915
exit(0)
914916

915-
# TODO: future use for inserting wiki text automatically
916-
# if args.build or args.preview:
917+
# TODO: future use for inserting wiki text automatically
918+
# if args.build or args.preview:
917919
build_all(preview=args.preview)
918920
exit(0)
919921
if args.preview:

scripts/cap_params.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import re
77

88
from argparse import ArgumentParser
9+
910
parser = ArgumentParser('find and optionally replace parameters')
10-
parser.add_argument("--change", action='store_true', help="change matches to use param markup")
11+
parser.add_argument(
12+
"--change", action='store_true', help="change matches to use param markup"
13+
)
1114
parser.add_argument("files", nargs='+')
1215

1316
args = parser.parse_args()

scripts/generate_motor_json.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* in an Ardupilot/ardupilot environment to update JSON data.
1717
*
1818
****************************************************************************"""
19+
1920
import argparse
2021
import json
2122
import math
@@ -167,7 +168,7 @@ def truncate(number, decimal_places):
167168
"""
168169
truncate a float decimal_places digits after the decimal point
169170
"""
170-
str = f"{number:.{decimal_places+1}f}"
171+
str = f"{number:.{decimal_places + 1}f}"
171172
truncated = str[: str.find(".") + decimal_places + 1]
172173
return float(truncated)
173174

@@ -449,7 +450,8 @@ def generate_all(output_file=None, force_overwrite=False):
449450
if run with '-h' or '--help', print help
450451
"""
451452
parser = argparse.ArgumentParser(
452-
description="Generate motor matrices (JSON) from 'AP_Motors/AP_MotorsMatrix.cpp'.")
453+
description="Generate motor matrices (JSON) from 'AP_Motors/AP_MotorsMatrix.cpp'."
454+
)
453455
parser.add_argument(
454456
"-o",
455457
"--output",
@@ -460,7 +462,8 @@ def generate_all(output_file=None, force_overwrite=False):
460462
help=(
461463
"Output to file (default is stdout; '-o' or '--output' with no argument writes to "
462464
f"'{DEFAULT_OUTPUT_FILE.relative_to(THIS_SCRIPT.parent)}')."
463-
))
465+
),
466+
)
464467
parser.add_argument(
465468
"-f",
466469
"--force",

0 commit comments

Comments
 (0)