Skip to content

Commit c4aecc7

Browse files
authored
Merge pull request #135 from openSUSE/toms/reformat-code-with-ruff
Reformat source code with Ruff
2 parents 79ba31d + af00704 commit c4aecc7

98 files changed

Lines changed: 3268 additions & 2906 deletions

File tree

Some content is hidden

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

.ruff.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ignore = [
5555
"D203", # Conflicts with D211 (one blank line before class docstring)
5656
"D213", # Conflicts with D212 (multi-line docstring start convention)
5757
# "D401", # First line of docstring should be in imperative mood
58-
"COM812", #
58+
"COM812", #
5959
]
6060

6161
# Allow autofix for everything except complexity and annotations
@@ -77,7 +77,7 @@ max-complexity = 10
7777

7878
[format]
7979
# 5. Use single quotes in `ruff format`.
80-
quote-style = "single"
80+
quote-style = "double"
8181

8282

8383
[lint.per-file-ignores]
@@ -91,8 +91,11 @@ quote-style = "single"
9191
"ANN201", # Missing return type annotation
9292
"ANN202", # Missing return type annotation for private function
9393
"ANN204", # Missing return type annotation for special method `__init__`
94+
"ANN401", # Missing type annotation for self in method
9495
"D100", # Missing docstring in public module
9596
"D101", # Missing docstring in public class
9697
"D103", # Missing docstring in public function
9798
"D105", # Missing docstring in magic method
98-
]
99+
]
100+
# Ignore unused imports in all __init__.py files
101+
"__init__.py" = ["F401"]

GEMINI.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Project: Docbuild
2+
3+
Docbuild is a project to build documentation either from DocBook or ADoc code. It maintains a set of XML configuration files, clones the repositories, calls the `daps` executable, takes care of metadata and syncs the result deliverables to its target directory.
4+
5+
## General instructions
6+
7+
- Make minimal changes
8+
- Leave the code base untouched as much as possible
9+
10+
## Coding Standards
11+
12+
Ensure the generated code conforms to these points:
13+
14+
- Python Version: Use Python 3.12 or higher. Adapt code style, type hints, and docstrings accordingly.
15+
16+
- Type Hints: Use type hints for functions and variables where feasible.
17+
18+
- Docstrings: Add Sphinx-style docstrings. Document the purpose of the code in a short line, followed by the arguments and their purpose.
19+
20+
- Clarity & Maintainability: Focus on clean, maintainable code. Adhere to the single responsibility principle (one function, one purpose).

changelog.d/135.infra.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reformat the source code with Ruff. Removed unused imports and variables, fix docstrings, and use double quotes in strings.

docs/source/conf.py

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
from docbuild.__about__ import __version__
1010

11-
project = 'docbuild'
12-
copyright = '2025, Tom Schraitle' # noqa: A001
13-
author = 'Tom Schraitle'
11+
project = "docbuild"
12+
copyright = "2025, Tom Schraitle" # noqa: A001
13+
author = "Tom Schraitle"
1414
release = __version__
1515

16-
gh_user = 'openSUSE'
17-
gh_repo_url = f'https://github.com/{gh_user}/{project}'
18-
gh_repo_slug = f'{gh_user}/{project}'
16+
gh_user = "openSUSE"
17+
gh_repo_url = f"https://github.com/{gh_user}/{project}"
18+
gh_repo_slug = f"{gh_user}/{project}"
1919

20-
xml_config_repo = 'https://gitlab.suse.de/susedoc/docserv-config'
21-
xml_config_slug = '/'.join(xml_config_repo.rsplit('/', 2)[-2:])
20+
xml_config_repo = "https://gitlab.suse.de/susedoc/docserv-config"
21+
xml_config_slug = "/".join(xml_config_repo.rsplit("/", 2)[-2:])
2222

