Repository

High-level saving and loading functionality for dman.

dman.model.repository.uninterrupted()[source]

Return context that suppresses keyboard interrupts until it exists.

dman.model.repository.context(key: str, *, subdir: PathLike = '', cluster: bool = True, verbose: int = None, generator: str = None, base: PathLike = None, gitignore: bool = True)[source]
Get a context from a mount point.

The path of the file is determined as described below.

If the files are clustered then the path is <base>/<generator>/<subdir>/<key>/<key>.<ext> If cluster is set to False then the path is <base>/<generator>/<subdir>/<key>.<ext>

When base is not provided then it is set to .dman if it does not exist an exception is raised.

When generator is not provided it will automatically be set based on the location of the script relative to the .dman folder (again raising an exception if it is not found). For example if the script is located in <project-root>/examples/folder/script.py and .dman is located in <project-root>/.dman. Then generator is set to cache/examples:folder:script (i.e. the / is replaced by : in the output).

Parameters:
  • key (str) – Key for the file.

  • subdir (os.PathLike, optional) – Specifies optional subdirectory in generator folder. Defaults to “”.

  • cluster (bool, optional) – A subfolder key is automatically created when set to True. Defaults to True.

  • verbose (bool, optional) – Level of verbosity. Defaults to False

  • generator (str, optional) – Specifies the generator that created the file. Defaults to script label.

  • base (os.PathLike, optional) – Specifies the root folder. Defaults to “.dman”.

  • gitignore (bool, optional) – Specifies whether files added to this mount point should be ignored.

dman.model.repository.store(key: str, obj, *, subdir: PathLike = '', cluster: bool = False, verbose: Optional[int] = None, gitignore: bool = True, generator: Optional[str] = None, base: Optional[PathLike] = None)[source]
Save a storable object.

The path of the file is determined as described below.

If the files are clustered then the path is <base>/<generator>/<subdir>/<key>/<key>.<ext> If cluster is set to False then the path is <base>/<generator>/<subdir>/<key>.<ext>

When base is not provided then it is set to .dman if it does not exist an exception is raised.

When generator is not provided it will automatically be set based on the location of the script relative to the .dman folder (again raising an exception if it is not found). For example if the script is located in <project-root>/examples/folder/script.py and .dman is located in <project-root>/.dman. Then generator is set to cache/examples:folder:script (i.e. the / is replaced by : in the output).

Parameters:
  • key (str) – Key for the file.

  • obj (Any) – The storable to store.

  • subdir (os.PathLike, optional) – Specifies optional subdirectory in generator folder. Defaults to “”.

  • cluster (bool, optional) – A subfolder key is automatically created when set to True. Defaults to True.

  • verbose (bool, optional) – Level of verbosity. Defaults to False

  • generator (str, optional) – Specifies the generator that created the file. Defaults to script label.

  • base (os.PathLike, optional) – Specifies the root folder. Defaults to “.dman”.

  • gitignore (bool, optional) – Specifies whether files added to this mount point should be ignored.

dman.model.repository.save(key: str, obj, *, subdir: PathLike = '', cluster: bool = True, verbose: Optional[int] = None, validate: Optional[bool] = None, gitignore: bool = True, generator: Optional[str] = None, base: Optional[PathLike] = None)[source]
Save a serializable object to a file.

The path of the file is determined as described below.

If the files are clustered then the path is <base>/<generator>/<subdir>/<key>/<key>.<ext> If cluster is set to False then the path is <base>/<generator>/<subdir>/<key>.<ext>

When base is not provided then it is set to .dman if it does not exist an exception is raised.

When generator is not provided it will automatically be set based on the location of the script relative to the .dman folder (again raising an exception if it is not found). For example if the script is located in <project-root>/examples/folder/script.py and .dman is located in <project-root>/.dman. Then generator is set to cache/examples:folder:script (i.e. the / is replaced by : in the output).

Parameters:
  • key (str) – Key for the file.

  • obj (Any) – The serializable to save.

  • subdir (os.PathLike, optional) – Specifies optional subdirectory in generator folder. Defaults to “”.

  • cluster (bool, optional) – A subfolder key is automatically created when set to True. Defaults to True.

  • verbose (bool, optional) – Level of verbosity. Defaults to False

  • generator (str, optional) – Specifies the generator that created the file. Defaults to script label.

  • base (os.PathLike, optional) – Specifies the root folder. Defaults to “.dman”.

  • gitignore (bool, optional) – Specifies whether files added to this mount point should be ignored.

dman.model.repository.load(key: str, *, default=<dataclasses._MISSING_TYPE object>, default_factory=<dataclasses._MISSING_TYPE object>, subdir: ~os.PathLike = '', cluster: bool = True, verbose: ~typing.Optional[int] = None, gitignore: bool = True, generator: ~typing.Optional[str] = None, base: ~typing.Optional[~os.PathLike] = None)[source]
Load a serializable or storable object from a file.

