wads.install_system_deps¶
Install system dependencies from [tool.wads.ops.*] sections in pyproject.toml.
This script reads system dependency configurations and installs them on the appropriate platform. It can be used as a standalone CLI tool or imported as a module.
Each [tool.wads.ops.<dep>] section may declare an install_timeout (seconds)
to raise the per-command ceiling for a dependency that is slow but healthy — a
cold-cache apt-get install ffmpeg on a GitHub runner is the motivating case.
Without a declaration the timeout stays at DFLT_INSTALL_TIMEOUT:
[tool.wads.ops.ffmpeg]
install_timeout = 900
install.linux = ["sudo apt-get update", "sudo apt-get install -y ffmpeg"]
The CLI’s --install-timeout sets the fallback for dependencies that declare
none; a declaration always wins over it.
A failed or timed-out install command is retried with exponential backoff
(DFLT_INSTALL_RETRIES extra attempts, DFLT_INSTALL_BACKOFF seconds
before the first retry, doubling), because the usual cause on a hosted runner is a
transient apt mirror timeout that a raised ceiling does not cure. A dependency may
declare install_retries (0 disables retrying); the CLI’s --install-retries
sets the fallback. Worst case for a command that always fails is
(retries + 1) * install_timeout plus the backoff waits. Commands are retried one at a time, so a successful
apt-get update is not repeated when only the following install flaked.
An install command may name a wads recipe instead of spelling it out (issue #160):
[tool.wads.ops.ffmpeg]
check.linux = "ffmpeg -version && ffprobe -version"
install.linux = "wads:static-ffmpeg"
expands to static_ffmpeg_commands(): a pinned, sha256-checked static build in
seconds instead of a crawling apt mirror, with apt as the fallback (Linux x86_64 only;
another architecture goes straight to apt). Override its parameters (url,
sha256, …) under [tool.wads.ops.ffmpeg.recipe]; an unknown or mistyped
parameter fails the dependency. Running the binaries in the check (rather than
which) also catches a wrong-architecture or corrupt download.
An install whose commands all exit 0 is not trusted on that alone: when the dependency
declares a check.<platform>, that check is re-run afterwards, and a dependency whose
check still fails is re-installed (DFLT_VERIFY_RETRIES more rounds, each after a
backoff wait that starts at DFLT_INSTALL_BACKOFF seconds and doubles) and then
reported as failed. Package managers do report success for installs that did nothing —
Chocolatey prints installed 0/0 packages and exits 0 when its feed returns a 5xx —
and a CI job would then run its tests without the dependency, red for the wrong reason
or green with the coverage silently skipped (issue #162). A dependency whose check
cannot pass in the installing process (one that only works in a new shell, say) opts
out with verify_install = false. A blank check counts as no check: not verified.
So the worst case for one dependency is (verify_retries + 1) full install rounds —
each up to n_commands * (retries + 1) * install_timeout plus its command backoffs,
followed by its checks (n_checks * DFLT_CHECK_TIMEOUT) — plus the backoff waits
between rounds: with the defaults, a failing verify roughly doubles the install time.
check and install take a string or a list. A list item is either a command line
or a command in argv form (a list of strings, e.g.
check.linux = [["dpkg", "-s", "unixodbc"], ["rpm", "-q", "unixODBC"]]), which is
quoted into one command line for the platform’s shell. Checks are OR-ed (any passing
one means installed); install commands are AND-ed (run in order, all must succeed).
Module Attributes
Dependencies with a big dependency tree get a longer ceiling than the global default (a cold-cache |
|
An install command of the form |
|
Static ffmpeg + ffprobe for linux64 (x86_64), checked against its sha256. |
|
Seconds apt waits for the dpkg lock before giving up ( |
|
Seconds between SIGTERM and SIGKILL when a timed-out install is stopped. |
|
Extra install rounds for a dependency whose commands succeeded but whose declared |
|
Commands a |
|
Recipes |
Functions
|
Check if dependency is already installed using check commands. |
Detect the current platform. |
|
|
Find pyproject.toml file from path (file or directory). |
|
Install a dependency, then confirm it with its check commands. |
|
Install a dependency using install commands. |
|
Install system dependencies from pyproject.toml. |
|
CLI entry point. |
|
Read [tool.wads.ops.*] sections from pyproject.toml. |
|
Commands installing a static ffmpeg build: download, verify, extract, else apt. |
Warnings for |
|
|
|
Classes
|
A named install: builds commands from |
- wads.install_system_deps.DFLT_APT_LOCK_TIMEOUT = 120¶
Seconds apt waits for the dpkg lock before giving up (
-o DPkg::Lock::Timeout).
- wads.install_system_deps.DFLT_KILL_GRACE = 5¶
Seconds between SIGTERM and SIGKILL when a timed-out install is stopped.
- wads.install_system_deps.DFLT_VERIFY_RETRIES = 1¶
Extra install rounds for a dependency whose commands succeeded but whose declared
checkstill fails afterwards (a package manager that reported success for nothing — e.g. Chocolatey on a feed 5xx).
- wads.install_system_deps.INSTALL_RECIPES = {'static-ffmpeg': InstallRecipe(commands=<function static_ffmpeg_commands>, defaults={'url': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2026-09-30-13-08/ffmpeg-n8.1.3-9-g29e619e767-linux64-gpl-8.1.tar.xz', 'sha256': '97ce978979194b5cf7e06a5e68020dbdaa7a4f3294c5452b6a1bc347100dbb79', 'binaries': ['ffmpeg', 'ffprobe'], 'bin_dir': '/usr/local/bin', 'download_timeout': 120, 'apt_fallback': True}, platforms=('linux',), min_timeout=900)}¶
Recipes
install.<platform> = "wads:<name>"may name; extend by adding to it.
- class wads.install_system_deps.InstallRecipe(commands, defaults, platforms, min_timeout=None)[source]¶
Bases:
objectA named install: builds commands from
defaultsoverridden by parameters.platformsare theinstall.<platform>keys the recipe may be named under.min_timeout(seconds) floors the per-command install timeout of a dependency using the recipe unless it declaresinstall_timeoutitself, so the recipe’s own worst case fits whatever the dependency is called (issue #181).
- wads.install_system_deps.RECIPE_PREFIX = 'wads:'¶
An install command of the form
wads:<name>names a recipe here, expanded into the commands the recipe builds from its defaults overridden by the dependency’s[tool.wads.ops.<dep>.recipe]table (issue #160).
- wads.install_system_deps.SLOW_DEP_INSTALL_TIMEOUTS = {'ffmpeg': 900}¶
Dependencies with a big dependency tree get a longer ceiling than the global default (a cold-cache
apt-get install ffmpegoutlasts 300s). A declaration or an explicitdefault_install_timeoutstill wins, except that a recipe’smin_timeoutfloors the latter (only a per-dependencyinstall_timeoutgoes below it).
- wads.install_system_deps.STATIC_FFMPEG_DEFAULTS = {'apt_fallback': True, 'bin_dir': '/usr/local/bin', 'binaries': ['ffmpeg', 'ffprobe'], 'download_timeout': 120, 'sha256': '97ce978979194b5cf7e06a5e68020dbdaa7a4f3294c5452b6a1bc347100dbb79', 'url': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2026-09-30-13-08/ffmpeg-n8.1.3-9-g29e619e767-linux64-gpl-8.1.tar.xz'}¶
Static ffmpeg + ffprobe for linux64 (x86_64), checked against its sha256. BtbN/FFmpeg-Builds keeps the last autobuild of each month for two years, so this 2026-09-30 pin expires around 2028-09: re-pin (url + sha256) before then.
- wads.install_system_deps.UNIX_ONLY_CHECK_COMMANDS = {'which': '`where <name>` or `<name> -version`'}¶
Commands a
check.windowscannot rely on, with what to use instead. Checks run withshell=True, which on Windows is cmd.exe:whichexists there only when Git’susr\binhappens to be on PATH, so a good install reads as failed (issue #192).
- wads.install_system_deps.check_if_installed(dep_name, check_cmds, timeout=10)[source]¶
Check if dependency is already installed using check commands.
- wads.install_system_deps.find_pyproject(path)[source]¶
Find pyproject.toml file from path (file or directory).
- Return type:
- wads.install_system_deps.install_and_verify(dep_name, install_cmds, check_cmds, *, verify_retries=1, backoff=5, sleep=None, is_installed=<function check_if_installed>, install=<function install_dependency>, **install_kwargs)[source]¶
Install a dependency, then confirm it with its check commands.
installrunsinstall_cmds(with its own per-command retries); when it reports success andcheck_cmdsdeclares a command,is_installedmust agree, or the install is repeated up toverify_retriesmore times, afterbackoffseconds (doubling), before failing. With no check declared the install’s own exit status is all there is to go on.backoffandsleepare also passed on toinstallfor its per-command retries.Returns
(success, error_message)likeinstall_dependency().
- wads.install_system_deps.install_dependency(dep_name, install_cmds, timeout=300, *, retries=2, backoff=5, sleep=None, apt_lock_timeout=120)[source]¶
Install a dependency using install commands.
- Parameters:
dep_name (
str) – Name of dependencyinstall_cmds (
any) – Command(s) to install (see_as_commands())timeout (
float) – Timeout in seconds for each commandretries (
int) – Extra attempts for a command that fails or times outbackoff (
float) – Seconds before the first retry; doubles for each further onesleep – Wait function (default
time.sleep; injectable for tests)apt_lock_timeout (
Optional[float]) – Seconds each apt call waits for the dpkg lock (None: no flag)
- Returns:
bool, error_message: Optional[str])
- Return type:
- wads.install_system_deps.install_system_dependencies(pyproject_path='.', platform=None, skip_check=False, verbose=True, *, default_install_timeout=None, default_install_retries=2, apt_lock_timeout=120, install=None, is_installed=None)[source]¶
Install system dependencies from pyproject.toml.
- Parameters:
pyproject_path (
str) – Path to pyproject.toml or directory containing itplatform (
Optional[str]) – Platform to install for (linux/macos/windows), auto-detect if Noneskip_check (
bool) – Skip checking if dependencies are already installedverbose (
bool) – Print detailed progressdefault_install_timeout (
Optional[float]) – Per-command install timeout (seconds) for dependencies that declare noinstall_timeoutof their own.None:SLOW_DEP_INSTALL_TIMEOUTSfor known-slow ones, elseDFLT_INSTALL_TIMEOUT. Either way, a dependency using an install recipe gets at least the recipe’smin_timeout.apt_lock_timeout (
Optional[float]) – Seconds each apt call waits for the dpkg lock (None: no flag).default_install_retries (
int) – Retries per failed install command for dependencies that declare noinstall_retriesof their own.install – Runs one dependency’s install commands (
None:install_dependency()).is_installed – Runs one dependency’s check commands, before installing and to verify the install (
None:check_if_installed()).
- Return type:
- Returns:
(installed_count, skipped_count, failed_count)
- wads.install_system_deps.read_system_deps(pyproject_path)[source]¶
Read [tool.wads.ops.*] sections from pyproject.toml.
- wads.install_system_deps.static_ffmpeg_commands(params)[source]¶
Commands installing a static ffmpeg build: download, verify, extract, else apt.
A static build takes seconds;
apt-get install ffmpegpulls ~99 packages from a runner mirror that sometimes crawls for 20+ minutes, which no timeout or retry cures (issue #160).paramsoverridesSTATIC_FFMPEG_DEFAULTS:urlandsha256of a.tar.xzwhose*/bin/holdsbinaries, extracted intobin_dir. The archive goes to$RUNNER_TEMP(else/tmp) and is removed afterwards, whatever happened. On a machine that is not x86_64, or when the download, the checksum or the extraction fails, the command fails, or, whenapt_fallbackis true, removes any partly extractedbinariesand installs ffmpeg from apt (--no-install-recommends) with a warning.>>> [cmd] = static_ffmpeg_commands({"apt_fallback": False}) >>> "sha256sum -c -" in cmd and "'*/bin/ffprobe'" in cmd and "apt-get" not in cmd True
- wads.install_system_deps.unix_only_check_warnings(ops)[source]¶
Warnings for
check.windowscommands that call a Unix-only command.opsis the[tool.wads.ops]table (anything else declares nothing); the commands and their suggested replacements areUNIX_ONLY_CHECK_COMMANDS. The commands are reported, not rewritten: they are the user’s.>>> unix_only_check_warnings({"ffmpeg": {"check": {"windows": "which ffmpeg"}}}) ['check.windows for ffmpeg uses `which`, which cmd.exe lacks; use `where <name>` or `<name> -version` (`which ffmpeg`)'] >>> unix_only_check_warnings({"ffmpeg": {"check": {"windows": "where ffmpeg", "linux": "which ffmpeg"}}}) []
- wads.install_system_deps.with_apt_lock_timeout(cmd, seconds)[source]¶
cmdwith everyapt/apt-getcall told to waitsecondsfor the dpkg lock.>>> with_apt_lock_timeout("sudo apt-get update && sudo apt-get install -y ffmpeg", 60) 'sudo apt-get -o DPkg::Lock::Timeout=60 update && sudo apt-get -o DPkg::Lock::Timeout=60 install -y ffmpeg' >>> with_apt_lock_timeout("apt install -y apt-utils", None) 'apt install -y apt-utils'
- Return type: