snakeobjects package¶
This is snakeobject python package.
Project class¶
-
class
Project(directory=None)¶ Each objects of the Project class represents a snakeobject project.
The project directory is given as the
directoryparameter. Ifdirectoryis none, thefind_so_project_directory()function is used to determine the project directory.A snakeobject project attributes are:
-
directory: str¶ the project directory
-
parameters: dict[str, str]¶ a key value dictionary for global project level parameters
-
objectGraph: ObjectGraph¶ the objectGraph for the project
Project useful functions are:
-
get_object_directory(object_instance)¶ returns directory of object
-
get_object_path(type_name, object_name)¶ return path to the object of type type_name, and object name object_name
-
get_pipeline_directory¶ returns path to the project pipeline directory
-
get_parameter(name, parent_project_id=None)¶ If parent_project_id is given returns the value of parameter in that project, otherwise, if name is in project parameters, returns its value. Finally, if name is not in the project parameters, returns the value of named parameters in the first project recursively folowing parent projects.
-
ObjectGraph class¶
-
class
ObjectGraph¶ The class representing the directed acyclic graph representing the relationships among the snakeobjects’ objects. Each object is defined by a set an object type and by object id.
-
__getitem__(key)¶ Query objects in the object graph.
- Parameters
key (oType or (oType,oOid)) – the object query
The graph (G) indexing has two forms depending of the key parameter:
G[oType]returns the list of the objects of typeoType;G[oType,oId]returns the object with object idoIdand object type typeoType.
- Return type
list(OGO) if form 1 is used or OGO if form 2 is used
-
add(oType, oId, params=None, deps=None)¶ Adds a new object to the object graph.
- Parameters
oType (str) – the object type of the new object.
oId (str) – the object id of the new object.
params (dict[str,str]) – the parameters of the new object. If None, the new object is assigned with no parameters.
deps (list[OGO]) – list objects the new object depends on. If None, the new object depends on no other objects. The objects included in deps should already be part of the
ObjectGraph.
- Returns
the newly created object.
- Return type
-
get_object_types()¶ The object types used in the ObjectGraph
-
save(outFile)¶ Save the object graph in a json file
outFile.
-
-
class
OGO(oType, oId, params=None, deps=None)¶ The class represents the objects in an
ObjectGraph. Each object has the following attributes:-
oType: str¶ the object type of the object
-
oId: str¶ the object id of the object
-
params: dict[str, str]¶ the key-value parameters of the object
-
find_project_directory function¶
-
find_so_project_directory()¶ Determines the directory for the current snakeobjects project.
Several approaches are attempted and the first suitable directory found is returned. If everything fails, the current working directory is returned.
If the SO_PROJECT environment variable exits, its values is returned.
If the current working directory contains a file named so_project.yaml, the current working directory is returned.
The parents of the current working directory are examined recursively and the first one containing so_project.yaml file is returned.
load_object_graph function¶
-
load_object_graph(fname)¶