2323
# --- Prolog configuration
2424
rst_prolog = f"""
@@ -39,87 +39,87 @@
3939
extensions = [
4040
# Include documentation from docstrings
4141
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
42-
'sphinx.ext.autodoc',
42+
"sphinx.ext.autodoc",
4343
#
4444
# Link to other projects' documentation
4545
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
46-
'sphinx.ext.intersphinx',
46+
"sphinx.ext.intersphinx",
4747
#
4848
# Test code snippets in the documentation
4949
# https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html
50-
'sphinx.ext.doctest',
50+
"sphinx.ext.doctest",
5151
#
5252
# Create short aliases for external links
5353
# https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
54-
'sphinx.ext.extlinks',
54+
"sphinx.ext.extlinks",
5555
#
5656
# Embed Graphviz graphs
5757
# https://www.sphinx-doc.org/en/master/usage/extensions/graphviz.html
58-
'sphinx.ext.graphviz',
58+
"sphinx.ext.graphviz",
5959
#
6060
# Document Click command-line interfaces
6161
# https://sphinx-click.readthedocs.io/en/latest/
62-
'sphinx_click',
62+
"sphinx_click",
6363
#
6464
# Add a "copy" button to code blocks
6565
# https://sphinx-copybutton.readthedocs.io/en/latest/
66-
'sphinx_copybutton',
66+
"sphinx_copybutton",
6767
#
6868
# Render type hints in signatures
6969
# https://github.com/tox-dev/sphinx-autodoc-typehints
70-
'sphinx_autodoc_typehints',
70+
"sphinx_autodoc_typehints",
7171
#
7272
# Generate API documentation from source code
7373
# https://sphinx-autoapi.readthedocs.io/en/latest/
74-
'autoapi.extension',
74+
"autoapi.extension",
7575
]
7676

77-
templates_path = ['_templates']
77+
templates_path = ["_templates"]
7878
exclude_patterns = []
7979

80-
language = 'en'
80+
language = "en"
8181

8282
# -- Options for autoapi extension
8383
# https://sphinx-autoapi.readthedocs.io/en/latest/reference/config.html
8484
autoapi_modules = {
85-
'docbuild': None,
85+
"docbuild": None,
8686
# {
8787
# # "output": "reference/_autoapi",
8888
# # "prune": True|False,
8989
# # "override": True|False,
9090
# # "template":
9191
# }
9292
}
93-
autoapi_root = 'reference/_autoapi'
94-
autoapi_dirs = ['../../src/']
95-
autoapi_type = 'python'
93+
autoapi_root = "reference/_autoapi"
94+
autoapi_dirs = ["../../src/"]
95+
autoapi_type = "python"
9696
autoapi_add_toctree_entry = False
9797
# autoapi_template_dir = "_templates/autoapi"
9898
autoapi_options = [
99-
'members',
99+
"members",
100100
# "undoc-members",
101101
# 'inherited-members',
102-
'show-inheritance',
103-
'show-module-summary',
102+
"show-inheritance",
103+
"show-module-summary",
104104
# 'imported-members',
105-
'special-members',
106-
'show-inheritance-diagram', # needs sphinx.ext.inheritance_diagram & graphviz
105+
"special-members",
106+
"show-inheritance-diagram", # needs sphinx.ext.inheritance_diagram & graphviz
107107
# "private-members",
108108
]
109109
autoapi_keep_files = True
110-
autodoc_typehints = 'signature'
111-
autoapi_own_page_level = 'class'
112-
#autoapi_python_use_implicit_namespaces = True
110+
autodoc_typehints = "signature"
111+
autoapi_own_page_level = "class"
112+
# autoapi_python_use_implicit_namespaces = True
113113

114114
# -- Options for extlinks extension ------------------------------------------
115115
# https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
116116
extlinks = {
117117
# Example for linking to a specific file/path in the repo:
118-
'gh_path': (f'{gh_repo_url}/blob/main/%s', '%s'),
118+
"gh_path": (f"{gh_repo_url}/blob/main/%s", "%s"),
119119
# Example for linking to a specific directory in the repo:
120-
'gh_tree': (f'{gh_repo_url}/tree/main/%s', '%s'),
120+
"gh_tree": (f"{gh_repo_url}/tree/main/%s", "%s"),
121121
# Linking to the GH issue tracker:
122-
'gh': (f'{gh_repo_url}/issues/%s', 'GH #%s'),
122+
"gh": (f"{gh_repo_url}/issues/%s", "GH #%s"),
123123
}
124124

125125

@@ -129,90 +129,90 @@
129129

130130
autosummary_generate = False
131131
autodoc_default_options = {
132-
'members': True,
133-
'undoc-members': False,
134-
'show-inheritance': True,
135-
'inherited-members': False,
136-
'private-members': True,
132+
"members": True,
133+
"undoc-members": False,
134+
"show-inheritance": True,
135+
"inherited-members": False,
136+
"private-members": True,
137137
}
138138

139-
html_theme = 'pydata_sphinx_theme'
139+
html_theme = "pydata_sphinx_theme"
140140
# html_theme = "alabaster"
141141

142-
html_static_path = ['_static']
142+
html_static_path = ["_static"]
143143

144144
html_css_files = [
145-
'css/custom.css',
145+
"css/custom.css",
146146
]
147147

148148
html_context = {
149-
'github_user': gh_user,
150-
'github_repo': project,
151-
'github_version': 'main',
152-
'doc_path': 'docs/source/',
149+
"github_user": gh_user,
150+
"github_repo": project,
151+
"github_version": "main",
152+
"doc_path": "docs/source/",
153153
}
154154

155155
html_theme_options = {
156-
'announcement': 'Documentation is under construction.',
157-
'show_prev_next': True,
156+
"announcement": "Documentation is under construction.",
157+
"show_prev_next": True,
158158
# "html_last_updated_fmt": "%b %d, %Y",
159-
'content_footer_items': ['last-updated'],
160-
'github_url': gh_repo_url,
159+
"content_footer_items": ["last-updated"],
160+
"github_url": gh_repo_url,
161161
# "external_links": [
162162
# {"name": "link-one-name", "url": "https://<link-one>"},
163163
# ],
164164
#
165-
'icon_links': [
165+
"icon_links": [
166166
{
167-
'name': 'GitLab susedoc/docserv-config',
168-
'url': xml_config_repo,
169-
'icon': 'fa-brands fa-square-gitlab',
170-
'type': 'fontawesome',
167+
"name": "GitLab susedoc/docserv-config",
168+
"url": xml_config_repo,
169+
"icon": "fa-brands fa-square-gitlab",
170+
"type": "fontawesome",
171171
},
172172
{
173-
'name': 'Kanban board',
174-
'url': 'https://github.com/orgs/openSUSE/projects/27/',
175-
'icon': 'fa-solid fa-table-columns',
176-
'type': 'fontawesome',
173+
"name": "Kanban board",
174+
"url": "https://github.com/orgs/openSUSE/projects/27/",
175+
"icon": "fa-solid fa-table-columns",
176+
"type": "fontawesome",
177177
},
178178
],
179179
#
180-
'use_edit_page_button': True,
181-
'back_to_top_button': True,
182-
'logo': {
183-
'text': 'Docbuild Documentation',
180+
"use_edit_page_button": True,
181+
"back_to_top_button": True,
182+
"logo": {
183+
"text": "Docbuild Documentation",
184184
# "image_light": "_static/logo-light.png",
185185
# "image_dark": "_static/logo-dark.png",
186186
},
187187
}
188188

189-
html_logo = '_static/logo.png'
189+
html_logo = "_static/logo.png"
190190

191-
html_favicon = '_static/favicon.ico'
191+
html_favicon = "_static/favicon.ico"
192192

193193
# -- Options for intersphinx extension ---------------------------------------
194194
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#configuration
195195

196196
intersphinx_mapping = {
197-
'python': ('https://docs.python.org/3', None),
198-
'pydantic': ('https://docs.pydantic.dev/latest/', None),
199-
'click': ('https://click.palletsprojects.com/en/latest/', None),
200-
'jinja2': ('https://jinja.palletsprojects.com/en/latest/', None),
197+
"python": ("https://docs.python.org/3", None),
198+
"pydantic": ("https://docs.pydantic.dev/latest/", None),
199+
"click": ("https://click.palletsprojects.com/en/latest/", None),
200+
"jinja2": ("https://jinja.palletsprojects.com/en/latest/", None),
201201
}
202202

203203
# -- Options for linkcheck builder --------------------------------------------
204204
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-the-linkcheck-builder
205205

206206
linkcheck_ignore = [
207207
# Ignore links to the internal GitLab server, which may require a VPN or login.
208-
r'https://gitlab\.suse\.de/.*',
208+
r"https://gitlab\.suse\.de/.*",
209209
# Ignore links to local development servers.
210-
r'http://127\.0\.0\.1:\d+/',
211-
r'http://localhost:\d+/',
210+
r"http://127\.0\.0\.1:\d+/",
211+
r"http://localhost:\d+/",
212212
# Ignore mailto links
213-
r'mailto:.*',
213+
r"mailto:.*",
214214
# Ignore settings page as only admins have access
215-
rf'https://github\.com/{gh_user}/{project}/settings/rules',
215+
rf"https://github\.com/{gh_user}/{project}/settings/rules",
216216
# Just ignore useless example URLs
217-
r'https://github\.com/org/repo',
217+
r"https://github\.com/org/repo",
218218
]

src/docbuild/__about__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This module contains metadata about the package, including its version and authors.
44
"""
55

