Generalize "path" variables for resolvers
This commit is contained in:
parent
2ef315e8c2
commit
4bfe58706b
@ -26,6 +26,7 @@ class FreqaiModelResolver(IResolver):
|
||||
initial_search_path = (
|
||||
Path(__file__).parent.parent.joinpath("freqai/prediction_models").resolve()
|
||||
)
|
||||
extra_path = "freqaimodel_path"
|
||||
|
||||
@staticmethod
|
||||
def load_freqaimodel(config: Config) -> IFreqaiModel:
|
||||
@ -50,7 +51,6 @@ class FreqaiModelResolver(IResolver):
|
||||
freqaimodel_name,
|
||||
config,
|
||||
kwargs={"config": config},
|
||||
extra_dir=config.get("freqaimodel_path"),
|
||||
)
|
||||
|
||||
return freqaimodel
|
||||
|
@ -42,6 +42,8 @@ class IResolver:
|
||||
object_type_str: str
|
||||
user_subdir: Optional[str] = None
|
||||
initial_search_path: Optional[Path]
|
||||
# Optional config setting containing a path (strategy_path, freqaimodel_path)
|
||||
extra_path: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
def build_search_paths(cls, config: Config, user_subdir: Optional[str] = None,
|
||||
@ -58,6 +60,9 @@ class IResolver:
|
||||
for dir in extra_dirs:
|
||||
abs_paths.insert(0, Path(dir).resolve())
|
||||
|
||||
if cls.extra_path and (extra := config.get(cls.extra_path)):
|
||||
abs_paths.insert(0, Path(extra).resolve())
|
||||
|
||||
return abs_paths
|
||||
|
||||
@classmethod
|
||||
|
@ -30,6 +30,7 @@ class StrategyResolver(IResolver):
|
||||
object_type_str = "Strategy"
|
||||
user_subdir = USERPATH_STRATEGIES
|
||||
initial_search_path = None
|
||||
extra_path = "strategy_path"
|
||||
|
||||
@staticmethod
|
||||
def load_strategy(config: Config = None) -> IStrategy:
|
||||
@ -268,14 +269,6 @@ class StrategyResolver(IResolver):
|
||||
"or contains Python code errors."
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def build_search_paths(cls, config: Config, user_subdir: Optional[str] = None,
|
||||
extra_dirs: List[str] = []) -> List[Path]:
|
||||
|
||||
if 'strategy_path' in config and config['strategy_path'] not in extra_dirs:
|
||||
extra_dirs = [config['strategy_path']] + extra_dirs
|
||||
return super().build_search_paths(config, user_subdir, extra_dirs)
|
||||
|
||||
|
||||
def warn_deprecated_setting(strategy: IStrategy, old: str, new: str, error=False):
|
||||
if hasattr(strategy, old):
|
||||
|
Loading…
Reference in New Issue
Block a user