Skip to content
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

Format Python code with ruff format instead of black #498

Merged
merged 3 commits into from
Nov 25, 2024
Merged
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
22 changes: 7 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Sphinx AutoAPI
:target: https://pypi.org/project/sphinx-autoapi/
:alt: Supported Python Versions

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

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

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

You can check your formatting using black's check mode:
You can check your formatting using ruff format's check mode:

.. code-block:: bash

tox -e format

You can also get black to format your changes for you:
You can also get ruff to format your changes for you:

.. code-block:: bash

black autoapi/ tests/

You can even get black to format changes automatically when you commit using `pre-commit <https://pre-commit.com/>`_:


.. code-block:: bash

pip install pre-commit
pre-commit install
ruff format

Release Notes
~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions docs/changes/498.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Format Python code with ruff format instead of black.
60 changes: 35 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,49 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Sphinx AutoAPI'
copyright = '2023, Read the Docs'
author = 'Read the Docs'
project = "Sphinx AutoAPI"
copyright = "2023, Read the Docs"
author = "Read the Docs"
version = ".".join(str(x) for x in autoapi.__version_info__[:2])
release = autoapi.__version__

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

extensions = [
'autoapi.extension',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx_design',
"autoapi.extension",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx_design",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'changes/*.rst']
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "changes/*.rst"]


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

html_theme = 'furo'
html_static_path = ['_static']
html_css_files = ['overrides.css']
html_theme = "furo"
html_static_path = ["_static"]
html_css_files = ["overrides.css"]

# -- Options for AutoAPI extension -------------------------------------------
autoapi_dirs = ['../autoapi']
autoapi_dirs = ["../autoapi"]
autoapi_generate_api_docs = False

# -- Options for intersphinx extension ---------------------------------------

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

# -- Enable confval and event roles ------------------------------------------

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


def parse_event(env, sig, signode):
m = event_sig_re.match(sig)
Expand All @@ -64,18 +65,27 @@ def parse_event(env, sig, signode):
name, args = m.groups()
signode += addnodes.desc_name(name, name)
plist = addnodes.desc_parameterlist()
for arg in args.split(','):
for arg in args.split(","):
arg = arg.strip()
plist += addnodes.desc_parameter(arg, arg)
signode += plist
return name


def setup(app):
app.add_object_type('confval', 'confval',
objname='configuration value',
indextemplate='pair: %s; configuration value')
fdesc = TypedField('parameter', label='Parameters',
names=('param',), typenames=('type',), can_collapse=True)
app.add_object_type('event', 'event', 'pair: %s; event', parse_event,
doc_field_types=[fdesc])
app.add_object_type(
"confval",
"confval",
objname="configuration value",
indextemplate="pair: %s; configuration value",
)
fdesc = TypedField(
"parameter",
label="Parameters",
names=("param",),
typenames=("type",),
can_collapse=True,
)
app.add_object_type(
"event", "event", "pair: %s; event", parse_event, doc_field_types=[fdesc]
)
16 changes: 4 additions & 12 deletions tests/test_astroid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def test_can_get_full_imported_basename(self, import_, basename, expected):
{}
class ThisClass({}): #@
pass
""".format(
import_, basename
)
""".format(import_, basename)
node = astroid.extract_node(source)
basenames = _astroid_utils.resolve_qualname(node.bases[0], node.basenames[0])
assert basenames == expected
Expand All @@ -82,9 +80,7 @@ def test_can_get_full_function_basename(self, import_, basename, expected):
{}
class ThisClass({}): #@
pass
""".format(
import_, basename
)
""".format(import_, basename)
node = astroid.extract_node(source)
basenames = _astroid_utils.resolve_qualname(node.bases[0], node.basenames[0])
assert basenames == expected
Expand Down Expand Up @@ -163,9 +159,7 @@ def test_parse_annotations(self, signature, expected):
"""
def func({}) -> str: #@
pass
""".format(
signature
)
""".format(signature)
)

annotations = _astroid_utils.get_args_info(node.args)
Expand Down Expand Up @@ -227,9 +221,7 @@ def test_format_args(self, signature, expected):
"""
def func({}) -> str: #@
pass
""".format(
signature
)
""".format(signature)
)

args_info = _astroid_utils.get_args_info(node.args)
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ commands =
[testenv:format]
skip_install = true
deps =
black
ruff
commands =
black --check --diff autoapi tests
ruff format --check --diff

[testenv:lint]
skip_install = true
Expand Down
Loading