6-
__version__ = '0.14.0'
6+
__version__ = "0.14.0"
77
__authors__ = [
8-
'Tom Schraitle <[email protected]>',
8+
"Tom Schraitle <[email protected]>",
99
]

src/docbuild/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
from .cli.cmd_cli import cli
44

5-
if __name__ == '__main__':
5+
if __name__ == "__main__":
66
cli()

src/docbuild/cli/callback.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Click callback to validate doctype strings."""
2+
13
import logging
24

35
import click
@@ -40,39 +42,39 @@ def validate_doctypes(
4042
except ValueError as err:
4143
click.secho(
4244
f"ERROR: Invalid doctype string '{doctype_str}': {err}",
43-
fg='red',
45+
fg="red",
4446
err=True,
4547
)
4648
raise click.Abort(err) from err
4749

4850
except ValidationError as err:
4951
for error in err.errors():
50-
field = error['loc'][0]
52+
field = error["loc"][0]
5153
# Convert to string to ensure it works as dictionary key
5254
field_name = str(field)
53-
msg = error['msg']
55+
msg = error["msg"]
5456
# Make accessing of .description and .examples safe(r) if
5557
# the definition in Doctype is not present
5658
safe_field = Field(description=None, examples=None)
5759
hint = getattr(
5860
Doctype.model_fields.get(field_name, safe_field),
59-
'description',
61+
"description",
6062
None,
6163
)
6264
examples = getattr(
6365
Doctype.model_fields.get(field_name, safe_field),
64-
'examples',
66+
"examples",
6567
None,
6668
)
6769
click.secho(
6870
f"ERROR in '{field}': {msg}",
69-
fg='red',
71+
fg="red",
7072
err=True,
7173
)
7274
if hint:
73-
click.echo(f' → Hint: {hint}')
75+
click.echo(f" → Hint: {hint}")
7476
if examples:
75-
click.echo(f' → Examples: {", ".join(examples)}')
77+
click.echo(f" → Examples: {', '.join(examples)}")
7678
click.echo()
7779
raise click.Abort(err) from err
7880

0 commit comments

Comments
 (0)