switch project to pyproject.toml and update tox.ini

This commit is contained in:
Walter Boring 2026-01-16 13:35:44 -05:00
parent c71a7d3598
commit 93095879b9
9 changed files with 114 additions and 66 deletions

View File

@ -1,23 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-json
- id: detect-private-key
- id: check-merge-conflict
- id: check-case-conflict
- id: check-docstring-first
- id: check-builtin-literals
- id: check-illegal-windows-names
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.16.0
rev: v2.7.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/dizballanze/gray
rev: v0.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
hooks:
- id: gray
###### Relevant part below ######
- id: ruff-check
types_or: [python, pyi]
args: ["check", "--select", "I", "--fix"]
###### Relevant part above ######
- id: ruff-format
types_or: [python, pyi]

View File

@ -12,5 +12,4 @@
import pbr.version
__version__ = pbr.version.VersionInfo("aprsd_weewx_plugin").version_string()

View File

@ -2,6 +2,5 @@ from oslo_config import cfg
from aprsd_weewx_plugin.conf import weewx
CONF = cfg.CONF
weewx.register_opts(CONF)

View File

@ -31,7 +31,6 @@ import importlib
import os
import pkgutil
LIST_OPTS_FUNC_NAME = "list_opts"
@ -64,9 +63,10 @@ def _import_modules(module_names):
for modname in module_names:
mod = importlib.import_module("aprsd_weewx_plugin.conf." + modname)
if not hasattr(mod, LIST_OPTS_FUNC_NAME):
msg = "The module 'aprsd_weewx_plugin.conf.%s' should have a '%s' "\
"function which returns the config options." % \
(modname, LIST_OPTS_FUNC_NAME)
msg = (
"The module 'aprsd_weewx_plugin.conf.%s' should have a '%s' "
"function which returns the config options." % (modname, LIST_OPTS_FUNC_NAME)
)
raise Exception(msg)
else:
imported_modules.append(mod)

View File

@ -1,6 +1,5 @@
from oslo_config import cfg
weewx_group = cfg.OptGroup(
name="aprsd_weewx_plugin",
title="APRSD Weewx Plugin settings",
@ -44,10 +43,7 @@ weewx_mqtt_opts = [
),
]
ALL_OPTS = (
weewx_opts +
weewx_mqtt_opts
)
ALL_OPTS = weewx_opts + weewx_mqtt_opts
def register_opts(cfg):

View File