A default value can be provided, which is returned when no file is found. Similarly default_factory is a function without arguments that is called instead of default. If both default and default_factory are specified then the value in default is returned.

The path of the file is determined as described below.

If the files are clustered then the path is <base>/<generator>/<subdir>/<key>/<key>.<ext> If cluster is set to False then the path is <base>/<generator>/<subdir>/<key>.<ext>

When base is not provided then it is set to .dman if it does not exist an exception is raised.

When generator is not provided it will automatically be set based on the location of the script relative to the .dman folder (again raising an exception if it is not found). For example if the script is located in <project-root>/examples/folder/script.py and .dman is located in <project-root>/.dman. Then generator is set to cache/examples:folder:script (i.e. the / is replaced by : in the output).

Parameters:
  • key (str) – Key for the file.

  • default (Any, optional) – The default value.

  • default_factory (Callable, optional) – Method with no argument that produces the default value.

  • subdir (os.PathLike, optional) – Specifies optional subdirectory in generator folder. Defaults to “”.

  • cluster (bool, optional) – A subfolder key is automatically created when set to True. Defaults to True.

  • verbose (bool, optional) – Level of verbosity. Defaults to False

  • generator (str, optional) – Specifies the generator that created the file. Defaults to script label.

  • base (os.PathLike, optional) – Specifies the root folder. Defaults to “.dman”.

  • gitignore (bool, optional) – Specifies whether files added to this mount point should be ignored.

Returns:

Loaded object or default value if file does not exist.

dman.model.repository.clean(key: str, *, subdir: PathLike = '', cluster: bool = True, verbose: Optional[int] = None, generator: Optional[str] = None, base: Optional[PathLike] = None)[source]
Remove a serializable object.

The path of the file is determined as described below.

If the files are clustered then the path is <base>/<generator>/<subdir>/<key>/<key>.<ext> If cluster is set to False then the path is <base>/<generator>/<subdir>/<key>.<ext>

When base is not provided then it is set to .dman if it does not exist an exception is raised.

When generator is not provided it will automatically be set based on the location of the script relative to the .dman folder (again raising an exception if it is not found). For example if the script is located in <project-root>/examples/folder/script.py and .dman is located in <project-root>/.dman. Then generator is set to cache/examples:folder:script (i.e. the / is replaced by : in the output).

Parameters:
  • key (str) – Key for the file.

  • subdir (os.PathLike, optional) – Specifies optional subdirectory in generator folder. Defaults to “”.

  • cluster (bool, optional) – A subfolder key is automatically created when set to True. Defaults to True.

  • verbose (bool, optional) – Level of verbosity. Defaults to False

  • generator (str, optional) – Specifies the generator that created the file. Defaults to script label.

  • base (os.PathLike, optional) – Specifies the root folder. Defaults to “.dman”.

dman.model.repository.track(key: str, *, default=<dataclasses._MISSING_TYPE object>, default_factory=<dataclasses._MISSING_TYPE object>, subdir: ~os.PathLike = '', cluster: bool = True, verbose: ~typing.Optional[int] = None, gitignore: bool = True, generator: ~typing.Optional[str] = None, base: ~typing.Optional[~os.PathLike] = None)[source]
Create track a serializable or storable object with a file.

Ideally track is used as a context: i.e. with track(...) as obj: .... When the context is entered the object is loaded from a file (or default value is returned as described below). When the context exits, then the file is saved.

If the object is storable, it will automatically be wrapped in a record before serialization.

The path of the file is determined as described below.

If the files are clustered then the path is <base>/<generator>/<subdir>/<key>/<key>.<ext> If cluster is set to False then the path is <base>/<generator>/<subdir>/<key>.<ext>

When base is not provided then it is set to .dman if it does not exist an exception is raised.

When generator is not provided it will automatically be set based on the location of the script relative to the .dman folder (again raising an exception if it is not found). For example if the script is located in <project-root>/examples/folder/script.py and .dman is located in <project-root>/.dman. Then generator is set to cache/examples:folder:script (i.e. the / is replaced by : in the output).

Parameters:
  • key (str) – Key for the file.

  • default (Any, optional) – The default value.

  • default_factory (Callable, optional) – Method with no argument that produces the default value.

  • subdir (os.PathLike, optional) – Specifies optional subdirectory in generator folder. Defaults to “”.

  • cluster (bool, optional) – A subfolder key is automatically created when set to True. Defaults to True.

  • verbose (bool, optional) – Level of verbosity. Defaults to False

  • generator (str, optional) – Specifies the generator that created the file. Defaults to script label.

  • base (os.PathLike, optional) – Specifies the root folder. Defaults to “.dman”.

  • gitignore (bool, optional) – Specifies whether files added to this mount point should be ignored.