def __enter__(self) -> "TaskTestFunction": try: config_dir, config_name = split_config_path( self.config_path, self.config_name) job_name = detect_task_name(self.calling_file, self.calling_module) self.hydra = Hydra.create_main_hydra_file_or_module( calling_file=self.calling_file, calling_module=self.calling_module, config_path=config_dir, job_name=job_name, strict=self.strict, ) self.temp_dir = tempfile.mkdtemp() overrides = copy.deepcopy(self.overrides) assert overrides is not None overrides.append(f"hydra.run.dir={self.temp_dir}") self.job_ret = self.hydra.run( config_name=config_name, task_function=self, overrides=overrides, with_log_configuration=self.configure_logging, ) return self finally: GlobalHydra().clear()
def __init__( self, config_path: Optional[str] = None, job_name: Optional[str] = None, strict: Optional[bool] = None, caller_stack_depth: int = 1, ) -> None: self._gh_backup = get_gh_backup() if config_path is not None and os.path.isabs(config_path): raise HydraException( "config_path in initialize() must be relative") calling_file, calling_module = detect_calling_file_or_module_from_stack_frame( caller_stack_depth + 1) if job_name is None: job_name = detect_task_name(calling_file=calling_file, calling_module=calling_module) Hydra.create_main_hydra_file_or_module( calling_file=calling_file, calling_module=calling_module, config_path=config_path, job_name=job_name, strict=strict, )
def __enter__(self) -> "SweepTaskFunction": overrides = copy.deepcopy(self.overrides) assert overrides is not None if self.temp_dir: Path(self.temp_dir).mkdir(parents=True, exist_ok=True) else: self.temp_dir = tempfile.mkdtemp() overrides.append(f"hydra.sweep.dir={self.temp_dir}") try: config_dir, config_name = split_config_path( self.config_path, self.config_name) job_name = detect_task_name(self.calling_file, self.calling_module) hydra_ = Hydra.create_main_hydra_file_or_module( calling_file=self.calling_file, calling_module=self.calling_module, config_path=config_dir, job_name=job_name, strict=self.strict, ) self.returns = hydra_.multirun( config_name=config_name, task_function=self, overrides=overrides, with_log_configuration=self.configure_logging, ) finally: GlobalHydra().clear() return self
def __init__( self, config_path: Optional[str] = _UNSPECIFIED_, job_name: Optional[str] = None, caller_stack_depth: int = 1, ) -> None: self._gh_backup = get_gh_backup() # DEPRECATED: remove in 1.2 # in 1.2, the default config_path should be changed to None if config_path is _UNSPECIFIED_: url = "https://hydra.cc/docs/next/upgrades/1.0_to_1.1/changes_to_hydra_main_config_path" deprecation_warning( message=dedent(f"""\ config_path is not specified in hydra.initialize(). See {url} for more information."""), stacklevel=2, ) config_path = "." if config_path is not None and os.path.isabs(config_path): raise HydraException( "config_path in initialize() must be relative") calling_file, calling_module = detect_calling_file_or_module_from_stack_frame( caller_stack_depth + 1) if job_name is None: job_name = detect_task_name(calling_file=calling_file, calling_module=calling_module) Hydra.create_main_hydra_file_or_module( calling_file=calling_file, calling_module=calling_module, config_path=config_path, job_name=job_name, )