API reference#

dso.WatermarkedFile(output_file, **kwargs)#

Contextmanager that handles adding watermarks to files.

Currently supports SVG, PDF and all pixel graphics supported by pillow.

Parameters:
  • output_file (Path | str) – Path to final (watermarked) image.

  • kwargs – Use this to customize watermarks. Takes precedence over the configuration in params.

Yields:
  • Temporary filename to which the non-watermarked file needs to be written.

  • If no watermark configuration is present (neither in params nor in kwargs),

  • yields the output file path directly without applying any watermark.

Example

>>> fig, ax = plt.subplots()
>>> ax.plot(range(10), range(10))
>>> with dso.WatermarkedFile(stage_here("output/plot.pdf")) as f:
        fig.savefig(f, bbox_inches="tight")
dso.here(rel_path=None)#

Get project root as a Path object

Parameters:

rel_path (str | Path | None (default: None)) – Relative path to be appended to the project root

Return type:

Path

dso.read_params(stage)#

Set stage dir and load parameters from the stage’s params.yaml

It is required to provide the path of the current stage relative to the project root to ensure that the correct config is loaded, no matter of the current working directory (as long as the working directory is any subdirectory of the project root). The function recompiles params.in.yaml to params.yaml on-the-fly to ensure that up-to-date params are always loaded.

Only parameters that are declared as params, dep, or output in dvc.yaml are loaded to ensure that one does not forget to keep the dvc.yaml updated.

Calls set_stage() internally.

Parameters:

stage (str | Path) – Path to stage, relative to the project root

Return type:

dict

dso.set_stage(stage)#

Set the active stage for stage_here()

This sets the stage dir in dso.CONFIG.

Parameters:

stage (str | Path) – Path to stage, relative to the project root

Return type:

None

dso.stage_here(rel_path=None)#

Get the absolute path to the current stage

The current stage is stored in dso.CONFIG and can be set using dso.set_stage() or dso.read_params().

Parameters:

rel_path (str | Path | None (default: None)) – Relative path to be appended to the stage root

Return type:

Path