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

Update linters #979

Merged
merged 5 commits into from
Jun 12, 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
5 changes: 5 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ lint.select = [
'ALL',
]

lint.exclude = [
# exclude any hello/sample scripts
'Hello.py',
]

lint.ignore = [
# we do not type annotate everything at this time
'ANN',
Expand Down
8 changes: 4 additions & 4 deletions sphinxcontrib/confluencebuilder/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def add(self, path, docname):
Returns:
the key, document name and path
"""
logger.verbose('adding manual attachment: %s' % path)
logger.verbose(f'adding manual attachment: {path}')
abs_path = find_env_abspath(self.env, self.out_dir, path)
return self._handle_entry(abs_path, docname, standalone=True)

Expand Down Expand Up @@ -219,7 +219,7 @@ def process_file_node(self, node, docname, standalone=False):

target = node['reftarget']
if target.find('://') == -1:
logger.verbose('process file node: %s' % target)
logger.verbose(f'process file node: {target}')
path = self._interpret_asset_path(node)
if path:
return self._handle_entry(path, docname, standalone)
Expand All @@ -245,7 +245,7 @@ def process_image_node(self, node, docname, standalone=False):

uri = str(node['uri'])
if not uri.startswith('data:') and uri.find('://') == -1:
logger.verbose('process image node: %s' % uri)
logger.verbose(f'process image node: {uri}')
path = self._interpret_asset_path(node)
if path:
return self._handle_entry(path, docname, standalone)
Expand Down Expand Up @@ -344,7 +344,7 @@ def _interpret_asset_path(self, node):
abs_path = find_env_abspath(self.env, self.out_dir, path)

if not abs_path:
logger.verbose('failed to find path: %s' % path)
logger.verbose(f'failed to find path: {path}')

return abs_path

Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/config/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def conf_translate(value):
# ##################################################################

# confluence_publish_debug
opts = PublishDebug._member_names_ # noqa: SLF001 pylint: disable=no-member
opts = PublishDebug._member_names_ # pylint: disable=no-member
try:
validator.conf('confluence_publish_debug').bool() # deprecated
except ConfluenceConfigError:
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def apply_env_overrides(builder):
env_key = key.upper()
env_val = os.getenv(env_key)
if env_val:
logger.verbose('accepting configuration from env: %s' % env_val)
logger.verbose(f'accepting configuration from env: {env_val}')

if key in config_manager.options_bool:
conf[key] = str2bool(env_val)
Expand Down
4 changes: 2 additions & 2 deletions sphinxcontrib/confluencebuilder/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def trace(container, data):
try:
trace_file = Path('trace.log')
with trace_file.open('a', encoding='utf-8') as file:
file.write('[%s]\n' % container)
file.write(f'[{container}]\n')
file.write(data)
file.write('\n')
except OSError as err:
ConfluenceLogger.warn('unable to trace: %s' % err)
ConfluenceLogger.warn(f'unable to trace: {err}')
4 changes: 2 additions & 2 deletions sphinxcontrib/confluencebuilder/singlebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _register_doctree_title_targets(self, docname, doctree):
secnumbers = self.env.toc_secnumbers.get(self.config.root_doc, {})

docref_set = False
doc_anchorname = '%s/' % docname
doc_anchorname = f'{docname}/'
root_section = None
title_node = self._find_title_element(doctree)
if title_node:
Expand All @@ -216,7 +216,7 @@ def _register_doctree_title_targets(self, docname, doctree):

anchorname = f'{docname}/#{id_}'
if anchorname not in secnumbers:
anchorname = '%s/' % id_
anchorname = f'{id_}/'

if self.add_secnumbers:
secnumber = secnumbers.get(anchorname)
Expand Down
4 changes: 2 additions & 2 deletions sphinxcontrib/confluencebuilder/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def register_title(docname, title, config):
base_tail += postfix

if len(title) + len(base_tail) > try_max:
warning = 'document title has been trimmed due to length: %s' % title
warning = f'document title has been trimmed due to length: {title}'
if len(base_tail) > 0:
warning += '; With postfix: %s' % base_tail
warning += f'; With postfix: {base_tail}'
logger.warn(warning)
title = title[0:try_max - len(base_tail)]

Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/confluencebuilder/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def confluence_supported_svg(builder, node):
with abs_path.open('rb') as f:
svg_data = f.read()
except OSError as err:
builder.warn('error reading svg: %s' % err)
builder.warn(f'error reading svg: {err}')
return

modified = False
Expand Down Expand Up @@ -196,15 +196,15 @@ def confluence_supported_svg(builder, node):

# write the new svg file (if needed)
if not out_file.is_file():
logger.verbose('generating compatible svg of: %s' % uri)
logger.verbose(f'generating compatible svg of: {uri}')
logger.verbose(f'generating compatible svg to: {out_file}')

out_file.parent.mkdir(parents=True, exist_ok=True)
try:
with out_file.open('wb') as f:
f.write(svg_data)
except OSError as err:
builder.warn('error writing svg: %s' % err)
builder.warn(f'error writing svg: {err}')
return

# replace the required node attributes
Expand Down
8 changes: 4 additions & 4 deletions sphinxcontrib/confluencebuilder/transmute/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright Sphinx Confluence Builder Contributors (AUTHORS)

from contextlib import suppress
from docutils import nodes
from sphinx.util.math import wrap_displaymath
from sphinxcontrib.confluencebuilder.compat import docutils_findall as findall
Expand Down Expand Up @@ -32,11 +33,10 @@
imgmath = None

# load inheritance_diagram extension if available to handle node pre-processing
inheritance_diagram = None
if graphviz:
try:
with suppress(ImportError):
from sphinx.ext import inheritance_diagram
except ImportError:
inheritance_diagram = None


def doctree_transmute(builder, doctree):
Expand Down Expand Up @@ -272,7 +272,7 @@ def __init__(self, builder):
graph = node['graph']

graph_hash = inheritance_diagram.get_graph_hash(node)
name = 'inheritance%s' % graph_hash
name = f'inheritance{graph_hash}'

dotcode = graph.generate_dot(name, {}, env=builder.env)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,5 @@ def __init__(self, builder):

node.replace_self(new_container)
except DiagramsError as exc:
ConfluenceLogger.warn(
'diagrams code %r: ' % node['code'] + str(exc))
ConfluenceLogger.warn('diagrams code %r: %s', node['code'], exc)
node.parent.remove(node)
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ def __init__(self, builder):
new_node['align'] = node['align']
node.replace_self(new_node)
except MermaidError as exc:
ConfluenceLogger.warn('mermaid code %r: ' % node['code'] + str(exc))
ConfluenceLogger.warn('mermaid code %r: %s', node['code'], exc)
node.parent.remove(node)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ usedevelop = false
[testenv:pylint]
deps =
{[testenv]deps}
pylint
pylint: pylint==3.2.3
commands =
pylint \
sphinxcontrib \
Expand All @@ -58,7 +58,7 @@ commands =
[testenv:ruff]
deps =
{[testenv]deps}
ruff: ruff==0.3.4
ruff: ruff==0.4.8
setenv =
{[testenv]setenv}
RUFF_CACHE_DIR={toxworkdir}/.ruff_cache
Expand Down