annie.core.runtime¶
Launch-time helpers for running Annie as an installed desktop app (infrastructure).
Concerns of the installed app rather than of the UI, kept out of annie.app and
annie.desktop so they can be unit-tested:
FFmpeg DLLs on Windows. Since Python 3.8, Windows no longer searches
PATHfor the DLLs an extension module depends on, so torchcodec cannot find FFmpeg’savcodec-*.dll& co. unless their folder is registered withos.add_dll_directory()before torchcodec is imported.No console windows. The installed Annie runs without a console (
pythonw), so every ffmpeg/ffprobe it starts would get a console window of its own, flashing on screen;hidden_console()keeps them hidden.A second launch. Double-clicking the shortcut while Annie is already running must open the running instance instead of crashing on a busy port.
Launcher age. The Windows installer’s launcher (
installer/windows/launcher.pyw) stamps its version intoANNIE_LAUNCHER_VERSION. Annie itself updates on every start, but the launcher, the bundled Python and FFmpeg only change when the user reinstalls, so Annie tells them when that is needed.Updates. The tray’s “Check for updates” compares the running version with the newest release on PyPI.
The Annie folder. The tray opens the folder that holds Annie’s program and data.
Example datasets. The installer can include two small example datasets; the tray downloads them later when they were left out.
Attributes¶
Oldest |
|
Permanent download link to the newest Windows installer. |
|
Microsoft's permanent link to the Visual C++ Redistributable (x64). |
|
PyPI's JSON description of the |
|
The example datasets (the repo's |
|
The top-level folders of the examples archive; nothing else is extracted from it. |
Functions¶
|
Return the folder holding FFmpeg's shared libraries, or |
|
The |
|
On Windows, register FFmpeg's DLL folder so torchcodec can load it. |
|
Return the browser URL for an Annie server bound to |
|
Return whether something already accepts connections on |
|
Return whether the server on |
|
Return whether the Windows launcher that started Annie is too old. |
|
Return the numeric release part of a version string, or |
|
Return whether release |
|
Return the newest Annie release on PyPI, or |
|
Return the folder the tray's "Open Annie folder" opens. |
|
Whether the example datasets' configs are in |
|
Unpack the examples archive into |
|
Download the example datasets into |
|
Explain why the frame decoder (torchcodec, and PyTorch under it) could not load. |
Module Contents¶
- annie.core.runtime.REQUIRED_LAUNCHER_VERSION = 3¶
Oldest
installer/windows/launcher.pywversion this Annie works with.Bump this together with
LAUNCHER_VERSIONin the launcher whenever the launcher, its bundled Python or FFmpeg changes in a way this Annie relies on. Version 2 is the tray launcher with the bundled Python; installs still runningAnnie.cmd(version 1) are asked to run the new installer. Version 3 bundles the Visual C++ runtime next to that Python, which PyTorch needs on PCs without the system-wide Redistributable.
- annie.core.runtime.INSTALLER_URL = 'https://github.com/fodorad/Annie/releases/latest/download/Annie-Setup.exe'¶
Permanent download link to the newest Windows installer.
- annie.core.runtime.VC_REDIST_URL = 'https://aka.ms/vs/17/release/vc_redist.x64.exe'¶
Microsoft’s permanent link to the Visual C++ Redistributable (x64).
- annie.core.runtime.PYPI_URL = 'https://pypi.org/pypi/annie/json'¶
PyPI’s JSON description of the
annieproject;info.versionis the newest release.
- annie.core.runtime.EXAMPLES_URL = 'https://github.com/fodorad/Annie/releases/latest/download/annie-examples.zip'¶
The example datasets (the repo’s
data/configanddata/example), per release.
- annie.core.runtime.EXAMPLE_FOLDERS = ('config', 'example')¶
The top-level folders of the examples archive; nothing else is extracted from it.
- annie.core.runtime.ffmpeg_dll_dir(override: str | None, ffmpeg_exe: str | None) pathlib.Path | None[source]¶
Return the folder holding FFmpeg’s shared libraries, or
Noneif unknown.On Windows the DLLs sit next to
ffmpeg.exein a shared build’sbinfolder.- Parameters:
override – The
ANNIE_FFMPEG_LIB_DIRvalue, if any; wins when it is a folder.ffmpeg_exe – The
ffmpegexecutable found onPATH, if any.
- Returns:
The folder to register, or
Nonewhen neither source points at one.
The
subprocesscreationflagsthat keep a console program out of sight.When a program without a console (the installed Annie runs under
pythonw) starts a console program such as ffmpeg or ffprobe, Windows opens a new console window for it, which flashes on screen for every video.CREATE_NO_WINDOWgives the child a console it can write to, without a window. Other platforms need no flags.- Parameters:
platform –
sys.platform, injectable for tests.- Returns:
CREATE_NO_WINDOWon Windows, else0(no flags, valid everywhere); pass it on assubprocess.run(cmd, creationflags=hidden_console()).
- annie.core.runtime.ensure_windows_ffmpeg_dlls() pathlib.Path | None[source]¶
On Windows, register FFmpeg’s DLL folder so torchcodec can load it.
Idempotent and a no-op on other platforms. Call before importing torchcodec.
- Returns:
The folder registered by this call, or
Noneif nothing was registered.
- annie.core.runtime.app_url(host: str, port: int) str[source]¶
Return the browser URL for an Annie server bound to
host:port.
- annie.core.runtime.port_in_use(host: str, port: int) bool[source]¶
Return whether something already accepts connections on
host:port.
- annie.core.runtime.annie_running(host: str, port: int) bool[source]¶
Return whether the server on
host:portis Annie (its page title says so).Distinguishes a second launch of Annie from an unrelated app holding the port.
- annie.core.runtime.launcher_outdated(raw_version: str | None) bool[source]¶
Return whether the Windows launcher that started Annie is too old.
- Parameters:
raw_version – The
ANNIE_LAUNCHER_VERSIONvalue; empty orNonewhen Annie was not started by the installer’s launcher.- Returns:
Trueonly for a readable version belowREQUIRED_LAUNCHER_VERSION.
- annie.core.runtime.parse_version(raw: str) tuple[int, ...] | None[source]¶
Return the numeric release part of a version string, or
Noneif there is none."1.12.0"gives(1, 12, 0). Anything after the release numbers (.dev3,rc1,+g1a2b3c) is ignored, so a development build of 1.13.0 compares equal to the 1.13.0 release rather than newer.- Parameters:
raw – A version string such as
"1.12.0"or"v1.12.1.dev2+gabc".
- annie.core.runtime.is_newer(latest: str, current: str) bool[source]¶
Return whether release
latestis newer than the runningcurrentversion.Unreadable versions never count as newer, so a garbled answer from PyPI cannot trigger an update. Missing trailing parts count as zero (
1.12equals1.12.0).
- annie.core.runtime.latest_pypi_version(timeout: float = 5.0) str | None[source]¶
Return the newest Annie release on PyPI, or
Nonewhen PyPI cannot be reached.
- annie.core.runtime.annie_folder(settings: annie.core.config.Settings, install_dir: pathlib.Path | None) pathlib.Path[source]¶
Return the folder the tray’s “Open Annie folder” opens.
With the installer’s defaults that is
%USERPROFILE%\Annie, which holds both the program (App) and your work (Data). When the two were put in unrelated places, or Annie was not started by the Windows launcher, it is the data folder.- Parameters:
settings – The running app’s settings, which know where the data lives.
install_dir – The
ANNIE_INSTALL_DIRfolder, orNonewhen not installed.
- annie.core.runtime.examples_installed(directory: pathlib.Path) bool[source]¶
Whether the example datasets’ configs are in
directory(anANNIE_DATA_DIR).
- annie.core.runtime.extract_examples(archive: pathlib.Path, directory: pathlib.Path) int[source]¶
Unpack the examples archive into
directoryand return the number of files.Only entries under
config/andexample/are extracted, and none may escapedirectory, so a damaged or hostile archive cannot write anywhere else.- Parameters:
archive – The downloaded
annie-examples.zip.directory – The
ANNIE_DATA_DIRfolder; created when missing.
- Raises:
ValueError – If the archive holds no example configs.
zipfile.BadZipFile – If it is not a zip archive.
- annie.core.runtime.download_examples(directory: pathlib.Path, timeout: float = 60.0) int[source]¶
Download the example datasets into
directory; seeextract_examples().The archive is kept inside
directoryonly while it is unpacked.- Raises:
OSError – If the download fails.
ValueError – If the download is not a valid examples archive.
- annie.core.runtime.decoder_problem(exc: BaseException, platform: str = sys.platform, *, installed: bool | None = None) str[source]¶
Explain why the frame decoder (torchcodec, and PyTorch under it) could not load.
Two usual causes:
FFmpeg’s shared libraries are missing: torchcodec then cannot load its core library (
Could not load libtorchcodec, a 150-line message). The installed Windows app bundles FFmpeg; a source checkout needs a shared FFmpeg onPATH, and a terminal opened before installing it still has the oldPATH.Windows lacks the Visual C++ runtime: PyTorch’s DLLs need
msvcp140.dll& co. The Windows installer bundles them; older installs and other setups need the system-wide Redistributable.
- Parameters:
exc – The error raised while importing the decoder or opening a video with it.
platform –
sys.platform, injectable for tests.installed – Whether this is the Windows installer’s Annie (
ANNIE_INSTALL_DIRset); detected whenNone.
- Returns:
A one-line message for the Log tab, the toast and the banner (the full error stays in the Log tab’s details).