@@ -269,273 +269,3 @@ def load(base_dir: str, pipeline_name: str | None = None):
269269
270270def save (config : Config ):
271271 config .save ()
272-
273-
274- # import os
275- # from pathlib import Path
276-
277- # import yaml
278- # from hamilton.function_modifiers import source, value
279- # from munch import Munch, munchify, unmunchify
280-
281- # from .helpers.templates import (
282- # PIPELINE_TEMPLATE, # noqa: F401
283- # SCHEDULER_TEMPLATE, # noqa: F401
284- # TRACKER_TEMPLATE, # noqa: F401
285- # )
286-
287-
288- # class BaseConfig:
289- # def __init__(self, name: str, base_dir: str | None = None) -> None:
290- # self._base_dir = base_dir or ""
291- # self._base_dir = str(self._base_dir).rstrip("/")
292- # if self._base_dir.endswith("conf"):
293- # self._base_dir = self._base_dir.rstrip("conf").rstrip("/")
294- # self.name = name
295- # self._path = os.path.join(self._base_dir, "conf", self.name + ".yml")
296-
297- # def load(self):
298- # """
299- # Load the configuration parameters from a YAML file.
300-
301- # Args:
302- # path (str): The path to the YAML file.
303-
304- # Returns:
305- # dict: The loaded configuration parameters.
306- # """
307- # if Path(self._path).exists():
308- # with open(self._path) as f:
309- # self._cfg = munchify(yaml.full_load(f))
310- # else:
311- # self._cfg = None
312-
313- # def write(self) -> None:
314- # """
315- # Write the configuration to a YAML file.
316-
317- # Args:
318- # cfg (dict | Munch): The configuration to be written.
319- # name (str): The name of the file.
320-
321- # Returns:
322- # None
323- # """
324-
325- # with open(self._path, "w") as f:
326- # f.write(
327- # eval(f"{self.name.upper()}_TEMPLATE")
328- # + yaml.dump(unmunchify(self._cfg), sort_keys=False)
329- # .replace("null", "")
330- # .replace("{}", "")
331- # )
332-
333- # def update(self, cfg: dict | Munch) -> None:
334- # """
335- # Update the configuration with the given parameters.
336-
337- # Args:
338- # cfg (dict | Munch): The parameters to update the configuration with.
339- # name (str): The name of the configuration.
340-
341- # Returns:
342- # None
343- # """
344- # if self._cfg is None:
345- # self._cfg = munchify(cfg)
346- # else:
347- # self._cfg.update(cfg)
348- # # self._write()
349-
350-
351- # class TrackerConfig(BaseConfig):
352- # name = "tracker"
353- # init_cfg = {
354- # "username": None,
355- # "api_url": "http://localhost:8241",
356- # "ui_url": "http://localhost:8242",
357- # "api_key": None,
358- # "pipeline": {},
359- # }
360-
361- # def __init__(self, base_dir: str | None = None) -> None:
362- # super().__init__(self.name, base_dir)
363-
364- # self.load()
365- # self._cfg = self._cfg or munchify(self.init_cfg)
366-
367-
368- # class SchedulerConfig(BaseConfig):
369- # name = "scheduler"
370- # init_cfg = {
371- # "data_store": {"type": "memory"},
372- # "event_broker": {"type": "local"},
373- # "cleanup_interval": {"unit": "minutes", "value": 15},
374- # "pipeline": {},
375- # }
376-
377- # def __init__(self, base_dir: str | None = None) -> None:
378- # super().__init__(self.name, base_dir)
379-
380- # self.load()
381- # self._cfg = self._cfg or munchify(self.init_cfg)
382-
383-
384- # class PipelineConfig(BaseConfig):
385- # name = "pipeline"
386- # init_cfg = {
387- # "run": {},
388- # # {
389- # # "dev": {"inputs": None, "final_vars": None, "with_tracker": False},
390- # # "prod": {"inputs": None, "final_vars": None, "with_tracker": True},
391- # # },
392- # "params": {},
393- # }
394-
395- # def __init__(self, base_dir: str | None = None) -> None:
396- # super().__init__(self.name, base_dir)
397-
398- # self.load()
399- # self._cfg = self._cfg or munchify(self.init_cfg)
400-
401- # def _to_ht_params(self, d: dict, parent_dict: dict | None = None):
402- # """
403- # Recursively converts the values in a dictionary to `source` or `value` objects.
404-
405- # Args:
406- # d (dict): The dictionary to convert.
407- # parent_dict (dict | None): The parent dictionary. Defaults to None.
408-
409- # Returns:
410- # dict: The converted dictionary.
411- # """
412-
413- # if parent_dict is None:
414- # parent_dict = d
415-
416- # for k, v in d.items():
417- # if isinstance(v, str):
418- # if v in parent_dict:
419- # d[k] = source(v)
420- # else:
421- # d[k] = value(v)
422- # else:
423- # d[k] = value(v)
424- # return d
425-
426- # def _to_ht_parameterization(self, d: dict) -> dict:
427- # """
428- # Convert a dictionary into a parameterization dictionary.
429-
430- # Args:
431- # d (dict): The input dictionary.
432-
433- # Returns:
434- # dict: The parameterization dictionary.
435-
436- # """
437- # return {k: {k: d[k]} for k in d}
438-
439- # def load(self):
440- # """
441- # Load the configuration parameters.
442-
443- # This method loads the configuration parameters from the specified file path.
444- # It updates the parameters dictionary with the loaded values and converts
445- # certain values to a specific format using the `_to_ht_params` and
446- # `_to_ht_parameterization` methods.
447-
448- # Returns:
449- # None
450- # """
451- # ...
452- # super().load()
453- # if self._cfg is None:
454- # return
455-
456- # self._params = self._cfg.params.copy() if self._cfg.params is not None else {}
457-
458- # for node in self._params:
459- # if self._params[node] is None:
460- # continue
461- # self._params[node].update(
462- # {
463- # k: self._to_ht_params(v)
464- # for k, v in self._params[node].items()
465- # if v is not None
466- # }
467- # )
468- # self._params.update(
469- # {
470- # k: self._to_ht_parameterization(v)
471- # for k, v in self._params.items()
472- # if v is not None
473- # }
474- # )
475- # self._params = munchify(self._params)
476-
477-
478- # class Config:
479- # def __init__(self, base_dir: str | None = None) -> None:
480- # self._tracker = TrackerConfig(base_dir)
481- # self._scheduler = SchedulerConfig(base_dir)
482- # self._pipeline = PipelineConfig(base_dir)
483-
484- # def update(
485- # self,
486- # cfg: dict | Munch,
487- # name: str,
488- # ) -> None:
489- # """
490- # Update the configuration with the given parameters.
491-
492- # Args:
493- # cfg (dict | Munch): The parameters to update the configuration with.
494- # name (str): The name of the configuration.
495-
496- # Returns:
497- # None
498- # """
499- # if name == "pipeline":
500- # self._pipeline.update(cfg)
501- # if name == "tracker":
502- # self._tracker.update(cfg)
503- # if name == "scheduler":
504- # self._scheduler.update(cfg)
505-
506- # def write(
507- # self, pipeline: bool = False, tracker: bool = False, scheduler: bool = False
508- # ) -> None:
509- # """
510- # Write the configuration to file.
511-
512- # Args:
513- # pipeline (bool): If True, write the pipeline configuration to file.
514- # tracker (bool): If True, write the tracker configuration to file.
515- # scheduler (bool): If True, write the scheduler configuration to file.
516-
517- # Returns:
518- # None
519- # """
520- # if pipeline:
521- # self._pipeline.write()
522- # if tracker:
523- # self._tracker.write()
524- # if scheduler:
525- # self._scheduler.write()
526-
527- # @property
528- # def pipeline(self):
529- # return self._pipeline._cfg
530-
531- # @property
532- # def scheduler(self):
533- # return self._scheduler._cfg
534-
535- # @property
536- # def tracker(self):
537- # return self._tracker._cfg
538-
539- # @property
540- # def pipeline_params(self):
541- # return self._pipeline._params
0 commit comments