Compare commits

...

2 Commits

Author SHA1 Message Date
4399f61259 adding more changes
Some checks failed
Nix Tests / nix-test (nix-runner) (push) Failing after 4m4s
Python Tests / python-test (push) Failing after 59s
2025-10-07 18:46:16 -05:00
d11360b2ed dep: adding tomli dep 2025-10-07 13:50:15 -05:00
9 changed files with 169 additions and 4 deletions

1
config.toml Normal file
View File

@@ -0,0 +1 @@
[general_config]

View File

@@ -7,10 +7,12 @@ requires-python = ">=3.12"
dependencies = [
#"urllib3>=2.2.3",
"dacite>=1.9.2",
"tomli>=2.2.1",
]
[project.scripts]
hello = "hello_world:main"
taco = "trygo_py_cliclient.cli:main"
[build-system]
requires = ["hatchling"]

View File

@@ -0,0 +1,30 @@
import argparse
import pathlib
import logging
import trygo_py_cliclient.config
import trygo_py_cliclient.cli.common
_logger = logging.getLogger(__name__)
def parse_args():
parser = argparse.ArgumentParser(
"trygo-client", formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--config-file", type=str, help="config file location", default="config.toml"
)
args = parser.parse_args()
return args
def main():
args = parse_args()
config = trygo_py_cliclient.config.read_config(pathlib.Path(args.config_file))
trygo_py_cliclient.cli.common.set_up_logging(
config,
)
_logger.info(f"Loaded config {config=}")

View File

@@ -0,0 +1,29 @@
import trygo_py_cliclient.config
import typing
import logging
import pathlib
def set_up_logging(
config: trygo_py_cliclient.config.Config,
create_logfile_parents: bool = True,
):
# for convenience
conf = config.general_config
handlers: typing.List[logging.Handler] = []
if conf.log_stream:
handlers.append(logging.StreamHandler())
if conf.log_file is not None:
if create_logfile_parents:
# create any parent directories for the log file if needed.
pathlib.Path(conf.log_file).parent.mkdir(parents=True, exist_ok=True)
handlers.append(logging.FileHandler(conf.log_file))
logging.basicConfig(
level=logging.DEBUG,
format=conf.log_pattern,
handlers=handlers,
)
logging.captureWarnings(True)

View File

View File

@@ -1,5 +1,10 @@
from trygo_py_cliclient.config.config import (
GeneralConfig,
Config,
)
__all__ = ["GeneralConfig"]
from trygo_py_cliclient.config.config_reader import (
read_config,
)
__all__ = ["GeneralConfig", "Config", "read_config"]

View File

@@ -1,6 +1,14 @@
from dataclasses import dataclass
from typing import Optional
@dataclass(frozen=True)
class GeneralConfig:
log_pattern: str = "%(asctime)s | %(process)d | %(levelname)-7s | %(name)s:%(lineno)d | %(message)s"
log_file: Optional[str] = None
log_stream: bool = True
@dataclass(frozen=True)
class Config:
general_config: GeneralConfig = GeneralConfig()

View File

