Ask for what is needed, and nothing that is not

An audit of the dependencies rather than a feature, prompted by being asked to
make sure they were all listed.  Four things were wrong, and one of them was
wrong in the direction nobody checks.

A dependency that was not one.  The packaging asked for matplotlib, in a
"plots" extra, and nothing in the program has ever imported it: the graphs a
weather log turns into are drawn by this package's own PNG writer, the same one
the waterfalls and the maps use.  Anybody installing with that extra got a
large package to no effect.  Declarations are checked against imports in one
direction as a matter of course -- an undeclared import fails on the first
machine that is not the one it was written on -- and never in the other, where
the failure is silent and costs somebody else's disk.

Two speech engines that could not be installed.  The transcriber takes five
engines and the metadata offered extras for two of them, so openai-whisper and
pocketsphinx were supported and unobtainable.  They are alternatives rather
than a set -- one is tiny and poor, one is the reference and slow -- so each has
an extra of its own now.

Nothing that can play a recording.  The package suggested no audio player at
all, so on a fresh install saunterbrowse's Enter key did nothing and there was
no way to find out why.  Recommended now, as any one of the three things that
provide pw-play, paplay or aplay.

Nothing that can open a map.  The register's g key hands a coordinate to a
browser, which needs something to start one; xdg-utils is suggested and the
absence documented, since printing the coordinates instead is the useful answer
on a headless receiver anyway.

And the readme's list of audio players was simply wrong -- it named sox, left
out mpv, and had the order it does not try them in.  It is generated from the
table the code actually uses now.

Checked complete rather than assumed: the manual covers all seventeen
subcommands, and the package ships every module, both manuals, the copyright,
the readme and the install instructions.

Nine tests so none of it drifts again, each confirmed by putting the defect
back.  The pair that matters checks the dependencies both ways: everything
imported has to be asked for, and everything asked for has to be imported.  The
second of those is the one that had never existed, and is the one that would
have caught matplotlib years ago.

Full suite 2901 passed.  Built as 2026-09-25_01.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016PsWPTweCT6pwxKngvVxcg
This commit is contained in:
The Dust Council 2026-09-25 08:29:20 -07:00
commit c3b382a5f6
8 changed files with 186 additions and 10 deletions

View file

