annals.requirements#
Optional dependencies, checked where they are needed and explained when they are missing.
annals installs light: a heavy library (WeasyPrint for PDFs, pypdf for joining them,
markdownify for html to markdown) is imported only when the conversion that needs it runs,
and a missing one is a MissingDependency that says which conversion needed it and
the exact command that fixes it, never a bare ImportError from deep inside a library.
>>> check_requirements("json", what="anything") # present: returns quietly
>>> try:
... check_requirements("no_such_module_xyz", what="Combining into PDF")
... except MissingDependency as e:
... print(str(e).splitlines()[0])
Combining into PDF needs no_such_module_xyz, which is not installed.
The pip name and the hint for a module are in PACKAGES, so a new optional library is
one entry there.
Module Attributes
the extra of annals that installs everything a conversion may need |
|
module name -> (pip name, system hint or |
Functions
|
Raise |
|
The module |
|
The |
Exceptions
|
A library an operation needs is not installed (the message says how to install it). |
- annals.requirements.DFLT_EXTRA = 'pdf'#
the extra of annals that installs everything a conversion may need
- exception annals.requirements.MissingDependency(modules, *, what, extra='pdf')[source]#
Bases:
RuntimeErrorA library an operation needs is not installed (the message says how to install it).
- annals.requirements.PACKAGES: dict[str, tuple[str, str]] = {'PIL': ('pillow', ''), 'markdown_it': ('markdown-it-py', ''), 'markdownify': ('markdownify', ''), 'pdfdol': ('pdfdol', ''), 'playwright': ('playwright', 'Then fetch its browser: playwright install chromium'), 'pypdf': ('pypdf', ''), 'weasyprint': ('weasyprint', 'It also needs the Pango library (Debian/Ubuntu: apt install libpango-1.0-0).')}#
module name -> (pip name, system hint or
"")
- annals.requirements.check_requirements(*modules, what, extra='pdf')[source]#
Raise
MissingDependencyunless every one ofmodulesis installed.Cheap (nothing is imported), so a caller checks everything a job will use before it starts, and fails at once instead of half way.
- Return type:
- annals.requirements.import_lazily(name, *, what, extra='pdf')[source]#
The module
name, imported now; a failure to import it is aMissingDependency.A library that is installed but cannot load (WeasyPrint without Pango raises
OSError) is reported the same way.