@@ -1,7 +1,9 @@
import logging
import dacite
import pathlib
import tomli
from trygo_py_cliclient.config import GeneralConfig
from trygo_py_cliclient.config import GeneralConfig, Config
_logger = logging.getLogger(__name__)
@@ -10,7 +12,7 @@ _common_dacite_config = dacite.Config(
)
def read_general_config_dict(general_config_dict: dict) -> GeneralConfig:
def read_general_config_from_dict(general_config_dict: dict) -> GeneralConfig:
"""
Converts a dictionary to a GeneralConfig object
@@ -23,3 +25,58 @@ def read_general_config_dict(general_config_dict: dict) -> GeneralConfig:
config=_common_dacite_config,
)
return general_config
def read_config_dict(file_path: pathlib.Path) -> dict:
"""
Read a dict from file
"""
_logger.debug(f"Reading config from {file_path=}")
with open(file_path, "rb") as toml_file:
config_dict = tomli.load(toml_file)
return config_dict
def serialize_config(config_dict: dict) -> Config:
"""
Converts a dictionary to a Config object
Makes assumptions about structure of the config_dict, so validation should happen here too if needed.
:param config_dict: dictionary containing config values
:return: Config object
"""
# generation_config = GenerationConfig(**config_dict["generation_config"])
# general_config_dict = config_dict["general_config"]
# general_config = GeneralConfig(
# root_directory=general_config_dict["root_directory"],
# out_dir_name=general_config_dict["out_dir_name"],
# dots_json_name=general_config_dict["dots_json_name"],
# mega_merged_name=general_config_dict["mega_merged_name"],
# mega_merged_inferenced_name=general_config_dict["mega_merged_inferenced_name"],
# skip_to_stage=general_config_dict["skip_to_stage"],
# measurement_type=MeasurementTypeEnum(general_config_dict["measurement_type"]),
# indexes_json_name=general_config_dict["indexes_json_name"],
# log_pattern=general_config_dict["log_pattern"],
# )
# deepdog_config = DeepdogConfig(**config_dict["deepdog_config"])
# config = Config(
# generation_config=generation_config,
# general_config=general_config,
# deepdog_config=deepdog_config,
# )
config = dacite.from_dict(
data_class=Config,
data=config_dict,
config=_common_dacite_config,
)
_logger.warning(config)
return config
def read_config(file_path: pathlib.Path) -> Config:
config_dict = read_config_dict(file_path)
return serialize_config(config_dict)

35
uv.lock generated
View File

@@ -79,6 +79,7 @@ version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "dacite" },
{ name = "tomli" },
]
[package.dev-dependencies]
@@ -92,7 +93,10 @@ dev = [
]
[package.metadata]
requires-dist = [{ name = "dacite", specifier = ">=1.9.2" }]
requires-dist = [
{ name = "dacite", specifier = ">=1.9.2" },
{ name = "tomli", specifier = ">=2.2.1" },
]
[package.metadata.requires-dev]
dev = [
@@ -257,6 +261,35 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/14/78/1e7aee4498f79624f85a6480eb8bc04bacb729c30336bc61b384c6ce4998/syrupy-4.9.0-py3-none-any.whl", hash = "sha256:3028d60188df9b39079678501be7d72fe64d32e2bb53d78df87f5a84bde94d76", size = 52045, upload-time = "2025-03-08T19:08:29.96Z" },
]
[[package]]
name = "tomli"
version = "2.2.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/18/87/302344fed471e44a87289cf4967697d07e532f2421fdaf868a303cbae4ff/tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff", size = 17175, upload-time = "2024-11-27T22:38:36.873Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/52/e1/f8af4c2fcde17500422858155aeb0d7e93477a0d59a98e56cbfe75070fd0/tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea", size = 132762, upload-time = "2024-11-27T22:38:07.731Z" },
{ url = "https://files.pythonhosted.org/packages/03/b8/152c68bb84fc00396b83e7bbddd5ec0bd3dd409db4195e2a9b3e398ad2e3/tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8", size = 123453, upload-time = "2024-11-27T22:38:09.384Z" },
{ url = "https://files.pythonhosted.org/packages/c8/d6/fc9267af9166f79ac528ff7e8c55c8181ded34eb4b0e93daa767b8841573/tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192", size = 233486, upload-time = "2024-11-27T22:38:10.329Z" },
{ url = "https://files.pythonhosted.org/packages/5c/51/51c3f2884d7bab89af25f678447ea7d297b53b5a3b5730a7cb2ef6069f07/tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222", size = 242349, upload-time = "2024-11-27T22:38:11.443Z" },
{ url = "https://files.pythonhosted.org/packages/ab/df/bfa89627d13a5cc22402e441e8a931ef2108403db390ff3345c05253935e/tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77", size = 252159, upload-time = "2024-11-27T22:38:13.099Z" },
{ url = "https://files.pythonhosted.org/packages/9e/6e/fa2b916dced65763a5168c6ccb91066f7639bdc88b48adda990db10c8c0b/tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6", size = 237243, upload-time = "2024-11-27T22:38:14.766Z" },
{ url = "https://files.pythonhosted.org/packages/b4/04/885d3b1f650e1153cbb93a6a9782c58a972b94ea4483ae4ac5cedd5e4a09/tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd", size = 259645, upload-time = "2024-11-27T22:38:15.843Z" },
{ url = "https://files.pythonhosted.org/packages/9c/de/6b432d66e986e501586da298e28ebeefd3edc2c780f3ad73d22566034239/tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e", size = 244584, upload-time = "2024-11-27T22:38:17.645Z" },
{ url = "https://files.pythonhosted.org/packages/1c/9a/47c0449b98e6e7d1be6cbac02f93dd79003234ddc4aaab6ba07a9a7482e2/tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98", size = 98875, upload-time = "2024-11-27T22:38:19.159Z" },
{ url = "https://files.pythonhosted.org/packages/ef/60/9b9638f081c6f1261e2688bd487625cd1e660d0a85bd469e91d8db969734/tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4", size = 109418, upload-time = "2024-11-27T22:38:20.064Z" },
{ url = "https://files.pythonhosted.org/packages/04/90/2ee5f2e0362cb8a0b6499dc44f4d7d48f8fff06d28ba46e6f1eaa61a1388/tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7", size = 132708, upload-time = "2024-11-27T22:38:21.659Z" },
{ url = "https://files.pythonhosted.org/packages/c0/ec/46b4108816de6b385141f082ba99e315501ccd0a2ea23db4a100dd3990ea/tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c", size = 123582, upload-time = "2024-11-27T22:38:22.693Z" },
{ url = "https://files.pythonhosted.org/packages/a0/bd/b470466d0137b37b68d24556c38a0cc819e8febe392d5b199dcd7f578365/tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13", size = 232543, upload-time = "2024-11-27T22:38:24.367Z" },
{ url = "https://files.pythonhosted.org/packages/d9/e5/82e80ff3b751373f7cead2815bcbe2d51c895b3c990686741a8e56ec42ab/tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281", size = 241691, upload-time = "2024-11-27T22:38:26.081Z" },
{ url = "https://files.pythonhosted.org/packages/05/7e/2a110bc2713557d6a1bfb06af23dd01e7dde52b6ee7dadc589868f9abfac/tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272", size = 251170, upload-time = "2024-11-27T22:38:27.921Z" },
{ url = "https://files.pythonhosted.org/packages/64/7b/22d713946efe00e0adbcdfd6d1aa119ae03fd0b60ebed51ebb3fa9f5a2e5/tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140", size = 236530, upload-time = "2024-11-27T22:38:29.591Z" },
{ url = "https://files.pythonhosted.org/packages/38/31/3a76f67da4b0cf37b742ca76beaf819dca0ebef26d78fc794a576e08accf/tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2", size = 258666, upload-time = "2024-11-27T22:38:30.639Z" },
{ url = "https://files.pythonhosted.org/packages/07/10/5af1293da642aded87e8a988753945d0cf7e00a9452d3911dd3bb354c9e2/tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744", size = 243954, upload-time = "2024-11-27T22:38:31.702Z" },
{ url = "https://files.pythonhosted.org/packages/5b/b9/1ed31d167be802da0fc95020d04cd27b7d7065cc6fbefdd2f9186f60d7bd/tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec", size = 98724, upload-time = "2024-11-27T22:38:32.837Z" },
{ url = "https://files.pythonhosted.org/packages/c7/32/b0963458706accd9afcfeb867c0f9175a741bf7b19cd424230714d722198/tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69", size = 109383, upload-time = "2024-11-27T22:38:34.455Z" },
{ url = "https://files.pythonhosted.org/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc", size = 14257, upload-time = "2024-11-27T22:38:35.385Z" },
]
[[package]]
name = "typing-extensions"
version = "4.12.2"