@ -319,3 +319,164 @@ def test_the_tile_server_is_told_where_to_look_this_program_up():
assert "bandsaunter/" in USER_AGENT
assert REPOSITORY in USER_AGENT
assert bandsaunter.__version__ in USER_AGENT
# ---------------------------------------------------------------------------
# What it needs to run
# ---------------------------------------------------------------------------
# Import name to the name of the thing that provides it. Not derivable:
# "yaml" comes from PyYAML and "faster_whisper" from faster-whisper, and
# nothing in an import statement says so.
PROVIDES = {
"numpy": "numpy",
"scipy": "scipy",
"rich": "rich",
"yaml": "PyYAML",
"faster_whisper": "faster-whisper",
"whisper": "openai-whisper",
"vosk": "vosk",
"pocketsphinx": "pocketsphinx",
}
def _imported() -> set:
"""Every third-party module the package imports, anywhere."""
import ast
import sys
out = set()
for path in sorted((ROOT / "bandsaunter").glob("*.py")):
for node in ast.walk(ast.parse(path.read_text())):
names = []
if isinstance(node, ast.Import):
names = [a.name.split(".")[0] for a in node.names]
elif isinstance(node, ast.ImportFrom) and node.level == 0 \
and node.module:
names = [node.module.split(".")[0]]
for name in names:
if name not in sys.stdlib_module_names \
and name != "bandsaunter":
out.add(name)
return out
def _declared() -> set:
"""Every distribution the packaging metadata asks for, lower-cased."""
import tomllib
body = tomllib.load(open(ROOT / "pyproject.toml", "rb"))["project"]
wanted = list(body.get("dependencies") or [])
for extra in (body.get("optional-dependencies") or {}).values():
wanted.extend(extra)
out = set()
for spec in wanted:
out.add(re.split(r"[<>=!~\[ ]", spec, 1)[0].strip().lower())
return out
def test_everything_the_code_imports_is_asked_for_somewhere():
"""An undeclared import is an installation that works on the machine it
was written on and nowhere else."""
missing = []
for name in sorted(_imported()):
provider = PROVIDES.get(name)
assert provider is not None, (
f"{name} is imported and this test does not know what provides "
f"it -- add it to PROVIDES")
if provider.lower() not in _declared():
missing.append(f"{name} (from {provider})")
assert not missing, f"imported but never declared: {missing}"
def test_nothing_is_asked_for_that_the_code_never_imports():
"""The other direction, which is how a "plots" extra sat in the metadata
asking for matplotlib that nothing had ever imported: a large dependency
installed to no effect, and nothing to notice."""
# The tooling extras are not imported by the package and are not meant
# to be; everything else has to be.
tools = {"pytest", "pyte"}
imported = {PROVIDES[n].lower() for n in _imported() if n in PROVIDES}
stale = sorted(_declared() - imported - tools - {"pyqt6"})
assert not stale, f"declared but never imported: {stale}"
def test_the_window_bindings_the_code_accepts_are_the_ones_documented():
"""Four bindings work, because distributions disagree about which they
ship. The metadata can only name one, so the documentation has to name
the rest or three of them are a secret."""
from bandsaunter.livemap import BINDINGS
body = (ROOT / "INSTALL.md").read_text()
for binding in BINDINGS:
assert binding in body, f"{binding} works and is not documented"
def test_every_player_the_browser_will_use_is_named_in_the_readme():
"""The list said sox and ffplay and left out mpv, and had the order
wrong. A list of what to install is no use if it is not the list."""
from bandsaunter.browse import PLAYERS
body = README.read_text()
for name, _args in PLAYERS:
assert f"`{name}`" in body, f"{name} is used and not documented"
def test_every_engine_the_transcriber_will_use_is_documented():
from bandsaunter.transcribe import ENGINES
body = (ROOT / "INSTALL.md").read_text()
for engine in ENGINES:
assert engine in body, f"{engine} is an engine and is not documented"
def test_the_speech_engines_the_code_can_import_are_all_installable():
"""Each is an alternative rather than part of a set, so each has an
extra of its own."""
import tomllib
body = tomllib.load(open(ROOT / "pyproject.toml", "rb"))["project"]
extras = body.get("optional-dependencies") or {}
joined = " ".join(" ".join(v) for k, v in extras.items()
if k.startswith("transcribe")).lower()
for provider in ("faster-whisper", "openai-whisper", "vosk",
"pocketsphinx"):
assert provider in joined, f"no extra installs {provider}"
def test_the_package_asks_for_what_it_needs_to_be_useful():
"""The control file, which is the only dependency list apt reads."""
body = (ROOT / "packaging" / "build-deb.sh").read_text()
control = body[body.index("Package: bandsaunter"):]
# Hard requirements: without any of these it cannot start or cannot see
# a dongle.
for need in ("python3-numpy", "python3-scipy", "python3-rich",
"python3-yaml", "librtlsdr0"):
assert need in control, f"{need} is not in Depends"
# And the things that make it do everything it can do.
for offer in ("espeak-ng", "ffmpeg", "python3-pyqt6", "xdg-utils"):
assert offer in control, f"{offer} is not suggested or recommended"
# Something that can play a recording, or saunterbrowse's Enter key
# does nothing at all.
assert any(p in control for p in ("pipewire-bin", "pulseaudio-utils",
"alsa-utils")), \
"nothing that can play a recording is asked for"
def test_the_manual_covers_every_command_the_program_takes():
"""A subcommand that is not in the manual is one nobody finds."""
from bandsaunter.cli import build_parser
page = (ROOT / "packaging" / "bandsaunter.1").read_text()
commands = build_parser()._subparsers._group_actions[0].choices
for name in commands:
assert name in page, f"{name} is a command and is not in the manual"
def test_the_package_ships_both_manuals_and_the_readme():
"""Checked against the build script rather than a built package, so it
holds on a machine that has not built one."""
body = (ROOT / "packaging" / "build-deb.sh").read_text()
for wanted in ("bandsaunter.1", "saunterbrowse.1", "README.md",
"INSTALL.md", "copyright"):
assert wanted in body, f"{wanted} is not installed by the package"