Skip to content

Commit

Permalink
remove TemplateOption
Browse files Browse the repository at this point in the history
  • Loading branch information
diehlbw committed Sep 24, 2024
1 parent b3da44e commit c9c8399
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 181 deletions.
1 change: 0 additions & 1 deletion src/seismometer/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .config import ConfigProvider
from .model import AggregationStrategies, MergeStrategies
from .options import Option, TemplateOptions, template_options
21 changes: 4 additions & 17 deletions src/seismometer/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from seismometer.core.io import load_yaml

from .model import DataUsage, Event, EventDictionary, OtherInfo, PredictionDictionary
from .options import Option, template_options


class ConfigProvider:
Expand All @@ -32,7 +31,7 @@ class ConfigProvider:
data_dir : Optional[str | Path], optional
Specifies the path to the data directory, by default None; it uses data_dir from the primary config file,
which is where data dictionaries are written/read.
template_notebook : Optional[Option], optional
template_notebook : Optional[object], optional
Unused.
definitions : Optional[dict], optional
A dictionary of definitions to use instead of loading those specified by configuration, by default None.
Expand All @@ -48,7 +47,7 @@ def __init__(
usage_config: str | Path = None,
info_dir: str | Path = None,
data_dir: str | Path = None,
template_notebook: Option = None,
template_notebook: object = None,
definitions: dict = None,
output_path: str | Path = None,
):
Expand Down Expand Up @@ -118,17 +117,9 @@ def config(self, config_def: OtherInfo):
self._template = None

@property
def template(self) -> Option:
def template(self) -> None:
"""The template used for building a model-specific seismograph notebook."""
if self._template is None:
template_name = self.config.template
if template_name not in template_options:
raise ValueError(
f"Template option {template_name} not found in known options: {', '.join(template_options)}"
)
self._template = template_options[template_name]

return self._template
raise NotImplementedError("Template building is not implemented")

@property
def info_dir(self) -> Path:
Expand Down Expand Up @@ -385,11 +376,7 @@ def set_output(self, output: Path, nb_prefix: str = ""):
output = output.resolve()
if not output.suffix: # no suffix implies directory
self._output_dir = output
filename = self.template.value
if filename:
self._output_notebook = nb_prefix + filename.name
else: # file specified
self._output_notebook = output.name
if str(output.parent) == ".": # No path given, use config
self._output_dir = self.info_dir or output.parent
else:
Expand Down
77 changes: 0 additions & 77 deletions src/seismometer/configuration/options.py

This file was deleted.

15 changes: 2 additions & 13 deletions src/seismometer/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,20 @@ def resolve_filename(
# region load functions


def load_notebook(*, nb_template: "Option" = None, filepath: Optional[Pathlike] = None) -> nbformat.NotebookNode:
def load_notebook(filepath: Pathlike) -> nbformat.NotebookNode:
"""
Loads a notebook from a file.
Can load a notebook from a template Option or from file; prioritizing the path.
Parameters
----------
nb_template : Optional[Option], optional
The template to load, by default None.
filepath : Optional[Pathlike], optional
filepath : Pathlike, optional
The path to a notebook, by default None.
Returns
-------
nbformat.NotebookNode
The loaded notebook.
"""
if filepath is None:
try:
filepath = nb_template.value
except AttributeError:
raise ValueError("Either a valid nb_template or a filepath for the template notebook must be provided.")

return _load(read_ipynb, filepath)


Expand Down
60 changes: 0 additions & 60 deletions tests/configuration/test_options.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/configuration/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class TestConfigProvider:
("interventions", {}),
("prediction_columns", ["Age", "Input", "Score", "ScoringTime", "encounter_id", "id"]),
("censor_min_count", 15),
("output_notebook", "classifier_bin.ipynb"),
],
)
def test_testconfig_is_valid_simple_object(self, property, value, res):
Expand Down
13 changes: 1 addition & 12 deletions tests/core/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from conftest import res, tmp_as_current # noqa: F401

import seismometer.core.io as undertest
from seismometer.configuration.options import Option


class Test_IO:
Expand Down Expand Up @@ -46,7 +45,7 @@ def test_slugify_raises(self, string):

@pytest.fixture
def testdir(res) -> Path:
return res / "builder"
return res / "io"


# region Loaders
Expand All @@ -72,16 +71,6 @@ class TestLoadNotebook:
+ '"nbformat": 4, "nbformat_minor": 2}'
)

def test_load_notebook_with_invalid_input(self):
with pytest.raises(ValueError):
_ = undertest.load_notebook()

def test_load_notebook_with_nb_template(self, testdir):
file = testdir / TestLoadNotebook.filepath
nb_template = Option(value=file, name="test")
result = undertest.load_notebook(nb_template=nb_template)
assert result == TestLoadNotebook.expected

def test_load_notebook_with_filepath(self, testdir):
filepath = testdir / TestLoadNotebook.filepath
result = undertest.load_notebook(filepath=filepath)
Expand Down

0 comments on commit c9c8399

Please sign in to comment.