Skip to content

Commit

Permalink
Merge pull request #130 from entelecheia/1.5.4.refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia authored Jul 21, 2023
2 parents d8d3adb + a438adf commit 383c051
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hyfi/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from hyfi.about import AboutConfig
from hyfi.about import AboutConfig, __package_name__
from hyfi.utils.logging import LOGGING

logger = LOGGING.getLogger(__name__)
Expand All @@ -11,6 +11,7 @@
__hydra_default_config_group_value__ = "__init__"
__config_path__ = "conf"
__config_name__ = "config"
__config_module__ = f"{__package_name__}.{__config_path__}"

__about__ = AboutConfig()
_batcher_instance_ = None
Expand Down
5 changes: 5 additions & 0 deletions src/hyfi/core/hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from hydra.core.singleton import Singleton
from hydra.errors import HydraException

from hyfi.core import __config_module__


def get_gh_backup() -> Any:
if GlobalHydra in Singleton._instances:
Expand Down Expand Up @@ -87,6 +89,9 @@ def create_config_search_path(
if config_module is not None:
search_path.append("main", f"pkg://{config_module}")

if config_module != __config_module__:
search_path.append("hyfi", f"pkg://{__config_module__}")

if search_path_dir is not None and os.path.isdir(search_path_dir):
search_path.append("hyfi", f"file://{search_path_dir}")

Expand Down
5 changes: 5 additions & 0 deletions src/hyfi/utils/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,8 @@ def getsource(obj: str) -> str:
def viewsource(obj: str) -> None:
"""Print the source code of the object."""
print(PKGs.getsource(obj))

@staticmethod
def get_caller_module_name() -> str:
"""Get the name of the module that called this function."""
return inspect.getmodule(inspect.stack()[2][0]).__name__ # type: ignore
17 changes: 17 additions & 0 deletions tests/hyfi/composer/test_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from hyfi.composer import Composer
from hyfi.main import HyFI


def my_function():
caller_module_name = HyFI.get_caller_module_name()
print(f"The name of the caller module is {caller_module_name}")


def test_composer():
my_function()
cfg = Composer._compose("about", config_module="hyfi.conf")
print(cfg)


if __name__ == "__main__":
test_composer()

0 comments on commit 383c051

Please sign in to comment.