-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix circular import errors in settings with edgy
Recent changes made it more likely to hit circular import errors when providing settings. This PR fixes the problem by leveraging the new more lenient monkay 0.2 version and initialize the settings in cases of import errors later.
- Loading branch information
Showing
9 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
from typing import Any | ||
from __future__ import annotations | ||
|
||
from .global_settings import EdgySettings | ||
from functools import lru_cache | ||
from typing import TYPE_CHECKING, Any, cast | ||
|
||
if TYPE_CHECKING: | ||
from monkay import Monkay | ||
|
||
from edgy import EdgySettings, Instance | ||
|
||
|
||
@lru_cache | ||
def get_edgy_monkay() -> Monkay[Instance, EdgySettings]: | ||
from edgy import monkay | ||
|
||
monkay.evaluate_settings_once(on_conflict="error", ignore_import_errors=False) | ||
|
||
return monkay | ||
|
||
|
||
class SettingsForward: | ||
def __getattribute__(self, name: str) -> Any: | ||
from edgy import monkay | ||
|
||
monkay = get_edgy_monkay() | ||
return getattr(monkay.settings, name) | ||
|
||
|
||
settings: EdgySettings = SettingsForward() # type: ignore | ||
settings: EdgySettings = cast("EdgySettings", SettingsForward()) | ||
|
||
|
||
def evaluate_settings_once_ready() -> None: | ||
""" | ||
Call when settings must be ready. | ||
This doesn't prevent the settings being updated later or set before. | ||
""" | ||
get_edgy_monkay() | ||
|
||
|
||
__all__ = ["settings"] | ||
__all__ = ["settings", "evaluate_settings_once_ready"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters