owmeta_core.bundle package¶
- class owmeta_core.bundle.AccessorConfig[source]¶
Bases:
objectConfiguration for accessing a
Remote.Loadersare added to a remote according to which accessors are available
- class owmeta_core.bundle.Bundle(ident, bundles_directory='~/.owmeta/bundles', version=None, conf=None, remotes=None, remotes_directory='~/.owmeta/remotes', transaction_manager=None)[source]¶
Bases:
objectMain entry point for using bundles
Typical usage is something like this:
>>> with Bundle('example/bundleId', version=42) as bnd: ... for aDataObject in bnd(DataObject)().load(): ... # Do something with `aDataObject` ... print(aDataObject) DataObject(<http://example.org/entities#aDataObject>)
Note
Paths,
bundles_directoryandremotes_directory, will have symbolic links, environment variables, and “~” (for the current user’s home directory) expanded when theBundleis initialized. To reflect changes to symbolic links or home directories, thebundles_directoryorremotes_directoryattributes must be updated directly or a new instance must be created.- Parameters
- ident
str Bundle ID
- bundles_directory
str,optional Path to the bundles directory. Defaults to
DEFAULT_BUNDLES_DIRECTORY- version
int,optional Bundle version to access. By default, the latest version will be used.
- conf
Configurationordict,optional Configuration to add to the one created for the bundle automatically. Values for the default imports context (
IMPORTS_CONTEXT_KEY), the default context (DEFAULT_CONTEXT_KEY) and store ('rdf.store','rdf.source', and,'rdf.store_conf') will be ignored and overwritten.- remotesiterable
ofRemoteorstr,optional A subset of remotes and additional remotes to fetch from. See
Fetcher.fetch- remotes_directory
str,optional The directory to load
Remotesfrom in case a bundle is not in the bundle cache. Defaults toDEFAULT_REMOTES_DIRECTORY- transaction_manager
transaction.TransactionManager,optional Transaction manager
- ident
- load_dependencies()[source]¶
Load direct dependencies of this bundle
- Yields
BundleA direct dependency of this bundle
- load_dependencies_transitive()[source]¶
Load dependencies from this bundle transitively
- Yields
BundleA direct or indirect dependency of this bundle
- connection¶
The owmeta_core connection to the bundle’s indexed database
- class owmeta_core.bundle.BundleDependencyManager(dependencies, **common_bundle_arguments)[source]¶
Bases:
objectFinds the bundle in which a context is defined.
For a given bundle graph, that there is one Bundle that “owns” a given context. Although multiple bundles may provide that context, the one closest to the root of the graph which provides some statements in that context is called the owner. Note that this does not mean that bundles on which the owner depends do not also be queried; however, the exact behavior is up to the component that uses this component.
- Parameters
- dependencies
function Function that returns a sequence of dependency descriptors
- dependencies
- load_dependencies_transitive()[source]¶
Load dependencies from this bundle transitively.
Any given version of a bundle will be yielded at most once regardless of how many times that version of the bundle appears in the dependency graph. Dependencies will yielded in topological sort order, so every dependency a Bundle declares will be yielded before any of its transitive dependencies.
- Yields
BundleA direct or indirect dependency of this bundle
- class owmeta_core.bundle.BundleDependentStoreConfigBuilder(bundles_directory=None, remotes_directory=None, remotes=None, read_only=True, transaction_manager=None)[source]¶
Bases:
objectBuilds an RDFLib store configuration that depends on bundles.
The process of building the store configuration requires traversing the graph of dependencies so that duplicate dependencies in the graph can be omitted. To support this process, this builder will fetch bundles as needed to resolve transitive dependencies
- build(indexed_db_path, dependencies, bundle_directory=None)[source]¶
Builds the store configuration
- Parameters
- indexed_db_path
str Path to the indexed database of the store that depends on the listed dependenices
- dependencies
listofdict List of dependencies’ info, each entry including at least keys for ‘id’ and ‘version’
- bundle_directory
str,optional Path to the bundle directory for the dependent store, if the dependent store is a bundle. Used for information in an exceptional path, but not otherwise used
- indexed_db_path
- Returns
strThe type of the store. This is the name used to look up the RDFLib store plugin
objectThe configuration for the store. This is the object that will be passed to
rdflib.store.Store.opento configure the store.
- class owmeta_core.bundle.BundleTransactionManager(explicit=False)[source]¶
Bases:
TransactionManagerMarker class useful in debugging to identify which txn manager we’re using
- class owmeta_core.bundle.Cache(bundles_directory)[source]¶
Bases:
objectCache of bundles
- Parameters
- bundles_directory
str The where bundles are stored
- bundles_directory
- class owmeta_core.bundle.Deployer(remotes=(), **kwargs)[source]¶
Bases:
_RemoteHandlerMixinDeploys bundles to
Remotes.A deployer takes a bundle directory tree or bundle archive and uploads it to a remote.
Fetcheris, functionally, the dual of this class.Deployer is responsible for selecting remotes and corresponding uploaders among a set of options.
Uploadersare responsible for actually doing the upload.- deploy(bundle_path, remotes=None)[source]¶
Deploy a bundle to all remotes that are configured to accept uploads
- Parameters
- Raises
NoAcceptableUploadersThrown when none of the selected uploaders could upload the bundle
- class owmeta_core.bundle.Descriptor(ident, **kwargs)[source]¶
Bases:
objectDescriptor for a bundle.
The descriptor is sufficient to build a distributable bundle directory tree from a
ConjunctiveGraphand a set of files (seeInstaller).- dump(output)[source]¶
Save a descriptor to a file as a YAML record
- Parameters
- outputfile object
The file to save the descriptor to
- classmethod load(descriptor_source)[source]¶
Load a descriptor from a YAML record
- Parameters
- descriptor_source
stror file object The descriptor source. Handled by yaml.safe_load
- descriptor_source
- Raises
NotADescriptorThrown when the object loaded from
descriptor_sourceisn’t adict
- classmethod make(obj)[source]¶
Makes a descriptor from the given object.
- Parameters
- obj
adict-like object An object with parameters for the Descriptor. Typically a dict
- obj
- Returns
DescriptorThe created descriptor
- class owmeta_core.bundle.Fetcher(bundles_root, remotes, transaction_manager=None, **kwargs)[source]¶
Bases:
_RemoteHandlerMixinFetches bundles from
RemotesA fetcher takes a list of remotes, a bundle ID, and, optionally, a version number and downloads the bundle to a local directory.
Deployeris, functionally, the dual of this class.- Parameters
- fetch(bundle_id, bundle_version=None, remotes=None, progress_reporter=None, triples_progress_reporter=None)[source]¶
Retrieve a bundle by name from a remote and put it in the local bundle cache.
The first remote that can retrieve the bundle will be tried. Each remote will be tried in succession until one downloads the bundle.
- Parameters
- bundle_id
str The id of the bundle to retrieve
- bundle_version
int,optional The version of the bundle to retrieve. If not provided, attempt to fetch the latest version available
- remotesiterable
ofRemoteorstr A subset of remotes and additional remotes to fetch from. If an entry in the iterable is a string, then it will be looked for amongst the remotes passed in initially.
- progress_reportertqdm.tqdm-like
object,optional Receives updates of progress in fetching and installing locally
- triples_progress_reportertqdm.tqdm-like
object,optional Receives updates of progress for adding triples for an individual graph
- bundle_id
- Returns
strreturns the directory where the bundle has been placed
- Raises
exceptions.NoBundleLoaderThrown when none of the loaders are able to download the bundle
FetchTargetIsNotEmptyThrown when the requested bundle is already in the cache
- class owmeta_core.bundle.Installer(source_directory, bundles_directory, graph, imports_ctx=None, default_ctx=None, class_registry_ctx=None, installer_id=None, remotes=(), remotes_directory=None)[source]¶
Bases:
objectInstalls a bundle locally
- Parameters
- source_directory
str Directory where files come from. All files for a bundle must be below this directory
- bundles_directory
str Directory where the bundles files go. Usually this is the bundle cache directory
- graph
rdflib.graph.ConjunctiveGraph The graph from which we source contexts for this bundle
- default_ctx
str,optional The ID of the default context – the target of a query when not otherwise specified.
- imports_ctx
str,optional The ID of the imports context this installer should use. Imports relationships are selected from this graph according to the included contexts.
- class_registry_ctx
str,optional The ID of the class registry context this installer should use. Class registry entries are retrieved from this graph.
- installer_iditerable
ofRemoteorstr,optional Name of this installer for purposes of mutual exclusion
- remotesiterable
ofRemote,optional Remotes to be used for retrieving dependencies when needed during installation. If not provided, the remotes will be collected from
remotes_directory- remotes_directory
str,optional The directory to load
Remotesfrom in case a bundle is not in the bundle cache. Defaults toDEFAULT_REMOTES_DIRECTORY
- source_directory
- install(descriptor, progress_reporter=None)[source]¶
Given a descriptor, install a bundle
- Parameters
- descriptor
Descriptor The descriptor for the bundle
- progress_reportertqdm.tqdm-like
object Used for reporting progress during installation. optional
- descriptor
- Returns
strThe directory where the bundle is installed
- Raises
TargetIsNotEmptyThrown when the target directory for installation is not empty.
- class owmeta_core.bundle.Remote(name, accessor_configs=())[source]¶
Bases:
objectA place where bundles come from and go to
- Parameters
- name
str The name of the remote
- accessor_configsiterable
ofAccessorConfig Configs for how you access the remote
- name
- add_config(accessor_config)[source]¶
Add the given accessor config to this remote
- Parameters
- accessor_config
AccessorConfig The config to add
- accessor_config
- Returns
- generate_loaders()[source]¶
Generate the bundle loaders for this remote.
Loaders are generated from
accessor_configsandLOADER_CLASSESaccording with which type ofLoadercan load a type of accessor
- classmethod read(inp)[source]¶
Read a serialized
Remote- Parameters
- inpfile object
File-like object containing the serialized
Remote
- write(out)[source]¶
Serialize the
Remoteand write toout- Parameters
- outfile object
Target for writing the remote
- accessor_configs¶
Configs for how you access the remote.
One might configure mirrors or replicas for a given bundle repository as multiple accessor configs
- file_name¶
If read from a file, the remote should have this attribute set to its source file’s path
- name¶
Name of the remote
- class owmeta_core.bundle.URLConfig(url)[source]¶
Bases:
AccessorConfigConfiguration for accessing a remote with just a URL.
Note that URLConfigs should be pickle-able since they are written to a YAML file as part of the
Remotethey’re apart of.
- owmeta_core.bundle.build_indexed_database(dest, bundle_directory, transaction_manager, progress=None, trip_prog=None)[source]¶
Build the indexed database from a bundle directory
- owmeta_core.bundle.retrieve_remotes(remotes_dir, load_entry_points=True)[source]¶
Retrieve remotes from a project directory or user remotes directory
- owmeta_core.bundle.DEFAULT_BUNDLES_DIRECTORY = '~/.owmeta/bundles'¶
Default directory for the bundle cache
- owmeta_core.bundle.DEFAULT_REMOTES_DIRECTORY = '~/.owmeta/remotes'¶
Default directory for descriptors of user-level remotes as opposed to project-specific remotes
- owmeta_core.bundle.URL_CONFIG_MAP = {'file': <class 'owmeta_core.bundle.loaders.local.FileURLConfig'>, 'http': <class 'owmeta_core.bundle.loaders.http.HTTPURLConfig'>, 'https': <class 'owmeta_core.bundle.loaders.http.HTTPSURLConfig'>}¶
URLConfigsby scheme. Can be populated by pkg_resources entry points