fix: refactor some more for tests + pylint
This commit is contained in:
parent
7573cedf6e
commit
890adbad63
9 changed files with 42 additions and 17 deletions
4
.pylintrc
Normal file
4
.pylintrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
# -*- mode: conf; -*-
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
disable=fixme
|
|
@ -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
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ dependencies = [
|
|||
|
||||
[project.optional-dependencies]
|
||||
docs = ["Sphinx", "furo"]
|
||||
tests = ["pytest-cov", "tox"]
|
||||
tests = ["pylint", "pytest", "pytest-cov", "tox"]
|
||||
|
||||
|
||||
[project.urls]
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Package Version
|
||||
"""
|
||||
|
||||
from importlib.metadata import version
|
||||
|
||||
|
|
|
@ -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}")
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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)]
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
4
tox.ini
4
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue