API
pymerit
Standardized metadata generation and processing.
This package provides:
- Simple format for the metadata
- Handlers to load and store metadata
Base
Base classes for metadata including a metaclass to enable tracking of the schema-specific classes.
-
class
pymerit.base.MeritBase(*args, **kwargs)[source]
Base abstract class for pymerit schema implementors
-
description
Property-like access to metadata description element
-
dump()[source]
Return the metadata as a dictionary
-
dumps()[source]
Dump the internal structure into JSON-formatted string
-
classmethod
find_handler(schema)[source]
Short form of find_handler_for_schema
-
classmethod
find_handler_for_dict(dct)[source]
Find the handler class and load dict
A class can load one or more schema types.
-
classmethod
find_handler_for_schema(schema)[source]
Find loader for a given schema.
A class can load one or more schema types.
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
load(metadata)[source]
Load a dictionary. Call element-specific handler if it exists.
-
loads(s)[source]
Load a serialized string into a object
-
metadata = None
Internal dict representation of the metadata
required elements: name, description
-
name
Property-like access to metadata name element
-
prettyprint(max_width=80)[source]
Dump content in a neat form..
-
schema = 'default:base:v1'
Every Merit metadata class should specify a schema (a
string or a list of strings)
-
classmethod
schema_get(schemas)[source]
List known schemas and handling classes
-
classmethod
schema_list()[source]
List known schemas and handling classes
-
classmethod
schema_register(targetcls)[source]
Register class
-
classmethod
schema_unregister(targetcls)[source]
Unregister cls
-
validate(metadata=None)[source]
Check if the metadata is valid
| Parameters: | metadata (dict) – Optional metadata dict to be validated.
If not specified, will use the class’s metadata attribute. |
-
classmethod
validate_cls(targetcls, dct)[source]
Validate the class implementing schema
-
class
pymerit.base.MeritContextBase(*args, **kwargs)[source]
Baseclass for context schemas
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
class
pymerit.base.MeritGlobalBase(*args, **kwargs)[source]
Base abstract class for pymerit schema implementors
-
add_context(c)[source]
Add a context (e.g., host info) to metadata
-
add_resource(r)[source]
Add a resource (e.g., file) to metadata
-
dump_contexts(contexts)[source]
Dump contexts
-
dump_resources(resources)[source]
Dump resources
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
load_contexts(contexts)[source]
Validate and load contexts
-
load_resources(resources)[source]
Validate and load resourcess
-
class
pymerit.base.MeritMeta(name, bases, dct)[source]
Meta class for all elements with schemas. This allows for
registration, validation, and tracking of the schema implementors.
-
class
pymerit.base.MeritResourceBase(*args, **kwargs)[source]
Baseclass for resource schemas
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
Extensible pymerit libraries
-
class
pymerit.contrib.MeritContextPlatform(*args, **kwargs)[source]
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
class
pymerit.contrib.MeritContextProcess(*args, **kwargs)[source]
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
class
pymerit.contrib.MeritDefault(*args, **kwargs)[source]
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
class
pymerit.contrib.MeritResourceFile(*args, **kwargs)[source]
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
-
validate_path(path)[source]
Check if the path exists
-
class
pymerit.contrib.MeritResourceS3File(*args, **kwargs)[source]
-
initialize(*args, **kwargs)[source]
Initialize the state of the metadata object
Exceptions
-
exception
pymerit.exceptions.MeritDuplicateSchema[source]
Another handler exists for the given schema
-
exception
pymerit.exceptions.MeritInvalidAttribute[source]
Invalid name specified to generate the class attribute
-
exception
pymerit.exceptions.MeritInvalidContext[source]
Invalid class specified while adding context
-
exception
pymerit.exceptions.MeritInvalidMetadata[source]
Metadata cannot be loaded due to missing fields
-
exception
pymerit.exceptions.MeritInvalidResource[source]
Invalid class specified while adding resource
-
exception
pymerit.exceptions.MeritInvalidSchema[source]
Invalid schema definition
-
exception
pymerit.exceptions.MeritMissingSchema[source]
Schema not defined in the given merit subclass
-
exception
pymerit.exceptions.MeritNoAttribute[source]
Internal metadata does not have the required attribute
-
exception
pymerit.exceptions.MeritNoHandler[source]
Not class to handle metadata with a given schema
-
exception
pymerit.exceptions.MeritNotRegistered[source]
Class not a registered handler for any schema
Utils
Helper functions
-
pymerit.utils.all_subclasses(cls)[source]
Find all subclasses of a class
| Return type: | object |
| Returns: | “Set of subclasses” |
| Parameters: | cls (object) – Baseclass |
-
pymerit.utils.find_handler(schema)[source]
Find handler classes
| Parameters: | schema (str) – Schema to find handler for |
-
pymerit.utils.new(metadata, mode='json')[source]
Create Merit object from dictionary
| Parameters: | metadata (dict) – Metadata to be loaded |
-
pymerit.utils.schema_register(cls)[source]
Register a new handler class
| Parameters: | cls (class) – Handler class |
-
pymerit.utils.schema_unregister(cls)[source]
Unregister a handler class
| Parameters: | cls (class) – Handler class |
CLI
merit
CLI for merit metadata files
merit [OPTIONS] COMMAND [ARGS]...
schema
Discovery and operation
merit schema [OPTIONS] COMMAND [ARGS]...
list
List available schemas
merit schema list [OPTIONS]
show
Show details of a schema
merit schema show [OPTIONS] SCHEMA
Arguments
-
SCHEMA
Required argument