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 directory parameter. If directory is none, the find_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

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:

  1. G[oType] returns the list of the objects of type oType;

  2. G[oType,oId] returns the object with object id oId and object type type oType.

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

OGO

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

oOid: str

the object id of the object

params: dict[str, str]

the key-value parameters of the object

deps: list[OGO]

the list of the dependency objects (other objects this object depends on)

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.

  1. If the SO_PROJECT environment variable exits, its values is returned.

  2. If the current working directory contains a file named so_project.yaml, the current working directory is returned.

  3. 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)