Extract load_object from multiple paths to iResolver
This commit is contained in:
@@ -63,17 +63,12 @@ class HyperOptResolver(IResolver):
|
||||
# Add extra hyperopt directory on top of search paths
|
||||
abs_paths.insert(0, Path(extra_dir))
|
||||
|
||||
for _path in abs_paths:
|
||||
try:
|
||||
(hyperopt, module_path) = self._search_object(directory=_path,
|
||||
object_type=IHyperOpt,
|
||||
object_name=hyperopt_name)
|
||||
if hyperopt:
|
||||
logger.info(f"Using resolved hyperopt {hyperopt_name} from '{module_path}'...")
|
||||
return hyperopt
|
||||
except FileNotFoundError:
|
||||
logger.warning('Path "%s" does not exist.', _path.relative_to(Path.cwd()))
|
||||
|
||||
(hyperopt, module_path) = self._load_object(paths=abs_paths,
|
||||
object_type=IHyperOpt,
|
||||
object_name=hyperopt_name,
|
||||
kwargs={})
|
||||
if hyperopt:
|
||||
return hyperopt
|
||||
raise OperationalException(
|
||||
f"Impossible to load Hyperopt '{hyperopt_name}'. This class does not exist "
|
||||
"or contains Python code errors."
|
||||
@@ -125,17 +120,12 @@ class HyperOptLossResolver(IResolver):
|
||||
# Add extra hyperopt directory on top of search paths
|
||||
abs_paths.insert(0, Path(extra_dir))
|
||||
|
||||
for _path in abs_paths:
|
||||
try:
|
||||
(hyperoptloss, module_path) = self._search_object(directory=_path,
|
||||
object_type=IHyperOptLoss,
|
||||
object_name=hyper_loss_name)
|
||||
if hyperoptloss:
|
||||
logger.info(
|
||||
f"Using resolved hyperopt {hyper_loss_name} from '{module_path}'...")
|
||||
return hyperoptloss
|
||||
except FileNotFoundError:
|
||||
logger.warning('Path "%s" does not exist.', _path.relative_to(Path.cwd()))
|
||||
(hyperoptloss, module_path) = self._load_object(paths=abs_paths,
|
||||
object_type=IHyperOptLoss,
|
||||
object_name=hyper_loss_name,
|
||||
kwargs={})
|
||||
if hyperoptloss:
|
||||
return hyperoptloss
|
||||
|
||||
raise OperationalException(
|
||||
f"Impossible to load HyperoptLoss '{hyper_loss_name}'. This class does not exist "
|
||||
|
||||
Reference in New Issue
Block a user