Skip to content

Commit

Permalink
fix(core): change plugins type to Dict and rename method, enhance plu…
Browse files Browse the repository at this point in the history
…gins retrieval from package name
  • Loading branch information
entelecheia committed Aug 18, 2023
1 parent 94d3898 commit 5702d87
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/hyfi/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import os
from pathlib import Path
from typing import List, Optional, Set, Tuple, Union
from typing import List, Optional, Set, Tuple, Union, Dict

from pydantic import BaseModel

Expand Down Expand Up @@ -56,7 +56,7 @@ class GlobalHyFIConfig(BaseModel):
__package_name__: str = __hyfi_package_name__
__package_path__: str = __hyfi_package_path__
__version__: str = __hyfi_version__()
__plugins__: Optional[List[str]] = None
__plugins__: Optional[Dict[str, List[str]]] = None

__config_name__: str = __hyfi_config_name__
__config_dirname__: str = __hyfi_config_dirname__
Expand Down Expand Up @@ -105,7 +105,7 @@ def initialize(
if package_path not in self._packages_:
self._packages_.append((package_path, version))
if plugins:
self.__plugins__ = self.get_plugins(plugins)
self.__plugins__ = self.init_plugins(plugins)
if user_config_path:
self.__user_config_path__ = user_config_path
if config_dirname:
Expand Down Expand Up @@ -152,9 +152,11 @@ def secrets_dir(self) -> str:
@property
def plugins(self) -> Optional[List[str]]:
"""Returns the list of plugins to load."""
return self.__plugins__
if self.__plugins__ and self.__package_name__ in self.__plugins__:
return self.__plugins__[self.__package_name__]
return None

def get_plugins(self, plugins: List[str]) -> List[str]:
def init_plugins(self, plugins: List[str]) -> Dict[str, List[str]]:
"""Returns the list of plugins to load.
A plugin is a python module which contains a configuration module.
Expand All @@ -173,7 +175,7 @@ def get_plugins(self, plugins: List[str]) -> List[str]:
plugin = plugin.split(".")[0]
config_module = f"{plugin}.{self.__config_dirname__}"
_plugins.append(config_module)
return _plugins
return {self.__package_name__: _plugins}

@property
def package_name(self) -> str:
Expand Down

0 comments on commit 5702d87

Please sign in to comment.