Skip to content

Commit 2b2aadb

Browse files
authored
lint: Add Ruff rules (#283)
1 parent 7eed0f7 commit 2b2aadb

File tree

17 files changed

+52
-31
lines changed

17 files changed

+52
-31
lines changed

pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,27 @@ extend-include = [
154154
"tests/**/*.py",
155155
]
156156

157+
157158
[tool.ruff.lint.pydocstyle]
158159
convention = "google"
159160

160161
[tool.ruff.lint]
161-
extend-select = ["I"]
162+
extend-select = [
163+
"E", # pydecodestyle (errors)
164+
"W", # pydecodestyle (warnings)
165+
"G", # flake8-logging-format
166+
"I", # isort
167+
"LOG", # flake8-logging
168+
"PLE1205", # pylint (too many logging args)
169+
"PLE1206", # pylint (too few logging args)
170+
"TID252", # flake8-tidy-imports (prefer absolute imports)
171+
"C4", # flake8-comprehensions
172+
"B", # flake8-bugbear
173+
]
174+
ignore = [
175+
"E501", # Avoid enforcing line-length violations
176+
"B008", # Argument default function call (incompatible with typer)
177+
]
162178

163179

164180
[tool.ruff.lint.isort]

tests/test_prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ def _do_test_is_headless(envvar: str, value: str | None, expected: bool):
6060
assert is_headless() == expected
6161
finally:
6262
# IMPORTANT: Remove envvar and clear cache after each test
63-
os.environ = _orig_environ # type: ignore
63+
os.environ = _orig_environ # type: ignore # noqa: B003 # I _think_ this is fine?
6464
is_headless.cache_clear()

zabbix_cli/auth.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ def load_auth_token_file(self) -> Union[tuple[Path, str], tuple[None, None]]:
604604
if contents:
605605
return path, contents
606606
logger.info(
607-
f"No auth token file found. Searched in {', '.join(str(p) for p in paths)}"
607+
"No auth token file found. Searched in %s",
608+
{", ".join(str(p) for p in paths)},
608609
)
609610
return None, None
610611

@@ -616,7 +617,7 @@ def load_auth_file(self) -> tuple[Optional[Path], Optional[str]]:
616617
if contents:
617618
return path, contents
618619
logger.info(
619-
f"No auth file found. Searched in {', '.join(str(p) for p in paths)}"
620+
"No auth file found. Searched in %s", {", ".join(str(p) for p in paths)}
620621
)
621622
return None, None
622623

@@ -709,7 +710,7 @@ def write_auth_token_file(
709710

710711
try:
711712
file.write_text(f"{username}::{auth_token}")
712-
logger.info(f"Wrote auth token file {file}")
713+
logger.info("Wrote auth token file %s", file)
713714
except OSError as e:
714715
raise AuthTokenFileError(f"Unable to write auth token file {file}: {e}") from e
715716

zabbix_cli/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def populate(self) -> None:
3535
self._populate_hostgroup_cache()
3636
self._populate_templategroup_cache()
3737
except Exception as e:
38-
raise ZabbixCLIError(f"Failed to populate Zabbix cache: {e}")
38+
raise ZabbixCLIError(f"Failed to populate Zabbix cache: {e}") from e
3939

4040
def _populate_hostgroup_cache(self) -> None:
4141
"""Populates the hostgroup caches with data from the Zabbix API."""

zabbix_cli/commands/proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def load_balance_proxy_hosts(
203203
all_hosts = list(itertools.chain.from_iterable(p.hosts for p in proxies))
204204
if not all_hosts:
205205
exit_err("Proxies have no hosts to load balance.")
206-
logging.debug(f"Found {len(all_hosts)} hosts to load balance.")
206+
logging.debug("Found %d hosts to load balance.", len(all_hosts))
207207

208208
lb_proxies = {
209209
p.proxyid: LBProxy(proxy=p, weight=w) for p, w in zip(proxies, weights)
@@ -226,7 +226,7 @@ def load_balance_proxy_hosts(
226226
"Proxy '%s' has no hosts after balancing.", lb_proxy.proxy.name
227227
)
228228
continue
229-
logging.debug(f"Moving {n_hosts} hosts to proxy {lb_proxy.proxy.name!r}")
229+
logging.debug("Moving %d hosts to proxy %r", n_hosts, lb_proxy.proxy.name)
230230

231231
app.state.client.move_hosts_to_proxy(
232232
hosts=lb_proxy.hosts,

zabbix_cli/commands/usergroup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def sort_ugroups(
5858
try:
5959
return sorted(ugroups, key=lambda ug: int(ug.usrgrpid))
6060
except Exception as e:
61-
logging.error(f"Failed to sort user groups by ID: {e}")
61+
logging.error("Failed to sort user groups by ID: %s", e)
6262
# Fall back on unsorted (likely sorted by ID anyway)
6363
return ugroups
6464

zabbix_cli/config/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ def get(
547547
adapter = _get_type_adapter(type)
548548
return adapter.validate_python(attr)
549549
except AttributeError:
550-
raise ConfigOptionNotFound(f"Plugin configuration key '{key}' not found")
550+
raise ConfigOptionNotFound(
551+
f"Plugin configuration key '{key}' not found"
552+
) from None
551553
except ValidationError as e:
552554
raise PluginConfigTypeError(
553555
f"Plugin config key '{key}' failed to validate as type {type}: {e}"

zabbix_cli/output/formatting/dates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from datetime import datetime
44

5-
from ...logs import logger
6-
from .constants import NONE_STR
5+
from zabbix_cli.logs import logger
6+
from zabbix_cli.output.formatting.constants import NONE_STR
77

88

99
def datetime_str(

zabbix_cli/pyzabbix/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def parse_name_or_id_arg(
167167

168168
# If we have a wildcard, we can omit names or IDs entirely
169169
if "*" in names_or_ids:
170-
names_or_ids = tuple()
170+
names_or_ids = ()
171171

172172
if len(names_or_ids) > 1:
173173
logger.debug(

zabbix_cli/pyzabbix/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def get_port(self: InterfaceType) -> str:
315315
try:
316316
return self.value.metadata["port"]
317317
except KeyError:
318-
raise ZabbixCLIError(f"Unknown interface type: {self}")
318+
raise ZabbixCLIError(f"Unknown interface type: {self}") from None
319319

320320

321321
class InventoryMode(APIStrEnum):

0 commit comments

Comments
 (0)