-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from simonsobs/JBorrow/issue27
Refactor CLI components
- Loading branch information
Showing
18 changed files
with
671 additions
and
1,101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
""" | ||
Client settings. | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
from pydantic import BaseModel | ||
from pydantic_settings import BaseSettings | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
client_settings: "ClientSettings" | ||
|
||
|
||
class ClientInfo(BaseModel): | ||
""" | ||
Information for an individual client. | ||
""" | ||
|
||
user: str | ||
"Your username on this librarian" | ||
port: int | ||
"The port of this librarian server" | ||
host: str | ||
"The hostname of this librarian server" | ||
|
||
|
||
class ClientSettings(BaseSettings): | ||
connections: dict[str, ClientInfo] = {} | ||
|
||
@classmethod | ||
def from_file(cls, config_path: Path | str) -> "ClientSettings": | ||
""" | ||
Loads the settings from the given path. | ||
""" | ||
|
||
with open(config_path, "r") as handle: | ||
return cls.model_validate_json(handle.read()) | ||
|
||
|
||
# Automatically create a settings object on use. | ||
|
||
_settings = None | ||
|
||
|
||
def load_settings() -> ClientSettings: | ||
""" | ||
Load the settings from the config file. | ||
""" | ||
|
||
global _settings | ||
|
||
try_paths = [ | ||
os.environ.get("HL_CLIENT_CONFIG", None), | ||
Path.home() / ".hl_client.cfg", | ||
Path.home() / ".hl_client.json", | ||
] | ||
|
||
for path in try_paths: | ||
if path is not None: | ||
path = Path(path) | ||
else: | ||
continue | ||
|
||
if path.exists(): | ||
_settings = ClientSettings.from_file(path) | ||
return _settings | ||
|
||
_settings = ClientSettings() | ||
|
||
return _settings | ||
|
||
|
||
def __getattr__(name): | ||
""" | ||
Try to load the settings if they haven't been loaded yet. | ||
""" | ||
|
||
if name == "client_settings": | ||
global _settings | ||
|
||
if _settings is not None: | ||
return _settings | ||
|
||
return load_settings() | ||
|
||
raise AttributeError(f"module '{__name__}' has no attribute '{name}'") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file removed
BIN
-132 Bytes
hera_librarian/tests/test_data/zen.2458043.12552.xx.HH.uvA/header
Binary file not shown.
3 changes: 0 additions & 3 deletions
3
hera_librarian/tests/test_data/zen.2458043.12552.xx.HH.uvA/history
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.