Skip to content

Commit 54e36f9

Browse files
committed
Format code with ruff
1 parent 200b430 commit 54e36f9

File tree

150 files changed

+9965
-7863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+9965
-7863
lines changed

.github/workflows/ci/workflow_generate.py

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,82 @@
88

99

1010
class GithubActionsYamlLoader(yaml.SafeLoader):
11-
1211
@staticmethod
1312
def _unsupported(kind, token):
14-
return SyntaxError('Github Actions does not support %s:\n%s' % (kind, token.start_mark))
13+
return SyntaxError(
14+
"Github Actions does not support %s:\n%s" % (kind, token.start_mark)
15+
)
1516

1617
def fetch_alias(self):
1718
super().fetch_alias()
18-
raise self._unsupported('aliases', self.tokens[0])
19+
raise self._unsupported("aliases", self.tokens[0])
1920

2021
def fetch_anchor(self):
2122
super().fetch_anchor()
22-
raise self._unsupported('anchors', self.tokens[0])
23+
raise self._unsupported("anchors", self.tokens[0])
2324

2425

2526
environment = jinja2.Environment(
26-
block_start_string='<%',
27-
block_end_string='%>',
28-
variable_start_string='<@',
29-
variable_end_string='@>',
30-
comment_start_string='<#',
31-
comment_end_string='#>',
27+
block_start_string="<%",
28+
block_end_string="%>",
29+
variable_start_string="<@",
30+
variable_end_string="@>",
31+
comment_start_string="<#",
32+
comment_end_string="#>",
3233
lstrip_blocks=True,
3334
trim_blocks=True,
3435
)
3536

36-
with open('.github/workflows/ci/workflow_context.yml') as fp:
37+
with open(".github/workflows/ci/workflow_context.yml") as fp:
3738
context = yaml.load(fp, Loader=yaml.SafeLoader)
38-
with open('.github/workflows/ci/workflow_template.yml') as fp:
39+
with open(".github/workflows/ci/workflow_template.yml") as fp:
3940
template = environment.from_string(fp.read())
4041

41-
for j in context['jobs']:
42-
base_type = j['type'].split('_')[0]
43-
j['id'] = '%s_%s' % (base_type, j['variant'].lower().replace(' ', '_').replace('.', ''))
44-
j['name'] = '%s (%s)' % (base_type.capitalize(), j['variant'])
45-
j['needs'] = j.get('needs', [])
46-
j['reqs'] = ['reqs/%s.txt' % r for r in j['reqs']]
47-
j['cache_extra_deps'] = j.get('cache_extra_deps', [])
48-
if 'python' not in j:
49-
j['python'] = context['default_python']
50-
51-
if context['skippy_enabled']:
42+
for j in context["jobs"]:
43+
base_type = j["type"].split("_")[0]
44+
j["id"] = "%s_%s" % (
45+
base_type,
46+
j["variant"].lower().replace(" ", "_").replace(".", ""),
47+
)
48+
j["name"] = "%s (%s)" % (base_type.capitalize(), j["variant"])
49+
j["needs"] = j.get("needs", [])
50+
j["reqs"] = ["reqs/%s.txt" % r for r in j["reqs"]]
51+
j["cache_extra_deps"] = j.get("cache_extra_deps", [])
52+
if "python" not in j:
53+
j["python"] = context["default_python"]
54+
55+
if context["skippy_enabled"]:
5256
# Path to the "skip_cache" file.
53-
j['skip_cache_path'] = '.skip_cache_{id}'.format(**j)
57+
j["skip_cache_path"] = ".skip_cache_{id}".format(**j)
5458
# Name of the "skip_cache" (name + tree SHA1 = key).
55-
j['skip_cache_name'] = 'skip_{id}_py-{python}_{platform}'.format(cache_epoch=context['cache_epoch'], **j)
59+
j["skip_cache_name"] = "skip_{id}_py-{python}_{platform}".format(
60+
cache_epoch=context["cache_epoch"], **j
61+
)
5662
shell_definition = []
5763
for k, v in sorted(j.items()):
5864
if isinstance(v, list):
59-
v = '(' + ' '.join(map(shlex.quote, v)) + ')'
65+
v = "(" + " ".join(map(shlex.quote, v)) + ")"
6066
else:
6167
v = shlex.quote(v)
62-
shell_definition.append('job_%s=%s' % (k, v))
63-
j['shell_definition'] = '; '.join(shell_definition)
68+
shell_definition.append("job_%s=%s" % (k, v))
69+
j["shell_definition"] = "; ".join(shell_definition)
6470

6571
# Render template.
6672
workflow = template.render(context)
6773

6874
# Save result.
69-
with open('.github/workflows/ci.yml', 'w') as fp:
70-
fp.write(textwrap.dedent(
71-
'''
75+
with open(".github/workflows/ci.yml", "w") as fp:
76+
fp.write(
77+
textwrap.dedent(
78+
"""
7279
#
7380
# DO NOT MODIFY! AUTO-GENERATED FROM:
7481
# .github/workflows/ci/workflow_template.yml
7582
#
7683
77-
''').lstrip())
84+
"""
85+
).lstrip()
86+
)
7887
fp.write(workflow)
7988

8089
# And try parsing it to check it's valid YAML,

doc/conf.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# -- General configuration ---------------------------------------------------
1313

1414
extensions = [
15-
"sphinx_plover",
16-
"myst_parser",
17-
"sphinx.ext.todo",
15+
"sphinx_plover",
16+
"myst_parser",
17+
"sphinx.ext.todo",
1818
]
1919

2020
myst_enable_extensions = ["colon_fence"]
@@ -41,32 +41,32 @@
4141
html_favicon = "_static/favicon.ico"
4242

4343
html_css_files = [
44-
"custom.css",
44+
"custom.css",
4545
]
4646

4747
html_theme_options = {
48-
"navigation_with_keys": True,
49-
"light_css_variables": {
50-
"color-brand-primary": "#3d6961",
51-
"color-brand-content": "#3d6961",
52-
"color-sidebar-background": "#3d6961",
53-
"color-sidebar-brand-text": "white",
54-
"color-sidebar-brand-text--hover": "white",
55-
"color-sidebar-caption-text": "white",
56-
"color-sidebar-link-text": "white",
57-
"color-sidebar-link-text--top-level": "white",
58-
"color-sidebar-item-background--hover": "#71a89f",
59-
"color-sidebar-item-expander-background--hover": "#71a89f",
60-
"color-inline-code-background": "transparent",
61-
"font-stack--header": "'Patua One', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'",
62-
"font-stack--monospace": "'JetBrains Mono', SFMono-Regular, Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace",
63-
},
64-
"dark_css_variables": {
65-
"color-link": "#68a69b",
66-
"color-link--hover": "#68a69b",
67-
},
68-
"light_logo": "dolores.svg",
69-
"dark_logo": "dolores.svg",
48+
"navigation_with_keys": True,
49+
"light_css_variables": {
50+
"color-brand-primary": "#3d6961",
51+
"color-brand-content": "#3d6961",
52+
"color-sidebar-background": "#3d6961",
53+
"color-sidebar-brand-text": "white",
54+
"color-sidebar-brand-text--hover": "white",
55+
"color-sidebar-caption-text": "white",
56+
"color-sidebar-link-text": "white",
57+
"color-sidebar-link-text--top-level": "white",
58+
"color-sidebar-item-background--hover": "#71a89f",
59+
"color-sidebar-item-expander-background--hover": "#71a89f",
60+
"color-inline-code-background": "transparent",
61+
"font-stack--header": "'Patua One', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'",
62+
"font-stack--monospace": "'JetBrains Mono', SFMono-Regular, Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace",
63+
},
64+
"dark_css_variables": {
65+
"color-link": "#68a69b",
66+
"color-link--hover": "#68a69b",
67+
},
68+
"light_logo": "dolores.svg",
69+
"dark_logo": "dolores.svg",
7070
}
7171

7272
from pygments.lexer import RegexLexer, bygroups
@@ -75,26 +75,26 @@
7575

7676

7777
class RTFLexer(RegexLexer):
78-
name = "rtf"
79-
80-
tokens = {
81-
"root": [
82-
(r"(\\[a-z*\\_~\{\}]+)(-?\d+)?", bygroups(t.Keyword, t.Number.Integer)),
83-
(r"{\\\*\\cxcomment\s+", t.Comment.Multiline, "comment"),
84-
(
85-
r"({)(\\\*\\cxs)(\s+)([A-Z#0-9\-/#!,]+)(})",
86-
bygroups(t.Operator, t.Keyword, t.Text, t.String, t.Operator),
87-
),
88-
(r"{", t.Operator),
89-
(r"}", t.Operator),
90-
(r".+?", t.Text),
91-
],
92-
"comment": [
93-
(r"{", t.Comment.Multiline, "#push"),
94-
(r"}", t.Comment.Multiline, "#pop"),
95-
(r".+", t.Comment.Multiline),
96-
],
97-
}
78+
name = "rtf"
79+
80+
tokens = {
81+
"root": [
82+
(r"(\\[a-z*\\_~\{\}]+)(-?\d+)?", bygroups(t.Keyword, t.Number.Integer)),
83+
(r"{\\\*\\cxcomment\s+", t.Comment.Multiline, "comment"),
84+
(
85+
r"({)(\\\*\\cxs)(\s+)([A-Z#0-9\-/#!,]+)(})",
86+
bygroups(t.Operator, t.Keyword, t.Text, t.String, t.Operator),
87+
),
88+
(r"{", t.Operator),
89+
(r"}", t.Operator),
90+
(r".+?", t.Text),
91+
],
92+
"comment": [
93+
(r"{", t.Comment.Multiline, "#push"),
94+
(r"}", t.Comment.Multiline, "#pop"),
95+
(r".+", t.Comment.Multiline),
96+
],
97+
}
9898

9999

100100
lexers["rtf"] = RTFLexer(startinline=True)

linux/appimage/pyinfo.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
from distutils import sysconfig
22
import sys
33

4-
print("; ".join("py%s=%r" % (k, v) for k, v in sorted({
5-
'exe' : sys.executable,
6-
'prefix' : getattr(sys, "base_prefix", sys.prefix),
7-
'version': sysconfig.get_python_version(),
8-
'include': sysconfig.get_python_inc(prefix=''),
9-
'ldlib' : sysconfig.get_config_var('LDLIBRARY'),
10-
'py3lib' : sysconfig.get_config_var('PY3LIBRARY'),
11-
'stdlib' : sysconfig.get_python_lib(standard_lib=1, prefix=''),
12-
'purelib': sysconfig.get_python_lib(plat_specific=0, prefix=''),
13-
'platlib': sysconfig.get_python_lib(plat_specific=1, prefix=''),
14-
}.items())))
4+
print(
5+
"; ".join(
6+
"py%s=%r" % (k, v)
7+
for k, v in sorted(
8+
{
9+
"exe": sys.executable,
10+
"prefix": getattr(sys, "base_prefix", sys.prefix),
11+
"version": sysconfig.get_python_version(),
12+
"include": sysconfig.get_python_inc(prefix=""),
13+
"ldlib": sysconfig.get_config_var("LDLIBRARY"),
14+
"py3lib": sysconfig.get_config_var("PY3LIBRARY"),
15+
"stdlib": sysconfig.get_python_lib(standard_lib=1, prefix=""),
16+
"purelib": sysconfig.get_python_lib(plat_specific=0, prefix=""),
17+
"platlib": sysconfig.get_python_lib(plat_specific=1, prefix=""),
18+
}.items()
19+
)
20+
)
21+
)

osx/dmg_resources/settings.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,37 @@
33
import plistlib
44
import os.path
55

6-
application = defines.get('app', './dist/Plover.app')
6+
application = defines.get("app", "./dist/Plover.app")
77
appname = os.path.basename(application)
88

99

1010
def icon_from_app(app_path):
11-
plist_path = os.path.join(app_path, 'Contents', 'Info.plist')
12-
with open(plist_path, 'rb') as plist_file:
11+
plist_path = os.path.join(app_path, "Contents", "Info.plist")
12+
with open(plist_path, "rb") as plist_file:
1313
plist = plistlib.load(plist_file)
14-
icon_name = plist['CFBundleIconFile']
14+
icon_name = plist["CFBundleIconFile"]
1515
icon_root, icon_ext = os.path.splitext(icon_name)
1616
if not icon_ext:
17-
icon_ext = '.icns'
17+
icon_ext = ".icns"
1818
icon_name = icon_root + icon_ext
19-
return os.path.join(app_path, 'Contents', 'Resources', icon_name)
19+
return os.path.join(app_path, "Contents", "Resources", icon_name)
2020

21-
format = defines.get('format', 'UDBZ')
21+
22+
format = defines.get("format", "UDBZ")
2223

2324
# Files to include
2425
files = [application]
2526

2627
# Symlinks to create
27-
symlinks = {'Applications': '/Applications'}
28+
symlinks = {"Applications": "/Applications"}
2829

2930
# Volume icon
3031
badge_icon = icon_from_app(application)
3132

3233
# Where to put the icons
33-
icon_locations = {
34-
appname: (114, 244),
35-
'Applications': (527, 236)
36-
}
34+
icon_locations = {appname: (114, 244), "Applications": (527, 236)}
3735

38-
background = 'osx/dmg_resources/background.png'
36+
background = "osx/dmg_resources/background.png"
3937

4038
show_status_bar = False
4139
show_tab_view = False
@@ -46,15 +44,15 @@ def icon_from_app(app_path):
4644
# Window position in ((x, y), (w, h)) format
4745
window_rect = ((100, 100), (640, 380))
4846

49-
default_view = 'icon-view'
47+
default_view = "icon-view"
5048
show_icon_preview = False
51-
include_icon_view_settings = 'auto'
52-
include_list_view_settings = 'auto'
49+
include_icon_view_settings = "auto"
50+
include_list_view_settings = "auto"
5351

5452
arrange_by = None
5553
grid_offset = (0, 0)
5654
grid_spacing = 50
5755
scroll_position = (0, 0)
58-
label_pos = 'bottom'
56+
label_pos = "bottom"
5957
text_size = 16
6058
icon_size = 86

plover/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33

44
"""Plover: Open Source Stenography Software"""
55

6-
if __name__ == 'plover':
6+
if __name__ == "plover":
77
from plover.i18n import Translator
8+
89
_ = Translator(__package__)
910
else:
1011
# exec from `setup.py`, package data
1112
# may not be available, and we don't
1213
# want to translate anyway.
1314
_ = lambda s: s
1415

15-
__version__ = '5.0.0.dev2'
16-
__copyright__ = '(C) Open Steno Project'
17-
__url__ = 'http://www.openstenoproject.org/'
18-
__download_url__ = 'http://www.openstenoproject.org/plover'
16+
__version__ = "5.0.0.dev2"
17+
__copyright__ = "(C) Open Steno Project"
18+
__url__ = "http://www.openstenoproject.org/"
19+
__download_url__ = "http://www.openstenoproject.org/plover"
1920
__credits__ = _("""\
2021
Founded by stenographer Mirabai Knight.
2122
@@ -30,9 +31,9 @@
3031
3132
and many more on GitHub:
3233
<https://github.com/openstenoproject/plover>""")
33-
__license__ = 'GNU General Public License v2 or later (GPLv2+)'
34+
__license__ = "GNU General Public License v2 or later (GPLv2+)"
3435
# i18n: Short description for Plover, currently not used in the interface.
35-
__description__ = _('Open Source Stenography Software')
36+
__description__ = _("Open Source Stenography Software")
3637
__long_description__ = _("""\
3738
Plover is a free open source program intended to bring realtime
3839
stenographic technology not just to stenographers, but also to

plover/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from plover.scripts.main import main
22

33

4-
if __name__ == '__main__':
4+
if __name__ == "__main__":
55
main()

plover/command/set_config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ def set_config(engine, cmdline):
2222

2323

2424
def _cmdline_to_dict(cmdline):
25-
""" Add braces and parse the entire command line as a Python dict literal. """
25+
"""Add braces and parse the entire command line as a Python dict literal."""
2626
try:
27-
opt_dict = ast.literal_eval('{'+cmdline+'}')
27+
opt_dict = ast.literal_eval("{" + cmdline + "}")
2828
assert isinstance(opt_dict, dict)
2929
return opt_dict
3030
except (AssertionError, SyntaxError, ValueError) as e:
31-
raise ValueError('Bad command string "%s" for PLOVER:SET_CONFIG.\n' % cmdline
32-
+ 'See for reference:\n\n' + set_config.__doc__) from e
31+
raise ValueError(
32+
'Bad command string "%s" for PLOVER:SET_CONFIG.\n' % cmdline
33+
+ "See for reference:\n\n"
34+
+ set_config.__doc__
35+
) from e

0 commit comments

Comments
 (0)