Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduces utils.structs
Browse files Browse the repository at this point in the history
- add test for LazyOption init
- move ZnTypes and DVCOptions to structs module
PythonFZ committed Mar 5, 2022
1 parent d51d7d3 commit ea260b9
Showing 4 changed files with 62 additions and 53 deletions.
8 changes: 8 additions & 0 deletions tests/unit_tests/utlis/test_structs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

from zntrack.utils.structs import LazyOption


def test_noLazyOptionInit():
with pytest.raises(ValueError):
LazyOption()
15 changes: 4 additions & 11 deletions zntrack/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@
"""

from zntrack.utils import exceptions, file_io
from zntrack.utils.config import (
from zntrack.utils.config import Files, config
from zntrack.utils.structs import (
FILE_DVC_TRACKED,
VALUE_DVC_TRACKED,
DVCOptions,
Files,
LazyOption,
ZnTypes,
config,
)
from zntrack.utils.utils import (
check_type,
@@ -52,12 +52,5 @@
"FILE_DVC_TRACKED",
"VALUE_DVC_TRACKED",
"DVCOptions",
"LazyOption",
]


class LazyOption:
def __init__(self):
raise ValueError(
"Can not initialize LazyOption. If you expected something else open an "
"issue at https://github.com/zincware/ZnTrack and describe how you got here."
)
42 changes: 0 additions & 42 deletions zntrack/utils/config.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
Description: Configuration File for ZnTrack
"""
import dataclasses
import enum
import logging
from pathlib import Path

@@ -70,45 +69,4 @@ class Files:
params: Path = Path("params.yaml")


class ZnTypes(enum.Enum):
"""Collection of ZnTrack Types to identify descriptors beyond their dvc option
Attributes
----------
results: most zn.<options> like zn.outs() / zn.metrics() use this one
"""

DEPS = enum.auto()
DVC = enum.auto()
METADATA = enum.auto()
# method = enum.auto()
PARAMS = enum.auto()
ITERABLE = enum.auto()
RESULTS = enum.auto()


FILE_DVC_TRACKED = [ZnTypes.DVC]
# if the getattr(instance, self.name) is an affected file,
# e.g. the dvc.<outs> is a file / list of files
VALUE_DVC_TRACKED = [ZnTypes.RESULTS, ZnTypes.METADATA]


# if the internal file,
# e.g. in the case of zn.outs() like nodes/<node_name>/outs.json is an affected file


class DVCOptions(enum.Enum):
# Use enum over dataclass because it is iterable
PARAMS = "params"
DEPS = "deps"
OUTS = "outs"
CHECKPOINTS = "checkpoints"
OUTS_NO_CACHE = "outs_no_cache"
OUTS_PERSISTENT = "outs_persistent"
METRICS = "metrics"
METRICS_NO_CACHE = "metrics_no_cache"
PLOTS = "plots"
PLOTS_NO_CACHE = "plots_no_cache"


config = Config()
50 changes: 50 additions & 0 deletions zntrack/utils/structs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import enum


class LazyOption:
def __init__(self):
raise ValueError(
"Can not initialize LazyOption. If you expected something else open an "
"issue at https://github.com/zincware/ZnTrack and describe how you got here."
)


class ZnTypes(enum.Enum):
"""Collection of ZnTrack Types to identify descriptors beyond their dvc option
Attributes
----------
results: most zn.<options> like zn.outs() / zn.metrics() use this one
"""

DEPS = enum.auto()
DVC = enum.auto()
METADATA = enum.auto()
# method = enum.auto()
PARAMS = enum.auto()
ITERABLE = enum.auto()
RESULTS = enum.auto()


FILE_DVC_TRACKED = [ZnTypes.DVC]
# if the getattr(instance, self.name) is an affected file,
# e.g. the dvc.<outs> is a file / list of files
VALUE_DVC_TRACKED = [ZnTypes.RESULTS, ZnTypes.METADATA]


# if the internal file,
# e.g. in the case of zn.outs() like nodes/<node_name>/outs.json is an affected file


class DVCOptions(enum.Enum):
# Use enum over dataclass because it is iterable
PARAMS = "params"
DEPS = "deps"
OUTS = "outs"
CHECKPOINTS = "checkpoints"
OUTS_NO_CACHE = "outs_no_cache"
OUTS_PERSISTENT = "outs_persistent"
METRICS = "metrics"
METRICS_NO_CACHE = "metrics_no_cache"
PLOTS = "plots"
PLOTS_NO_CACHE = "plots_no_cache"

0 comments on commit ea260b9

Please sign in to comment.