owmeta_core.command module¶
This module defines the root of a high-level interface for owmeta_core, refered to as
“OWM” (for the main class
in the interface), “owm” (for the command line that
wraps the interface), or “the command interface” in the documentation. Additional
“sub-commands” may be defined which provide additional functionality.
If there is a suitable method in the high-level interface, it should generally be preferred to the lower-level interfaces for stability.
- exception owmeta_core.command.AlreadyDisconnected(owm)[source]¶
Bases:
Exception
Thrown when OWM is already disconnected but a request is made to disconnect again
- exception owmeta_core.command.ConfigMissingException(key)[source]¶
Bases:
GenericUserError
Thrown when a configuration key is missing
- exception owmeta_core.command.DirtyProjectRepository[source]¶
Bases:
Exception
Thrown when we’re about to commit, but the project repository has changes to the graphs such that it’s not safe to just re-serialize the indexed database over the graphs.
- exception owmeta_core.command.InvalidGraphException[source]¶
Bases:
GenericUserError
Thrown when a graph cannot be translated due to formatting errors
- exception owmeta_core.command.NoConfigFileError(config_file_path)[source]¶
Bases:
GenericUserError
Thrown when a project config file (e.g., ‘.owm/owm.conf’) cannot be found
- exception owmeta_core.command.OWMDirMissingException[source]¶
Bases:
GenericUserError
Thrown when the .owm directory is needed, but cannot be found
- exception owmeta_core.command.StatementValidationError(statements)[source]¶
Bases:
GenericUserError
Thrown in the case that a set of statements fails to validate
- exception owmeta_core.command.UnreadableGraphException[source]¶
Bases:
GenericUserError
Thrown when a graph cannot be read due to it being missing, the active user lacking permissions, etc.
- class owmeta_core.command.NullContextRecord(node_index, statement)[source]¶
Bases:
_NullContextRecord
Stored when the identifier for the context of an object we’re saving is
None
Create new instance of _NullContextRecord(node_index, statement)
- class owmeta_core.command.OWM(owmdir=None, non_interactive=False)[source]¶
Bases:
object
High-level commands for working with owmeta data
- Attributes
- cleanup_manager
atexit
-like An object to which functions can be
registered
andunregistered
. To handle cleaning up connections that were not closed more directly (e.g., by callingdisconnect
)- progress_reporter
tqdm
-like A callable that presents some kind of progress to a user. Interface is a subset of the
tqdm.tqdm
object: the reporter must acceptunit
,miniters
,file
, andleave
options, although what it does with those is unspecified. Additionally, for reporting progress on cloning a project, anoptional interface
is required.
- cleanup_manager
- add_graph(url=None, context=None, include_imports=True)[source]¶
Fetch a graph and add it to the local store.
- Parameters
- url
str
The URL of the graph to fetch
- context
rdflib.term.URIRef
If provided, only this context and, optionally, its imported graphs will be added.
- include_importsbool
If True, imports of the named context will be included. Has no effect if context is None.
- url
- commit(message, skip_serialization=False)[source]¶
Write the graph and configuration changes to the local repository
- connect(read_only=False, expect_cleanup=False)[source]¶
Create a connection to the project database.
Most commands will create their own connections where needed, but for multiple commands you’ll want to create one connection at the start. Multiple calls to this method can be made without calling
disconnect
on the resulting connection object, but only ifread_only
has the same value for all calls.Read-only connections can only be made with the default stores: if you have configured your own store and you want the connection to be read-only, you must change the configuration to make it read-only before calling
connect
.- Parameters
- Returns
ProjectConnection
Usable as a
context manager
- declare(python_type, attributes=(), id=None)[source]¶
Create a new data object or update an existing one
- diff(color=False)[source]¶
Show differences between what’s in the working context set and what’s in the serializations
- Parameters
- colorbool
If set, then ANSI color escape codes will be incorporated into diff output. Default is to output without color.
- disconnect()[source]¶
Destroy a connection to the project database
Should not be called if there is no active connection
- imports_context(context=None, user=False)[source]¶
Read or set current target imports context for the repository
- init(update_existing_config=False, default_context_id=None)[source]¶
Makes a new graph store.
The configuration file will be created if it does not exist. If it does exist, the location of the database store will, by default, not be changed in that file
If not provided, some values will be prompted for, unless batch (non-interactive) mode is enabled. If batch mode is enabled, either an error will be returned or a default value will be used for missing options. Values which are required either in a prompt or as options are indicated as “Required” below.
- regendb()[source]¶
Regenerates the indexed database from graph serializations.
Note that any uncommitted contents in the indexed database will be deleted.
- save(module, provider=None, context=None)[source]¶
Save the data in the given context
Saves the “mapped” classes declared in a module and saves the objects declared by the “provider” (see the argument’s description)
- Parameters
- module
str
Name of the module housing the provider
- provider
str
Name of the provider, a callble that accepts a context object and adds statements to it. Can be a “dotted” name indicating attribute accesses. Default is
DEFAULT_SAVE_CALLABLE_NAME
- context
str
The target context. The default context is used
- module
- translate(translator, output_key=None, output_identifier=None, data_sources=(), named_data_sources=None)[source]¶
Do a translation with the named translator and inputs
- Parameters
- basedir¶
The base directory. owmdir is resolved against this base
- config¶
OWMConfig
: Config file commands.Without any sub-command, prints the configuration parameters
- config_file¶
The config file name
- context¶
Context to use instead of the default context. Commands that work with other contexts (e.g.,
owm contexts rm-import
) will continue to use those other contexts unless otherwise indicated
- contexts¶
OWMContexts
: Commands for working with contexts
- graph_accessor_finder¶
Finds an RDFLib graph from the given URL
- namespace¶
OWMNamespace
: RDF namespace commands
- namespace_manager_store_name¶
The file name of the namespace database store
- non_interactive¶
If this option is provided, then interactive prompts are not allowed
- owmdir¶
The base directory for owmeta files. The repository provider’s files also go under here
- registry¶
OWMRegistry
: Commands for dealing with the class registry, a mapping of RDF types to constructs in programming languagesAlthough it is called the “class registry”, the registry can map RDF types to constructs other than classes in the target programming language, particularly in languages that don’t have classes (e.g., C) or where the use of classes is not preferred in that language.
- repository_provider¶
The provider of the repository logic (cloning, initializing, committing, checkouts)
- store_name¶
The file name of the database store
- temporary_directory¶
The base temporary directory for any operations that need one
- property transaction_manager¶
The
transaction.TransactionManager
for the current connection
- translator¶
OWMTranslator
: Data source translator commands
- userdir¶
Root directory for user-specific configuration
- class owmeta_core.command.OWMConfig(parent)[source]¶
Bases:
object
Config file commands.
Without any sub-command, prints the configuration parameters
- user¶
If set, configs are only for the user; otherwise, they would be committed to the repository
- user_config_file¶
The user config file name
- class owmeta_core.command.OWMContexts(parent)[source]¶
Bases:
object
Commands for working with contexts
- bundle(context)[source]¶
Show the closest bundle that defines this context
- Parameters
- context
str
The context to lookup
- context
- edit(context=None, format=None, editor=None, list_formats=False)[source]¶
Edit a provided context or the current default context.
The file name of the serialization will be passed as the sole argument to the editor. If the editor argument is not provided, will use the EDITOR environment variable. If EDITOR is also not defined, will try a few known editors until one is found. The editor must write back to the file.
- list(include_dependencies=False, include_default=False)[source]¶
List the set of contexts in the graph
- list_importers(context)[source]¶
List the contexts that import the given context
- Parameters
- context
str
The context to list importers for
- context
- list_imports(context)[source]¶
List the contexts that the given context imports
- Parameters
- context
str
The context to list imports for
- context
- serialize(context=None, destination=None, format='nquads', include_imports=False, whole_graph=False)[source]¶
Serialize the current default context or the one provided
- Parameters
- context
str
The context to save
- destination
file
orstr
A file-like object to write the file to or a file name. If not provided, messages the result.
- format
str
Serialization format (ex, ‘n3’, ‘nquads’)
- include_importsbool
If true, then include contexts imported by the provided context in the result. The default is not to include imported contexts.
- whole_graphbool
Serialize all contexts from all graphs (this probably isn’t what you want)
- context
- class owmeta_core.command.OWMNamespace(parent)[source]¶
Bases:
object
RDF namespace commands
- class owmeta_core.command.OWMRegistry(parent)[source]¶
Bases:
object
Commands for dealing with the class registry, a mapping of RDF types to constructs in programming languages
Although it is called the “class registry”, the registry can map RDF types to constructs other than classes in the target programming language, particularly in languages that don’t have classes (e.g., C) or where the use of classes is not preferred in that language.
- list(module=None, rdf_type=None, class_name=None)[source]¶
List registered classes
- Parameters
- module
str
If provided, limits the registry entries returned to those that have the given module name. Optional.
- rdf_type
str
If provided, limits the registry entries returned to those that have the given RDF type. Optional.
- class_name
str
If provided, limits the registry entries returned to those that have the given class name. Optional.
- module
- rm(*registry_entry)[source]¶
Remove a registry entry
- Parameters
- *registry_entry
str
Registry entry to remove
- *registry_entry
- show(*registry_entry)[source]¶
Show registry entries
- Parameters
- *registry_entry
str
Registry entry to show
- *registry_entry
- module_access¶
OWMRegistryModuleAccess
: Commands for manipulating software module access in the class registry
- class owmeta_core.command.OWMRegistryModuleAccess(parent)[source]¶
Bases:
object
Commands for manipulating software module access in the class registry
- declare¶
OWMRegistryModuleAccessDeclare
: Commands for module access declarations
- show¶
OWMRegistryModuleAccessShow
: Show module accessor description
- class owmeta_core.command.OWMRegistryModuleAccessDeclare(parent)[source]¶
Bases:
object
Commands for module access declarations
- python_pip(package_name, package_version=None, index=None, module_names=None, module_id=None)[source]¶
Declare access with a Python pip package
The given module should already have been defined in the class registry. This may be achieved by the “owm save” command.
- Parameters
- package_name
str
Name of the package
- package_version
str
Version of the package. If not provided, will attempt to find the active version in package metadata
- index
str
The index to get the package from. Optional
- module_names
list
of
str
Name of the module. If not provided, will attempt to find the modules from package metadata. Multiple module names can be provided
- module_id
str
URI identifier of the module. Cannot be specified along with
module_name
- package_name
- class owmeta_core.command.OWMRegistryModuleAccessShow(parent)[source]¶
Bases:
object
Show module accessor description
- class owmeta_core.command.OWMSource(parent)[source]¶
Bases:
object
Commands for working with DataSource objects
- derivs(data_source)[source]¶
List data sources derived from the one given
- Parameters
- data_source
str
The ID of the data source to find derivatives of
- data_source
- list_kinds(full=False)[source]¶
List kinds of DataSources available in the current context.
Note that only DataSource types which are reachable from the current context will be listed. So if, for instance, you have just saved some types (e.g., with
owm save
) but have not added an import of the contexts for those types, you may not see any results from this command.- Parameters
- fullbool
Whether to (attempt to) shorten the source URIs by using the namespace manager
- class owmeta_core.command.OWMTranslator(parent)[source]¶
Bases:
object
Data source translator commands
- create(translator_type)[source]¶
Creates an instance of the given translator class and adds it to the graph
- Parameters
- translator_type
str
RDF type for the translator class
- translator_type
- list_kinds(full=False)[source]¶
List kinds of DataTranslators
Note that only DataTranslator types which are reachable from the current context will be listed. So if, for instance, you have just saved some types (e.g., with
owm save
) but have not added an import of the contexts for those types, you may not see any results from this command.- Parameters
- fullbool
Whether to (attempt to) shorten the translator URIs by using the namespace manager
- class owmeta_core.command.OWMTypes(parent)[source]¶
Bases:
object
Commands for dealing with Python classes and RDF types
- class owmeta_core.command.ProjectConnection(owm, connection, connections, *, expect_cleanup=True)[source]¶
Bases:
object
Connection to the project database
- class owmeta_core.command.SaveValidationFailureRecord(user_module, stack, validation_record)[source]¶
Bases:
_SaveValidationFailureRecord
Record of a validation failure in
OWM.save
Create new instance of _SaveValidationFailureRecord(user_module, stack, validation_record)
- class owmeta_core.command.UnimportedContextRecord(importer, context, node_index, statement)[source]¶
Bases:
_UnimportedContextRecord
Stored when statements include a reference to an object but do not include the context of that object in the callback passed to
OWM.save
. For example, if we had a callback like this:def owm_data(ns): ctxA = ns.new_context(ident='http://example.org/just-pizza-stuff') ctxB = ns.new_context(ident='http://example.org/stuff-sam-likes') sam = ctxB(Person)('sam') pizza = ctxA(Thing)('pizza') sam.likes(pizza)
it would generate this error because
ctxB
does not declare an import forctxA
Create new instance of _UnimportedContextRecord(importer, context, node_index, statement)
- owmeta_core.command.DEFAULT_SAVE_CALLABLE_NAME = 'owm_data'¶
Default name for the provider in the arguments to
OWM.save
- owmeta_core.command.DSD_DIRKEY = 'owmeta_core.command.OWMDirDataSourceDirLoader'¶
Key used for data source directory loader and file path provider