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