Plugins#
Plugins can be used to extend quetz functionalities. For example, they can:
add extra endpoints
extract meta data from packages
and other
Built-in plugins#
Quetz repository provides a few “standard” plugins in the plugins sub-directory. However if you want to use them, you will still need to install them. After installing the Quetz server and its dependencies, go to the plugins
subdirectory and install selected plugins. For example,
cd plugins
pip install quetz_runexports
quetz_runexports
#
quetz_runexports
plugin extract the run_exports
metadata from conda packages and exposes them at the endpoint /api/channels/{channel_name}/packages/{package_name}/versions/{version_id}/run_exports
quetz_repodata_patching
#
Some channels, such as conda-forge
require that metadata from some packages are patched (modified) in the channel index (stored in repodata.json
file and similar), so that the channel is internally consistent (i.e. all packages can be installed and dependencies satisfied). For example, a package might be too restrictive in its specification of its dependencies, so the specifications need to be relaxed in the channel index. This procedure is called repodata patching.
quetz_repodata_patching
plugin implements the repodata patching. If installed, it will look for {channel_name}-repodata-patches
package in the channel and apply the patch instructions in the JSON format from this package to the channel index.
For more information about the repodata patching and patch format checkout the docs and conda-forge feedstock.
quetz_conda_suggest
#
quetz_conda_suggest
generates .map
files specific to a particular channel and a subdir. These map files facilitate the functioning of conda-suggest
. More information can be seen here.
The generated map file can be accessed from the endpoint /api/channels/{channel_name}/{subdir}/conda-suggest
.
quetz_current_repodata
#
quetz_current_repodata
plugin generates current_repodata.json
file specific to a particular channel and a subdir. It is a trimmed version of repodata.json
which contains the latest versions of each package.
More information can be accessed on the current repodata docs.
Creating a plugin#
Some examples can be found in plugins directory. If you want to create a new plugin, please use our cookiecutter template.
Hooks#
Hooks can be implemented in plugins. They are automatically called in quetz backend after or before certain operations:
- quetz.hooks.check_additional_permissions(db, user_id, user_role) bool #
Check if the user has appropriate permissions
- Parameters:
user_id (str) – id of the user
- quetz.hooks.post_add_package_version(version: PackageVersion, condainfo: CondaInfo) None #
hook for post-processsing after adding a package file.
- Parameters:
version (quetz.db_models.PackageVersion) – package version model that was added in to the database
condainfo (quetz.condainfo.CondaInfo) – metadata extracted from the archive
- quetz.hooks.post_index_creation(raw_repodata: dict, channel_name: str, subdir: str) None #
hook for post-processsing after creating package index.
- Parameters:
raw_repodata (dict) – the package index
channel_name (str) – the channel name
subdir (str) – the subdirectory to which belongs the package index
- quetz.hooks.post_package_indexing(tempdir: Path, channel_name: str, subdirs: List[str], files: dict, packages: dict) None #
hook for post-processsing after building indexes.
- Parameters:
pkgstore (quetz.pkgstores.PackageStore) – package store used to store/retrieve packages
channel_name (str) – metadata extracted from the archive
subdirs (list) – list of subdirs with indexes
files (dict) – a dict that contains list of files for each subdir - used in updating the index
packages (dict) – a dict that contains list of packages for each subdir - used in updating the index
- quetz.hooks.register_router() APIRouter #
add extra endpoints to the url tree.
It should return an
fastapi.APIRouter
with new endpoints definitions. By default it will be added to the root of the urlscheme
- quetz.hooks.validate_new_package(channel_name: str, package_name: str, file_handler: Optional[BinaryIO], condainfo: Optional[CondaInfo]) None #
Validate new package name.
It should raise :class:
quetz.errors.ValidationError
if a package is not valid.- Parameters:
package_name (str) – name of the package
channel_name (str) – name of channel with the package
file_handler (BinaryIO) – handler to the package file, it can be None if a package is created but no file was yet uploaded
condainfo (CondaInfo) – CondaInfo instance with package metadata, it can be None if file was not uploaded