diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..7eb5e2c --- /dev/null +++ b/.pylintrc @@ -0,0 +1,4 @@ +# -*- mode: conf; -*- + +[MESSAGES CONTROL] +disable=fixme diff --git a/docs/index.rst b/docs/index.rst index fc968b5..a779fbc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -17,6 +17,9 @@ project. .. _test coverage: https://buildbot.rattailproject.org/coverage/wuttamess/ +.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen + :target: https://github.com/pylint-dev/pylint + .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black diff --git a/pyproject.toml b/pyproject.toml index 5015f74..7d69a1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ [project.optional-dependencies] docs = ["Sphinx", "furo"] -tests = ["pytest-cov", "tox"] +tests = ["pylint", "pytest", "pytest-cov", "tox"] [project.urls] diff --git a/src/wuttamess/_version.py b/src/wuttamess/_version.py index 96c91a0..c4cb30e 100644 --- a/src/wuttamess/_version.py +++ b/src/wuttamess/_version.py @@ -1,4 +1,7 @@ # -*- coding: utf-8; -*- +""" +Package Version +""" from importlib.metadata import version diff --git a/src/wuttamess/apt.py b/src/wuttamess/apt.py index df584a4..d8351b6 100644 --- a/src/wuttamess/apt.py +++ b/src/wuttamess/apt.py @@ -2,7 +2,7 @@ ################################################################################ # # WuttaMess -- Fabric Automation Helpers -# Copyright © 2024 Lance Edgar +# Copyright © 2024-2025 Lance Edgar # # This file is part of Wutta Framework. # @@ -75,7 +75,9 @@ def update(c): c.run("apt-get update") -def upgrade(c, dist_upgrade=False, frontend="noninteractive"): +def upgrade( # pylint: disable=redefined-outer-name + c, dist_upgrade=False, frontend="noninteractive" +): """ Upgrade packages via APT. Essentially this runs: @@ -89,6 +91,9 @@ def upgrade(c, dist_upgrade=False, frontend="noninteractive"): """ options = "" if frontend == "noninteractive": - options = '--option Dpkg::Options::="--force-confdef" --option Dpkg::Options::="--force-confold"' + options = ( + '--option Dpkg::Options::="--force-confdef" ' + '--option Dpkg::Options::="--force-confold"' + ) upgrade = "dist-upgrade" if dist_upgrade else "upgrade" c.run(f"DEBIAN_FRONTEND={frontend} apt-get --assume-yes {options} {upgrade}") diff --git a/src/wuttamess/postgres.py b/src/wuttamess/postgres.py index 8416a58..0cd3b97 100644 --- a/src/wuttamess/postgres.py +++ b/src/wuttamess/postgres.py @@ -2,7 +2,7 @@ ################################################################################ # # WuttaMess -- Fabric Automation Helpers -# Copyright © 2024 Lance Edgar +# Copyright © 2024-2025 Lance Edgar # # This file is part of Wutta Framework. # @@ -25,13 +25,13 @@ PostgreSQL DB utilities """ -def sql(c, sql, database="", port=None, **kwargs): +def sql(c, sql_, database="", port=None, **kwargs): """ Execute some SQL as the ``postgres`` user. :param c: Fabric connection. - :param sql: SQL string to execute. + :param sql_: SQL string to execute. :param database: Name of the database on which to execute the SQL. If not specified, default ``postgres`` is assumed. @@ -40,7 +40,7 @@ def sql(c, sql, database="", port=None, **kwargs): """ port = f" --port={port}" if port else "" return c.sudo( - f'psql{port} --tuples-only --no-align --command="{sql}" {database}', + f'psql{port} --tuples-only --no-align --command="{sql_}" {database}', user="postgres", **kwargs, ) diff --git a/src/wuttamess/sync.py b/src/wuttamess/sync.py index 24b9165..db566e6 100644 --- a/src/wuttamess/sync.py +++ b/src/wuttamess/sync.py @@ -2,7 +2,7 @@ ################################################################################ # # WuttaMess -- Fabric Automation Helpers -# Copyright © 2024 Lance Edgar +# Copyright © 2024-2025 Lance Edgar # # This file is part of Wutta Framework. # @@ -84,7 +84,7 @@ def isync(c, root, selector=None, tags=None, echo=True, **kwargs): should be echoed to stdout. Generally thought to be useful but may be disabled. - :param \**kwargs: Any remaining kwargs are passed as-is to + :param \\**kwargs: Any remaining kwargs are passed as-is to :func:`fabsync:fabsync.isync()`. """ if selector: @@ -111,4 +111,6 @@ def check_isync(c, root, selector=None, **kwargs): :returns: ``True`` if any sync result indicates a file was modified; otherwise ``False``. """ - return any([result.modified for result in isync(c, root, selector, **kwargs)]) + return any( # pylint: disable=use-a-generator + [result.modified for result in isync(c, root, selector, **kwargs)] + ) diff --git a/src/wuttamess/util.py b/src/wuttamess/util.py index e201c3e..b9aa1b3 100644 --- a/src/wuttamess/util.py +++ b/src/wuttamess/util.py @@ -2,7 +2,7 @@ ################################################################################ # # WuttaMess -- Fabric Automation Helpers -# Copyright © 2024 Lance Edgar +# Copyright © 2024-2025 Lance Edgar # # This file is part of Wutta Framework. # @@ -24,8 +24,9 @@ Misc. Utilities """ +from collections.abc import Mapping from pathlib import Path -from typing_extensions import Any, Mapping +from typing_extensions import Any from mako.template import Template @@ -65,12 +66,12 @@ def is_symlink(c, path): :returns: ``True`` if path is a symlink, else ``False``. """ # nb. this function is derived from one copied from fabric v1 - cmd = 'test -L "$(echo %s)"' % path + cmd = f'test -L "$(echo {path})"' result = c.run(cmd, warn=True) - return False if result.failed else True + return not result.failed -def mako_renderer(c, env={}): +def mako_renderer(c, env=None): # pylint: disable=unused-argument """ This returns a *function* suitable for use as a ``fabsync`` file renderer. The function assumes the file is a Mako template. @@ -96,8 +97,11 @@ def mako_renderer(c, env={}): sync.check_isync(c, root, 'etc/postfix', renderers=renderers) """ + env = env or {} - def render(path: Path, vars: Mapping[str, Any], **kwargs) -> bytes: + def render( # pylint: disable=redefined-builtin,unused-argument + path: Path, vars: Mapping[str, Any], **kwargs + ) -> bytes: return Template(filename=str(path)).render(**env) return render diff --git a/tox.ini b/tox.ini index 63cbdde..ce3b1da 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,10 @@ envlist = py38, py39, py310, py311 extras = tests commands = pytest {posargs} +[testenv:pylint] +basepython = python3.11 +commands = pylint wuttamess + [testenv:coverage] basepython = python3.11 commands = pytest --cov=wuttamess --cov-report=html --cov-fail-under=100