Skip to content

Commit

Permalink
Switch to Ruff for formatting/linting
Browse files Browse the repository at this point in the history
TODO: update GitHub CI
  • Loading branch information
smsearcy committed Jun 5, 2024
1 parent 6d3ab6f commit 1811dcd
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 154 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ indent_size = 2
[*.rst]
indent_style = space
indent_size = 3

[*.toml]
indent_style = space
indent_size = 4
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

23 changes: 16 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version (should be consistent with `pdm.lock`
rev: v0.4.6
hooks:
- id: black
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/pdm-project/pdm
rev: 2.15.4
hooks:
- id: isort
# Ensure lock file is consistent with pyproject.toml
- id: pdm-lock-check
# Export python requirements
- id: pdm-export
args: ['-o', 'requirements.txt', '--without-hashes']
files: ^pdm.lock$
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pre-commit:
pre-commit run --all-files

lint:
flake8 meshinfo tests
ruff check . --fix
ruff format .

mypy:
mypy meshinfo tests
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# -- Project information -----------------------------------------------------

project = "Mesh Info"
copyright = "2022, Scott Searcy"
copyright = "Scott Searcy" # noqa: A001
author = "Scott Searcy"

# The full version, including alpha/beta/rc tags
Expand Down
5 changes: 2 additions & 3 deletions meshinfo/aredn.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ def primary_interface(self) -> Optional[Interface]:
if iface not in self.interfaces or not self.interfaces[iface].ip_address:
continue
return self.interfaces[iface]
else:
logger.warning("Unable to identify wireless interface")
return None
logger.warning("Unable to identify wireless interface")
return None

@property
def ip_address(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions meshinfo/backup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functionality for exporting and importing application data."""

from __future__ import annotations

import re
Expand Down
3 changes: 2 additions & 1 deletion meshinfo/collector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Repeatedly collects data about the network and stores it to the database."""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -155,7 +156,7 @@ async def collector(
except RuntimeError:
raise ConnectionError(
f"Failed to connect to OLSR daemon on {local_node} for network data"
)
) from None

poller_finished = time.monotonic()
poller_elapsed = poller_finished - start_time
Expand Down
3 changes: 2 additions & 1 deletion meshinfo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def configure(
configure_logging(app_config.log_level)

logger.debug(
"Application configuration", **attrs.asdict(app_config) # type: ignore
"Application configuration",
**attrs.asdict(app_config), # type: ignore
)

# configure Pyramid application
Expand Down
3 changes: 2 additions & 1 deletion meshinfo/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration of SQLAlchemy database, copied from Pyramid Cookiecutter."""

from __future__ import annotations

import contextlib
Expand Down Expand Up @@ -75,7 +76,7 @@ def get_tm_session(session_factory, transaction_manager, request=None):
"info" dict. The "info" dict is the official namespace for developers to
stash session-specific information. For more information, please see the
SQLAlchemy docs:
https://docs.sqlalchemy.org/en/stable/orm/session_api.html#sqlalchemy.orm.session.Session.params.info # noqa
https://docs.sqlalchemy.org/en/stable/orm/session_api.html#sqlalchemy.orm.session.Session.params.info
By placing the active ``request`` in the "info" dict, developers will be
able to access the active Pyramid request from an instance of an SQLAlchemy
Expand Down
2 changes: 1 addition & 1 deletion meshinfo/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def datagram_received(self, data, addr):
self.transport.close()

def error_received(self, exc):
logger.warning("Error received: {!r}", exc)
logger.warning("Error received", error=exc)

def connection_lost(self, exc):
self.on_con_lost.set_result(self.received)
Expand Down
1 change: 1 addition & 0 deletions meshinfo/pshell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration for Pyramid's interactive pshell."""

from . import models


Expand Down
1 change: 1 addition & 0 deletions meshinfo/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This process polls the network and displays the results to the user."""

from __future__ import annotations

import asyncio
Expand Down
4 changes: 2 additions & 2 deletions meshinfo/views/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def graph_params(params: dict) -> GraphParams:

try:
period = getattr(Period, params["period"].upper())
except KeyError:
raise HTTPBadRequest("Invalid period for graph")
except KeyError as err:
raise HTTPBadRequest("Invalid period for graph") from err
title = f"past {params['period'].lower()}"

return GraphParams(
Expand Down
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 46 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ build-backend = "pdm.backend"
name = "mesh-info"
description = "Collect and display information about an AREDN mesh network."
readme = "README.rst"
authors = [{name = "Scott Seary", email = "[email protected]"}]
authors = [{ name = "Scott Seary", email = "[email protected]" }]
requires-python = ">=3.9"
license = {text = "GNU General Public License v3 (GPLv3)"}
license = { text = "GNU General Public License v3 (GPLv3)" }
keywords = ["aredn", "mesh"]
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
dependencies = [
"aiohttp ~= 3.9.5",
Expand Down Expand Up @@ -49,11 +49,6 @@ Documentation = "https://mesh-info-ki7onk.readthedocs.io/"
[project.scripts]
meshinfo = "meshinfo.cli:main"

[tool.isort]
profile = "black"
known_third_party = "alembic"

[tool.pdm]
[tool.pdm.dev-dependencies]
testing = [
"Faker>=25.3.0",
Expand All @@ -76,3 +71,42 @@ ruff = [
mypy = [
"mypy>=1.10.0",
]

[tool.ruff]
target-version = "py39"

[tool.ruff.format]
exclude = ["alembic/versions/*.py"]

[tool.ruff.lint]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear"
"C4", # flake8-comprehensions
"C90", # mccabe
"E", "W", # pycodestyle
"F", # pyflakes
"I", # isort
"N", # pep8-naming
"PLC", "PLE", "PLW", # "PLR" # pylint
"YTT", # flake8-2020
# "D", # pydocstyle
# "RET", # flake8-return
# "SIM", # flake8-simplify
# "UP", # pyupgrade
]
ignore = [
"A003", # builtin-attribute-shadowing
"C416", # unnecessary `dict` comprehension
"D105", # magic-method
"D107", # public-init
"D203", # one-blank-line-before-class
"D213", # multi-line-summary-second-line
"PLR2004", # magic-value-comparison
]

[tool.ruff.lint.isort]
known-third-party = ["alembic"]

[tool.ruff.lint.mccabe]
max-complexity = 12
Loading

0 comments on commit 1811dcd

Please sign in to comment.