cmem_client.repositories.marketplace_packages¤
Repository for the marketplace packages installed in eccenca Corporate Memory.
Provides MarketplacePackagesRepository for installing packages from an archive or
directory, exporting an installed package again and removing one. The packages
available on a marketplace server are offered by the Marketplace component
(client.marketplace) instead.
Examples:
List the installed packages:
>>> from cmem_client.client import Client
>>> client = Client.from_env()
>>> list(client.marketplace_packages)
Install a package archive and export an installed package:
>>> from pathlib import Path
>>> from cmem_client.repositories.marketplace_packages import (
... MarketplacePackagesExportConfig,
... MarketplacePackagesImportConfig,
... )
>>> from cmem_client.repositories.protocols.import_item import ImportConflictPolicy
>>> client.marketplace_packages.import_item(
... key="w3c-geo-vocab",
... configuration=MarketplacePackagesImportConfig(install_from_marketplace=True),
... on_conflict=ImportConflictPolicy.REPLACE
... )
>>> client.marketplace_packages.export_item(
... key="w3c-geo-vocab",
... path=Path("w3c-geo-vocab"),
... configuration=MarketplacePackagesExportConfig(export_as_zip=False),
... )
>>> client.marketplace_packages.delete_item(key="w3c-geo-vocab", skip_if_missing=True)
Classes:
- MarketplacePackagesDeleteConfig – Package deletion configuration
- MarketplacePackagesExportConfig – Package export configuration
- MarketplacePackagesImportConfig – Configuration for marketplace package import operations.
- MarketplacePackagesRepository – Repository for marketplace package operations.
Functions:
- get_file_resource_key – Get the composite key a packaged image or text file is stored under in Corporate Memory.
- get_installation_metadata_query – Get the query for the installation metadata of the package.
Attributes:
- LOCK_FILE_RESOURCE –
- MAX_DEPENDENCY_DEPTH – Hard ceiling on marketplace-package dependency recursion depth.
LOCK_FILE_RESOURCE¤
MAX_DEPENDENCY_DEPTH¤
Hard ceiling on marketplace-package dependency recursion depth.
Not a cycle guard – a real cycle is resolved for free by dependency_chain on
MarketplacePackagesImportConfig/MarketplacePackagesDeleteConfig (see there), which
stops re-descending into a package already in progress higher up the same chain, whatever the
depth. This exists for a pathologically deep-but-acyclic chain, or a misbehaving marketplace.
The number is generous headroom above any realistic dependency chain, not a meaningful
business limit.
MarketplacePackagesDeleteConfig¤
Bases: DeleteConfig
Package deletion configuration
Attributes:
- skip_missing_dependencies (
bool) – If True, dependencies which are not installed are skipped instead of raising an error. - skip_missing_graphs (
bool) – If True, graphs of the package which do not exist are skipped instead of raising an error. - skip_missing_projects (
bool) – If True, projects of the package which do not exist are skipped instead of raising an error. - skip_missing_views (
bool) – If True, application views of the package which do not exist (for example because somebody deleted them by hand after the installation) are skipped instead of raising an error. - ignore_lock (
bool) – If set to True, ignore the lock mechanism. - ignore_dependencies (
bool) – If True, dependencies of the package are not deleted. - dependency_level (
int) – Current recursion depth for dependency resolution. Used internally to identify the top-level call and to enforce MAX_DEPENDENCY_DEPTH. Should not be set manually. - dependency_chain (
tuple[PackageIdentifier, …]) – package_ids of the packages currently being deleted, from the top-level call down to (but not including) the package about to be deleted. Used internally to skip re-descending into a package a dependency cycle leads back to – it is already being deleted higher up this chain. Should not be set manually.
dependency_chain¤
dependency_level¤
ignore_dependencies¤
ignore_lock¤
model_config¤
skip_missing_dependencies¤
skip_missing_graphs¤
skip_missing_projects¤
skip_missing_views¤
MarketplacePackagesExportConfig¤
Bases: ExportConfig
Package export configuration
Attributes:
- export_graph_serialization (
Literal[‘turtle’, ‘pretty-turtle’]) – Graph export serialization format. - export_as_zip (
bool) – If true, export the package as a zip file, otherwise as a directory.
export_as_zip¤
export_graph_serialization¤
model_config¤
MarketplacePackagesImportConfig¤
Bases: ImportConfig
Configuration for marketplace package import operations.
Attributes:
- ignore_dependencies (
bool) – If True, skips installation of package dependencies. - install_from_marketplace (
bool) – If True, downloads packages from the marketplace server. If False, loads packages from local filesystem. - package_version (
PackageVersionIdentifier | None) – Specific version to install. If None, installs the latest version. - dependency_level (
int) – Current recursion depth for dependency resolution. Used internally to enforce MAX_DEPENDENCY_DEPTH. Should not be set manually. - dependency_chain (
tuple[PackageIdentifier, …]) – package_ids of the packages currently being installed, from the top-level call down to (but not including) the package about to be installed. Used internally to skip re-descending into a package a dependency cycle leads
back to – it is already being installed higher up this chain. Should not be set manually.
- use_cache (
bool) – Weather to use the cache directory to look packages up which have already been downloaded. To prevent the cache entirely, set this up in the marketplace component. - ignore_lock (
bool) – If set to True, ignore the lock mechanism. - force_dependencies (
bool) – If True, an installed dependency whose version violates the constraint a package declares on it is upgraded or downgraded to a version which satisfies the constraint, and the installation proceeds although a version it puts in place (the package itself, or a dependency) violates the constraint of an installed package, which is then listed inbroken_dependants. If False, such an installation fails before anything is installed. - resolution (
DependencyResolution | None) – Resolved dependency versions of the whole installation tree. Used internally to hand the resolution down to dependency installations. Should not be set manually. - source (
PackageSource | None) – Where versions, dependency lists and archives are read from. If None, the marketplace server of the client (client.marketplace) is used. - broken_dependants (
list[BrokenDependant]) – Output of the installation: the installed packages whose version constraint it broke because the dependencies were forced. Cleared at the start of every top-level installation, so it always describes the last one made with this configuration. Empty after an installation which broke nothing.
broken_dependants¤
dependency_chain¤
dependency_level¤
force_dependencies¤
ignore_dependencies¤
ignore_lock¤
install_from_marketplace¤
model_config¤
package_version¤
resolution¤
source¤
use_archive_handler¤
use_cache¤
MarketplacePackagesRepository¤
Bases: Repository, ImportItemProtocol, ExportItemProtocol, DeleteItemProtocol
Repository for marketplace package operations.
Functions:
- acquire_lock – Acquire the shared marketplace-packages install/uninstall lock for a whole operation.
- delete_all – Delete all items from the repository
- delete_item – Delete an item from the repository
- dependency_tree – Report the dependency tree of the installed packages.
- export_item – Export an item from the repository to a file path.
- fetch_data – Fetch installed packages from the package data graph via SPARQL query.
- get_installed_file – Read a packaged image or text file of an installed package back from Corporate Memory.
- import_item – Import an exported file to the repository
- items – Get the items of the repository
- keys – Get the keys of the repository
- release_lock – Release the shared marketplace-packages install/uninstall lock acquired by
acquire_lock. - values – Get the values of the repository
Attributes:
- logger (
Logger) – Gets the client logger
acquire_lock¤
Acquire the shared marketplace-packages install/uninstall lock for a whole operation.
Import/delete each threads a fragile ignore_lock/dependency_level pair through
every recursive call to know which one is responsible for acquiring and releasing the
shared lock – correct for a plain recursive walk, but it breaks down when a step in
that walk is skipped for an unrelated reason (e.g. a dependency turns out to already be
installed): nothing acquires the lock in that call’s place, and a caller that assumed it
had can go on to (wrongly) treat a lock still held from a genuinely separate, earlier,
possibly-orphaned operation as its own.
Call this once, explicitly, before a multi-step operation that composes several
import/delete calls into one logical whole (see e.g.
eccenca_marketplace.services.install_local_package), then pass ignore_lock=True
to every one of those calls – no per-call bookkeeping needed. Pair with release_lock
in a finally, regardless of whether every step actually ran.
Parameters:
- package_id (
str) – The package this operation is ultimately for – recorded in the lock, and named in the error message if another process already holds it. - activity (
Literal[‘Install’, ‘Uninstall’]) – What the lock records itself as doing.
Raises:
MarketplacePackagesImportError– If another process already holds the lock.
delete_all¤
Delete all items from the repository
delete_item¤
Delete an item from the repository
Parameters:
- key (
str) – The key of the item to delete - skip_if_missing (
bool) – If True, it is ignored if the deleted item even exists - configuration (
DeleteItemConfig) – Optional configuration for deletion
Raises:
RepositoryModificationError– if an error occurs while creating the itemHTTPError– for any other http error
dependency_tree¤
Report the dependency tree of the installed packages.
Every installed package is listed with the dependencies its manifest declares - marketplace packages and Python packages alike - each with the declared constraint, the installed version and whether it is satisfied, violated or missing, and with the installed packages which depend on it. The violations of the tree collect every violated and missing dependency, so an empty list means the installed tree is consistent. A dependency which is missing because its dependant was installed while ignoring the dependencies, or because it was uninstalled, is reported as missing. The roots of the tree are the installed packages nothing else requires, and the nested tree expands them, every package once, for a caller which renders it.
Parameters:
- package_id (
str | None) – Report only the part of the tree this installed package pulls in, rooted at it (seeinstalled_subtree()).
Returns:
DependencyTree– The tree, read from Corporate Memory right now.
Raises:
MarketplacePackagesNotFoundError– Ifpackage_idis not installed.
export_item¤
Export an item from the repository to a file path.
Parameters:
- key (
str) – The key identifying the item to export. - path (
Path | None) – The target file path for export. If None, a path will be generated. - replace (
bool) – Whether to replace existing files at the target path. - configuration (
ExportItemConfig_contra | None) – Optional configuration for export behavior.
Returns:
Path– The actual path where the item was exported.
Raises:
RepositoryItemNotFoundError– If the specified item key is not found.RepositoryReadError– If there is an error during export or path mismatch.
fetch_data¤
Fetch installed packages from the package data graph via SPARQL query.
Queries the package data graph for all installed packages and their metadata.
get_installed_file¤
Read a packaged image or text file of an installed package back from Corporate Memory.
An installation keeps the icon, the marketplace images, the readme, the license and the changelog of a package as file resources, whether the package came from a marketplace or from a file, so they can be shown after the archive is gone. Only a path the installed manifest declares as an image or text file can be read.
Parameters:
- package_id (
str) – The ID of the installed package. - file_path (
str) – The path of the file as the installed manifest declares it.
Returns:
bytes– The raw content of the file.
Raises:
MarketplacePackagesNotFoundError– If the package is not installed.MarketplacePackagesFileNotFoundError– If the installed manifest declares no image or text file with this path.FilesNotFoundError– If the file resource is missing in Corporate Memory.
import_item¤
Import an exported file to the repository
By default, automatically handles zip files, directories, and single files using ImportItem model. Can be disabled by setting use_archive_handler=False in the configuration.
Returns:
str– The key of the imported item.
Raises:
RepositoryModificationError– If the item already exists and the conflict policy is FAIL, if the import type is not allowed for this repository, if the import request failed, or if the item is not present afterwards.
items¤
Get the items of the repository
keys¤
Get the keys of the repository
logger¤
Gets the client logger
release_lock¤
Release the shared marketplace-packages install/uninstall lock acquired by acquire_lock.
Safe to call even if the assets project or the lock file no longer exist (e.g. the last package was also removed as part of the same operation).
values¤
Get the values of the repository
get_file_resource_key¤
Get the composite key a packaged image or text file is stored under in Corporate Memory.
get_installation_metadata_query¤
Get the query for the installation metadata of the package.