Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/maison/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from maison import parsers
from maison import protocols
from maison import service
from maison import types
from maison import typedefs


def _bootstrap_service(package_name: str) -> service.ConfigService:
Expand Down Expand Up @@ -83,7 +83,7 @@ def __str__(self) -> str:
return f"<class '{self.__class__.__name__}'>"

@property
def values(self) -> types.ConfigValues:
def values(self) -> typedefs.ConfigValues:
"""Return the user's configuration values.

Returns:
Expand All @@ -92,7 +92,7 @@ def values(self) -> types.ConfigValues:
return self._values

@values.setter
def values(self, values: types.ConfigValues) -> None:
def values(self, values: typedefs.ConfigValues) -> None:
"""Set the user's configuration values."""
self._values = values

Expand Down Expand Up @@ -145,7 +145,7 @@ def validate(
self,
schema: typing.Optional[type[protocols.IsSchema]] = None,
use_schema_values: bool = True,
) -> types.ConfigValues:
) -> typedefs.ConfigValues:
"""Validate the configuration.

Warning:
Expand Down
6 changes: 3 additions & 3 deletions src/maison/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing

from maison import errors
from maison import types
from maison import typedefs


ParserDictKey = tuple[str, typing.Union[str, None]]
Expand All @@ -13,7 +13,7 @@
class Parser(typing.Protocol):
"""Defines the interface for a `Parser` class that's used to parse a config."""

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""Parse a config file.

Args:
Expand Down Expand Up @@ -42,7 +42,7 @@ def register_parser(
key = (suffix, stem)
self._parsers[key] = parser

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""See `Parser.parse_config`."""
key: ParserDictKey

Expand Down
6 changes: 3 additions & 3 deletions src/maison/config_validator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Holds the tools for validating a user's config."""

from maison import protocols
from maison import types
from maison import typedefs


class Validator:
Expand All @@ -11,8 +11,8 @@ class Validator:
"""

def validate(
self, values: types.ConfigValues, schema: type[protocols.IsSchema]
) -> types.ConfigValues:
self, values: typedefs.ConfigValues, schema: type[protocols.IsSchema]
) -> typedefs.ConfigValues:
"""See `Validator.validate`."""
validated_schema = schema(**values)
return validated_schema.model_dump()
4 changes: 2 additions & 2 deletions src/maison/parsers/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import configparser
import pathlib

from maison import types
from maison import typedefs


class IniParser:
Expand All @@ -12,7 +12,7 @@ class IniParser:
Implements the `Parser` protocol
"""

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""See the Parser.parse_config method."""
config = configparser.ConfigParser()
_ = config.read(file_path)
Expand Down
4 changes: 2 additions & 2 deletions src/maison/parsers/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import toml

from maison import types
from maison import typedefs


class PyprojectParser:
Expand All @@ -22,7 +22,7 @@ def __init__(self, package_name: str) -> None:
"""
self._package_name = package_name

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""See the Parser.parse_config method."""
try:
pyproject_dict = dict(toml.load(file_path))
Expand Down
4 changes: 2 additions & 2 deletions src/maison/parsers/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import toml

from maison import types
from maison import typedefs


class TomlParser:
Expand All @@ -13,7 +13,7 @@ class TomlParser:
Implements the `Parser` protocol
"""

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""See the Parser.parse_config method."""
try:
return dict(toml.load(file_path))
Expand Down
12 changes: 6 additions & 6 deletions src/maison/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import pathlib
import typing

from maison import types
from maison import typedefs


class Parser(typing.Protocol):
"""Defines the interface for a parser used to parse a config file."""

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""Parses a config file.

Args:
Expand All @@ -24,7 +24,7 @@ def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
class IsSchema(typing.Protocol):
"""Protocol for config schemas."""

def model_dump(self) -> types.ConfigValues:
def model_dump(self) -> typedefs.ConfigValues:
"""Convert the validated config to a dict."""
...

Expand All @@ -49,7 +49,7 @@ def get_file_path(
class ConfigParser(typing.Protocol):
"""Defines the interface for a class that parses a config."""

def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""Parse a config.

Args:
Expand All @@ -65,8 +65,8 @@ class Validator(typing.Protocol):
"""Defines the interface for a class that validates some config values."""

def validate(
self, values: types.ConfigValues, schema: type[IsSchema]
) -> types.ConfigValues:
self, values: typedefs.ConfigValues, schema: type[IsSchema]
) -> typedefs.ConfigValues:
"""Validate a config.

Args:
Expand Down
10 changes: 5 additions & 5 deletions src/maison/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Iterable

from maison import protocols
from maison import types
from maison import typedefs
from maison import utils


Expand Down Expand Up @@ -53,7 +53,7 @@ def get_config_values(
self,
config_file_paths: Iterable[pathlib.Path],
merge_configs: bool,
) -> types.ConfigValues:
) -> typedefs.ConfigValues:
"""Get the values from config files.

Args:
Expand All @@ -64,7 +64,7 @@ def get_config_values(
Returns:
The values from the config file(s)
"""
config_values: types.ConfigValues = {}
config_values: typedefs.ConfigValues = {}

for path in config_file_paths:
parsed_config = self.config_parser.parse_config(path)
Expand All @@ -76,8 +76,8 @@ def get_config_values(
return config_values

def validate_config(
self, values: types.ConfigValues, schema: type[protocols.IsSchema]
) -> types.ConfigValues:
self, values: typedefs.ConfigValues, schema: type[protocols.IsSchema]
) -> typedefs.ConfigValues:
"""Validate config values against a schema.

Args:
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/maison/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Module to hold various utils."""

from maison import types
from maison import typedefs


def deep_merge(
destination: types.ConfigValues, source: types.ConfigValues
) -> types.ConfigValues:
destination: typedefs.ConfigValues, source: typedefs.ConfigValues
) -> typedefs.ConfigValues:
"""Recursively updates the destination dictionary.

Usage example:
Expand Down
6 changes: 3 additions & 3 deletions tests/integration_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from maison import config
from maison import errors
from maison import types
from maison import typedefs


class TestUserConfig:
Expand Down Expand Up @@ -99,7 +99,7 @@ class Schema:
def __init__(self, *args: object, **kwargs: object) -> None:
pass

def model_dump(self) -> types.ConfigValues:
def model_dump(self) -> typedefs.ConfigValues:
return {"key": "validated"}

cfg = config.UserConfig(
Expand All @@ -123,7 +123,7 @@ class Schema:
def __init__(self, *args: object, **kwargs: object) -> None:
pass

def model_dump(self) -> types.ConfigValues:
def model_dump(self) -> typedefs.ConfigValues:
return {"key": "validated"}

cfg = config.UserConfig(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

from maison import config_parser
from maison import errors
from maison import types
from maison import typedefs


class FakePyprojectParser:
def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
return {"config": "pyproject"}


class FakeTomlParser:
def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
return {"config": "toml"}


Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_config_validator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from maison import config_validator
from maison import types
from maison import typedefs


class Schema:
def __init__(self, *args: object, **kwargs: object) -> None:
pass

def model_dump(self) -> types.ConfigValues:
def model_dump(self) -> typedefs.ConfigValues:
return {"key": "validated"}


Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from maison import protocols
from maison import service as config_service
from maison import types
from maison import typedefs


class FakeFileSystem:
Expand All @@ -16,21 +16,21 @@ def get_file_path(


class FakeConfigParser:
def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
return {
"values": {file_path.stem: file_path.suffix},
}


class Schema:
def model_dump(self) -> types.ConfigValues:
def model_dump(self) -> typedefs.ConfigValues:
return {"key": "validated"}


class FakeValidator:
def validate(
self, values: types.ConfigValues, schema: type[protocols.IsSchema]
) -> types.ConfigValues:
self, values: typedefs.ConfigValues, schema: type[protocols.IsSchema]
) -> typedefs.ConfigValues:
return schema().model_dump()


Expand Down
12 changes: 6 additions & 6 deletions tests/unit_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from maison import types
from maison import typedefs
from maison.utils import deep_merge


Expand All @@ -28,17 +28,17 @@ class TestDeepMerge:
)
def test_success(
self,
a: types.ConfigValues,
b: types.ConfigValues,
expected: types.ConfigValues,
a: typedefs.ConfigValues,
b: typedefs.ConfigValues,
expected: typedefs.ConfigValues,
) -> None:
assert deep_merge(a, b) == expected
assert a == expected

def test_incompatible_dicts(self) -> None:
"""Trying to merge incompatible dicts returns an error"""
dict_a: types.ConfigValues = {"1": "2", "2": "5"}
dict_b: types.ConfigValues = {"1": {"3": "4"}}
dict_a: typedefs.ConfigValues = {"1": "2", "2": "5"}
dict_b: typedefs.ConfigValues = {"1": {"3": "4"}}

with pytest.raises(RuntimeError):
_ = deep_merge(dict_a, dict_b)