Package updates
The admin shows which installed packages have a newer release: the Plugins page (a filter and the
installed → latest version), the plugin's own page, and the admin home (the core's version, a
count on the Plugins row). The core does not ask any registry itself: a plugin that knows the
versions reports them, and the update checker plugin (fastpluggy-update-checker) is that plugin.
Reporting updates from a plugin
Implement get_update_status() and check_for_updates() on the plugin class (the UpdateProvider
protocol of fastpluggy.core.updates). Nothing to declare: the core uses the first loaded plugin,
by name, that has both.
from datetime import datetime, timezone
from fastpluggy.core.module_base import FastPluggyBaseModule
from fastpluggy.core.updates import PackageVersion, UpdateStatus
class MyUpdates(FastPluggyBaseModule):
module_name: str = "my_updates"
last_status: UpdateStatus = UpdateStatus()
def get_update_status(self) -> UpdateStatus:
return self.last_status # from memory: pages call it while they render
def check_for_updates(self) -> None:
versions = {"fastpluggy-shop": ("1.0.0", "1.2.0")} # ask the registry here
self.last_status = UpdateStatus(
packages=[PackageVersion(name=name, installed=installed, latest=latest)
for name, (installed, latest) in versions.items()],
checked_at=datetime.now(timezone.utc),
source="registry.example.org",
)
UpdateStatus:
| Field | Meaning |
|---|---|
packages |
One PackageVersion per installed distribution the provider checked, up to date or not. |
checked_at |
When the last check ended (timezone-aware), None before the first one. Shown as "checked 3m ago". |
source |
Where the versions come from, shown as "checked … against <source>". |
details_url |
A page of the plugin listing what it checked (every package, the last error): linked as Details from the Plugins page. |
PackageVersion:
| Field | Meaning |
|---|---|
name |
The distribution name (fastpluggy-tasks-worker). It is matched to a plugin by the distribution the plugin was installed from, whatever its spelling (_, -, ., case). The core is fastpluggy. |
installed, latest |
The installed version and the newest release. update_available is true when latest is newer by PEP 440 (an install ahead of the registry, such as a .dev build, is not an update); a version PEP 440 cannot read is compared as text. |
Calls, timeouts and failures
get_update_status()is called while the Plugins page, a plugin page and the admin home render. Answer from memory. A call that takes more than 0.5 s, raises, or returns something else than anUpdateStatusshows no update information (the Plugins page says "Update status unavailable"). While a slow call runs, the provider is not called again.- A
packagesitem that is not aPackageVersion, or that a later assignment made invalid, is set aside and logged; the other packages are shown. check_for_updates()runs when an admin clicks Check for updates (Plugins page) or Check now (its footer), in a worker thread. It may block until the registry answers; what it raises is shown to the admin as a flash message.- Run your periodic check yourself (a background task); the core never calls
check_for_updates()on its own.
Installing a version from the plugin page
A plugin that can install a package version implements package_install_url() (the
PackageInstallProvider protocol). The plugin page of a plugin with a newer release then shows an
Install vX button that POSTs a form to that URL, after a confirmation.
from fastpluggy.core.module_base import FastPluggyBaseModule
class MyInstaller(FastPluggyBaseModule):
module_name: str = "my_installer"
def package_install_url(self, name: str, version: str) -> str | None:
return f"/plugin/my_installer/install?name={name}&version={version}"
The route receives the form POST and answers with a redirect (to a page following the install, for
example). Return None for a package it cannot install. Without an install provider, the plugin
page only states the new version: deployments that build an image install it there.
Where it shows
| Place | What |
|---|---|
| Plugins page | installed → latest in the Version column; an N updates available count and an Updates filter (?status=update); Check for updates in the header; "Updates checked … against … · Check now · Details" under the table. |
| Plugin page | vX available next to the name and in the subtitle; a box with the installed and new version, and the Install button when an install provider is loaded. |
| Admin home | Health: the core's version with "up to date" or "X available", and "N plugin updates · checked …" linking to the filter. System card: an N updates badge on the Plugins row. |
Without an update provider, none of this is shown. To tell the operator in the Needs attention
list as well, the provider also reports an info advisory of category upgrade.