Skip to content

Commit 6f91543

Browse files
authored
Format Python code with ruff format instead of black (#498)
1 parent b2ff263 commit 6f91543

File tree

5 files changed

+49
-54
lines changed

5 files changed

+49
-54
lines changed

README.rst

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Sphinx AutoAPI
1717
:target: https://pypi.org/project/sphinx-autoapi/
1818
:alt: Supported Python Versions
1919

20-
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
21-
:target: https://github.com/python/black
22-
:alt: Formatted with Black
20+
.. image:: https://img.shields.io/badge/code%20style-ruff-000000.svg
21+
:target: https://docs.astral.sh/ruff/
22+
:alt: Formatted with Ruff
2323

2424
Sphinx AutoAPI is a Sphinx extension for generating complete API documentation
2525
without needing to load, run, or import the project being documented.
@@ -77,27 +77,19 @@ Tests are executed through `tox <https://tox.readthedocs.io/en/latest/>`_.
7777
Code Style
7878
~~~~~~~~~~
7979

80-
Code is formatted using `black <https://github.com/python/black>`_.
80+
Code is formatted using `ruff <https://docs.astral.sh/ruff>`_.
8181

82-
You can check your formatting using black's check mode:
82+
You can check your formatting using ruff format's check mode:
8383

8484
.. code-block:: bash
8585
8686
tox -e format
8787
88-
You can also get black to format your changes for you:
88+
You can also get ruff to format your changes for you:
8989

9090
.. code-block:: bash
9191
92-
black autoapi/ tests/
93-
94-
You can even get black to format changes automatically when you commit using `pre-commit <https://pre-commit.com/>`_:
95-
96-
97-
.. code-block:: bash
98-
99-
pip install pre-commit
100-
pre-commit install
92+
ruff format
10193
10294
Release Notes
10395
~~~~~~~~~~~~~

docs/changes/498.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Format Python code with ruff format instead of black.

docs/conf.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,49 @@
1313
# -- Project information -----------------------------------------------------
1414
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
1515

16-
project = 'Sphinx AutoAPI'
17-
copyright = '2023, Read the Docs'
18-
author = 'Read the Docs'
16+
project = "Sphinx AutoAPI"
17+
copyright = "2023, Read the Docs"
18+
author = "Read the Docs"
1919
version = ".".join(str(x) for x in autoapi.__version_info__[:2])
2020
release = autoapi.__version__
2121

2222
# -- General configuration ---------------------------------------------------
2323
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
2424

2525
extensions = [
26-
'autoapi.extension',
27-
'sphinx.ext.intersphinx',
28-
'sphinx.ext.napoleon',
29-
'sphinx_design',
26+
"autoapi.extension",
27+
"sphinx.ext.intersphinx",
28+
"sphinx.ext.napoleon",
29+
"sphinx_design",
3030
]
3131

32-
templates_path = ['_templates']
33-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'changes/*.rst']
32+
templates_path = ["_templates"]
33+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "changes/*.rst"]
3434

3535

3636
# -- Options for HTML output -------------------------------------------------
3737
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3838

39-
html_theme = 'furo'
40-
html_static_path = ['_static']
41-
html_css_files = ['overrides.css']
39+
html_theme = "furo"
40+
html_static_path = ["_static"]
41+
html_css_files = ["overrides.css"]
4242

4343
# -- Options for AutoAPI extension -------------------------------------------
44-
autoapi_dirs = ['../autoapi']
44+
autoapi_dirs = ["../autoapi"]
4545
autoapi_generate_api_docs = False
4646

4747
# -- Options for intersphinx extension ---------------------------------------
4848

4949
intersphinx_mapping = {
50-
'jinja': ('https://jinja.palletsprojects.com/en/3.0.x/', None),
51-
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
52-
'python': ('https://docs.python.org/3/', None),
50+
"jinja": ("https://jinja.palletsprojects.com/en/3.0.x/", None),
51+
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
52+
"python": ("https://docs.python.org/3/", None),
5353
}
5454

5555
# -- Enable confval and event roles ------------------------------------------
5656

57-
event_sig_re = re.compile(r'([a-zA-Z-]+)\s*\((.*)\)')
57+
event_sig_re = re.compile(r"([a-zA-Z-]+)\s*\((.*)\)")
58+
5859

5960
def parse_event(env, sig, signode):
6061
m = event_sig_re.match(sig)
@@ -64,18 +65,27 @@ def parse_event(env, sig, signode):
6465
name, args = m.groups()
6566
signode += addnodes.desc_name(name, name)
6667
plist = addnodes.desc_parameterlist()
67-
for arg in args.split(','):
68+
for arg in args.split(","):
6869
arg = arg.strip()
6970
plist += addnodes.desc_parameter(arg, arg)
7071
signode += plist
7172
return name
7273

7374

7475
def setup(app):
75-
app.add_object_type('confval', 'confval',
76-
objname='configuration value',
77-
indextemplate='pair: %s; configuration value')
78-
fdesc = TypedField('parameter', label='Parameters',
79-
names=('param',), typenames=('type',), can_collapse=True)
80-
app.add_object_type('event', 'event', 'pair: %s; event', parse_event,
81-
doc_field_types=[fdesc])
76+
app.add_object_type(
77+
"confval",
78+
"confval",
79+
objname="configuration value",
80+
indextemplate="pair: %s; configuration value",
81+
)
82+
fdesc = TypedField(
83+
"parameter",
84+
label="Parameters",
85+
names=("param",),
86+
typenames=("type",),
87+
can_collapse=True,
88+
)
89+
app.add_object_type(
90+
"event", "event", "pair: %s; event", parse_event, doc_field_types=[fdesc]
91+
)

tests/test_astroid_utils.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def test_can_get_full_imported_basename(self, import_, basename, expected):
6767
{}
6868
class ThisClass({}): #@
6969
pass
70-
""".format(
71-
import_, basename
72-
)
70+
""".format(import_, basename)
7371
node = astroid.extract_node(source)
7472
basenames = _astroid_utils.resolve_qualname(node.bases[0], node.basenames[0])
7573
assert basenames == expected
@@ -82,9 +80,7 @@ def test_can_get_full_function_basename(self, import_, basename, expected):
8280
{}
8381
class ThisClass({}): #@
8482
pass
85-
""".format(
86-
import_, basename
87-
)
83+
""".format(import_, basename)
8884
node = astroid.extract_node(source)
8985
basenames = _astroid_utils.resolve_qualname(node.bases[0], node.basenames[0])
9086
assert basenames == expected
@@ -163,9 +159,7 @@ def test_parse_annotations(self, signature, expected):
163159
"""
164160
def func({}) -> str: #@
165161
pass
166-
""".format(
167-
signature
168-
)
162+
""".format(signature)
169163
)
170164

171165
annotations = _astroid_utils.get_args_info(node.args)
@@ -227,9 +221,7 @@ def test_format_args(self, signature, expected):
227221
"""
228222
def func({}) -> str: #@
229223
pass
230-
""".format(
231-
signature
232-
)
224+
""".format(signature)
233225
)
234226

235227
args_info = _astroid_utils.get_args_info(node.args)

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ commands =
2929
[testenv:format]
3030
skip_install = true
3131
deps =
32-
black
32+
ruff
3333
commands =
34-
black --check --diff autoapi tests
34+
ruff format --check --diff
3535

3636
[testenv:lint]
3737
skip_install = true

0 commit comments

Comments
 (0)