@ -1,4 +1,5 @@
"""Main module."""
import datetime
import json
import logging
@ -7,19 +8,17 @@ import time
import paho.mqtt.client as mqtt
from aprsd import plugin, threads
from aprsd.threads import tx
from aprsd.packets import core
from aprsd.threads import tx
from oslo_config import cfg
from aprsd_weewx_plugin import conf # noqa
CONF = cfg.CONF
LOG = logging.getLogger("APRSD")
class ClearableQueue(queue.Queue):
def clear(self):
try:
while True:
@ -69,10 +68,7 @@ class WeewxMQTTPlugin(plugin.APRSDRegexCommandPluginBase):
# if we have position and a callsign to report
# Then we can periodically report weather data
# to APRS
if (
CONF.aprsd_weewx_plugin.latitude and
CONF.aprsd_weewx_plugin.longitude
):
if CONF.aprsd_weewx_plugin.latitude and CONF.aprsd_weewx_plugin.longitude:
LOG.info("Creating WeewxWXAPRSThread")
wx_thread = WeewxWXAPRSThread(
wx_queue=self.wx_queue,
@ -219,7 +215,7 @@ class WeewxMQTTThread(threads.APRSDThread):
self.wx_queue.put(wx_data)
def stop(self):
LOG.info(__class__.__name__+" Stop")
LOG.info(__class__.__name__ + " Stop")
self.thread_stop = True
LOG.info("Stopping loop")
self.client.loop_stop()
@ -263,7 +259,9 @@ class WeewxWXAPRSThread(threads.APRSDThread):
hundredths = round(seconds / 60, 2)
return {
"degrees": degrees, "minutes": minutes, "seconds": seconds,
"degrees": degrees,
"minutes": minutes,
"seconds": seconds,
"hundredths": hundredths,
}

74
pyproject.toml Normal file
View File

@ -0,0 +1,74 @@
[build-system]
requires = ["setuptools>=45", "wheel", "pbr"]
build-backend = "setuptools.build_meta"
[project]
name = "aprsd_weewx_plugin"
dynamic = ["version"]
description = "HAM Radio APRSD that reports weather from a weewx weather station."
readme = "README.rst"
requires-python = ">=3.11"
license = {text = "GPL-3.0"}
authors = [
{name = "Walter A. Boring IV", email = "waboring@hemna.com"}
]
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Topic :: Communications :: Ham Radio",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
]
dependencies = [
"pbr",
"aprsd>=3.0.0",
"paho-mqtt",
"oslo-config",
]
[project.optional-dependencies]
dev = [
"pip",
"pip-tools",
"bump2version",
"wheel",
"watchdog",
"ruff",
"tox",
"tox-uv",
"coverage",
"Sphinx",
"twine",
"pytest",
"uv",
]
[project.entry-points."oslo.config.opts"]
"aprsd_weewx_plugin.conf" = "aprsd_weewx_plugin.conf.opts:list_opts"
[tool.setuptools]
packages = ["aprsd_weewx_plugin"]
[tool.setuptools.package-data]
"*" = ["LICENSE"]
[tool.setuptools.dynamic]
# Version is provided by pbr via setup hooks
# PBR will set __version__ in aprsd_weewx_plugin.__init__ during setup
version = {attr = "aprsd_weewx_plugin.__version__"}
[tool.pbr]
# PBR configuration - version is managed by pbr from git tags
# PBR uses setup hooks to inject version dynamically
[tool.ruff]
line-length = 99
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I", "N", "W"]
ignore = ["E203"] # Ignore whitespace before ':' (required by formatter)
[tool.mypy]
ignore_missing_imports = true
strict = true

View File

@ -1,4 +1,3 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -15,13 +14,4 @@
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(setup_requires=["pbr"], pbr=True)
setuptools.setup()

42
tox.ini
View File

@ -4,27 +4,16 @@
envlist =
fmt
lint
py{37,38,39}
py311
skip_missing_interpreters = true
[flake8]
# Use the more relaxed max line length permitted in PEP8.
max-line-length = 99
# This ignore is required by black.
extend-ignore = E203
extend-exclude =
venv
requires = tox-uv>=0.4.0
# This is the configuration for the tox-gh-actions plugin for GitHub Actions
# https://github.com/ymyzk/tox-gh-actions
# This section is not needed if not using GitHub Actions for CI.
[gh-actions]
python =
3.7: py37
3.8: py38, fmt, lint
3.9: py39
3.11: py311, fmt, lint
# Activate isolated build environment. tox will use a virtual environment
# to build a source distribution from the source tree. For build tools and
@ -32,34 +21,30 @@ python =
isolated_build = true
[testenv]
package = uv-editable
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
pytest
commands =
# Use -bb to enable BytesWarnings as error to catch str/bytes misuse.
# Use -Werror to treat warnings as errors.
{envpython} -bb -Werror -m pytest {posargs}
uv run pytest tests {posargs}
[testenv:type-check]
skip_install = true
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
mypy
commands =
mypy src tests
[testenv:lint]
skip_install = true
deps =
-r{toxinidir}/requirements-dev.txt
ruff
commands =
flake8 aprsd_weewx_plugin tests
ruff check aprsd_weewx_plugin tests
[testenv:docs]
skip_install = true
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
Sphinx
changedir = {toxinidir}/docs
commands =
{envpython} clean_docs.py
@ -69,15 +54,16 @@ commands =
[testenv:fmt]
skip_install = true
deps =
-r{toxinidir}/requirements-dev.txt
ruff
commands =
gray aprsd_weewx_plugin tests
ruff check --fix aprsd_weewx_plugin tests
ruff format aprsd_weewx_plugin tests
[testenv:licenses]
skip_install = true
recreate = true
deps =
-r{toxinidir}/requirements.txt
-e {toxinidir}
pip-licenses
commands =
pip-licenses {posargs}