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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ reportAny = false
reportAssignmentType = false
reportCallInDefaultInitializer = false
reportExplicitAny = false
reportImplicitOverride = false
reportImplicitStringConcatenation = false
reportMissingParameterType = false
reportMissingTypeArgument = false
Expand Down
3 changes: 3 additions & 0 deletions src/usethis/_backend/uv/toml.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from pathlib import Path

from typing_extensions import override

from usethis._file.toml.io_ import TOMLFileManager


class UVTOMLManager(TOMLFileManager):
"""Class to manage the uv.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path("uv.toml")
14 changes: 14 additions & 0 deletions src/usethis/_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from typing_extensions import override

from usethis._backend.uv.toml import UVTOMLManager
from usethis._file.ini.io_ import INIFileManager
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
Expand Down Expand Up @@ -45,6 +47,7 @@ class DotCodespellRCManager(INIFileManager):
"""Class to manage the .codespellrc file."""

@property
@override
def relative_path(self) -> Path:
return Path(".codespellrc")

Expand All @@ -53,6 +56,7 @@ class DotCoverageRCManager(INIFileManager):
"""Class to manage the .coveragerc file."""

@property
@override
def relative_path(self) -> Path:
return Path(".coveragerc")

Expand All @@ -61,6 +65,7 @@ class DotCoverageRCTOMLManager(TOMLFileManager):
"""Class to manage the .coveragerc.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path(".coveragerc.toml")

Expand All @@ -69,6 +74,7 @@ class DotImportLinterManager(INIFileManager):
"""Class to manage the .importlinter file."""

@property
@override
def relative_path(self) -> Path:
return Path(".importlinter")

Expand All @@ -77,6 +83,7 @@ class DotPytestINIManager(INIFileManager):
"""Class to manage the .pytest.ini file."""

@property
@override
def relative_path(self) -> Path:
return Path(".pytest.ini")

Expand All @@ -85,6 +92,7 @@ class DotRuffTOMLManager(TOMLFileManager):
"""Class to manage the .ruff.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path(".ruff.toml")

Expand All @@ -93,6 +101,7 @@ class MkDocsYMLManager(YAMLFileManager):
"""Class to manage the mkdocs.yml file."""

@property
@override
def relative_path(self) -> Path:
return Path("mkdocs.yml")

Expand All @@ -101,6 +110,7 @@ class PytestINIManager(INIFileManager):
"""Class to manage the pytest.ini file."""

@property
@override
def relative_path(self) -> Path:
return Path("pytest.ini")

Expand All @@ -109,6 +119,7 @@ class RuffTOMLManager(TOMLFileManager):
"""Class to manage the ruff.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path("ruff.toml")

Expand All @@ -117,6 +128,7 @@ class ToxINIManager(INIFileManager):
"""Class to manage the tox.ini file."""

@property
@override
def relative_path(self) -> Path:
return Path("tox.ini")

Expand All @@ -125,6 +137,7 @@ class DotTyTOMLManager(TOMLFileManager):
"""Class to manage the .ty.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path(".ty.toml")

Expand All @@ -133,5 +146,6 @@ class TyTOMLManager(TOMLFileManager):
"""Class to manage the ty.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path("ty.toml")
16 changes: 15 additions & 1 deletion src/usethis/_file/ini/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from configupdater import ConfigUpdater as INIDocument
from configupdater import Option, Section
from pydantic import TypeAdapter
from typing_extensions import assert_never
from typing_extensions import assert_never, override

from usethis._file.ini.errors import (
INIDecodeError,
Expand Down Expand Up @@ -42,12 +42,14 @@
class INIFileManager(KeyValueFileManager, metaclass=ABCMeta):
_content_by_path: ClassVar[dict[Path, INIDocument | None]] = {}

@override
def __enter__(self) -> Self:
try:
return super().__enter__()
except UnexpectedFileOpenError as err:
raise UnexpectedINIOpenError(err) from None

@override
def read_file(self) -> INIDocument:
try:
return super().read_file()
Expand All @@ -59,38 +61,45 @@ def read_file(self) -> INIDocument:
msg = f"Failed to decode '{self.name}':\n{err}"
raise INIDecodeError(msg) from None

@override
def _dump_content(self) -> str:
if self._content is None:
msg = "Content is None, cannot dump."
raise ValueError(msg)

return str(self._content)

@override
def _parse_content(self, content: str) -> INIDocument:
updater = INIDocument()
updater.read_string(content)
return updater

@override
def get(self) -> INIDocument:
return super().get()

@override
def commit(self, document: INIDocument) -> None:
return super().commit(document)

@property
@override
def _content(self) -> INIDocument | None:
return super()._content

@_content.setter
def _content(self, value: INIDocument | None) -> None:
self._content_by_path[self.path] = value

@override
def _validate_lock(self) -> None:
try:
super()._validate_lock()
except UnexpectedFileIOError as err:
raise UnexpectedINIIOError(err) from None

@override
def __contains__(self, keys: Sequence[Key]) -> bool:
"""Check if the INI file contains a value at the given key.

Expand All @@ -114,6 +123,7 @@ def __contains__(self, keys: Sequence[Key]) -> bool:
return True
return False

@override
def __getitem__(self, item: Sequence[Key]) -> object:
keys = item

Expand Down Expand Up @@ -146,6 +156,7 @@ def __getitem__(self, item: Sequence[Key]) -> object:
)
raise KeyError(msg)

@override
def set_value(
self,
*,
Expand Down Expand Up @@ -338,6 +349,7 @@ def _validated_append(
else:
root[section_key][option_key].append(value)

@override
def __delitem__(self, keys: Sequence[Key]) -> None:
"""Delete a value in the INI file.

Expand Down Expand Up @@ -417,6 +429,7 @@ def _delete_strkeys(self, strkeys: Sequence[str]) -> None:

self.commit(root)

@override
def extend_list(self, *, keys: Sequence[Key], values: Sequence[object]) -> None:
"""Extend a list in the INI file.

Expand Down Expand Up @@ -495,6 +508,7 @@ def _remove_from_list_in_option(
elif len(new_values) > 1:
root[section_key][option_key].set_values(new_values)

@override
def remove_from_list(
self, *, keys: Sequence[Key], values: Sequence[object]
) -> None:
Expand Down
4 changes: 4 additions & 0 deletions src/usethis/_file/pyproject_toml/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing_extensions import override

from usethis._file.toml.errors import (
TOMLDecodeError,
TOMLError,
Expand Down Expand Up @@ -28,6 +30,7 @@ class PyprojectTOMLDecodeError(TOMLDecodeError, PyprojectTOMLError):
"""Raised when a pyproject.toml file cannot be decoded."""

@property
@override
def name(self) -> str:
"""The name of the file that could not be decoded."""
return "pyproject.toml"
Expand All @@ -45,6 +48,7 @@ class PyprojectTOMLProjectSectionError(FileConfigError, PyprojectTOMLError):
"""Raised when the 'project' section is missing or invalid in 'pyproject.toml'."""

@property
@override
def name(self) -> str:
"""The name of the file that has a configuration error."""
return "pyproject.toml"
Expand Down
8 changes: 8 additions & 0 deletions src/usethis/_file/pyproject_toml/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from typing_extensions import override

from usethis._file.pyproject_toml.errors import (
PyprojectTOMLDecodeError,
PyprojectTOMLNotFoundError,
Expand Down Expand Up @@ -35,15 +37,18 @@ class PyprojectTOMLManager(TOMLFileManager):
"""Manages the pyproject.toml file."""

@property
@override
def relative_path(self) -> Path:
return Path("pyproject.toml")

@override
def __enter__(self) -> Self:
try:
return super().__enter__()
except UnexpectedTOMLOpenError as err:
raise UnexpectedPyprojectTOMLOpenError(err) from None

@override
def read_file(self) -> TOMLDocument:
try:
return super().read_file()
Expand All @@ -54,12 +59,14 @@ def read_file(self) -> TOMLDocument:
except TOMLDecodeError as err:
raise PyprojectTOMLDecodeError(err) from None

@override
def _validate_lock(self) -> None:
try:
super()._validate_lock()
except UnexpectedTOMLIOError as err:
raise UnexpectedPyprojectTOMLIOError(err) from None

@override
def set_value(
self, *, keys: Sequence[Key], value: Any, exists_ok: bool = False
) -> None:
Expand All @@ -69,6 +76,7 @@ def set_value(
except TOMLValueAlreadySetError as err:
raise PyprojectTOMLValueAlreadySetError(err) from None

@override
def __delitem__(self, keys: Sequence[Key]) -> None:
"""Remove a value from the pyproject.toml configuration file."""
try:
Expand Down
3 changes: 3 additions & 0 deletions src/usethis/_file/setup_cfg/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing_extensions import override

from usethis._file.ini.errors import (
INIDecodeError,
INIError,
Expand All @@ -23,6 +25,7 @@ class SetupCFGDecodeError(INIDecodeError, SetupCFGError):
"""Raised when a setup.cfg file cannot be decoded."""

@property
@override
def name(self) -> str:
"""The name of the file that could not be decoded."""
return "setup.cfg"
Expand Down
8 changes: 8 additions & 0 deletions src/usethis/_file/setup_cfg/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from typing_extensions import override

from usethis._file.ini.errors import (
INIDecodeError,
ININotFoundError,
Expand Down Expand Up @@ -35,15 +37,18 @@ class SetupCFGManager(INIFileManager):
"""Manages the setup.cfg file."""

@property
@override
def relative_path(self) -> Path:
return Path("setup.cfg")

@override
def __enter__(self) -> Self:
try:
return super().__enter__()
except UnexpectedINIOpenError as err:
raise UnexpectedSetupCFGOpenError(err) from None

@override
def read_file(self) -> INIDocument:
try:
return super().read_file()
Expand All @@ -54,12 +59,14 @@ def read_file(self) -> INIDocument:
except INIDecodeError as err:
raise SetupCFGDecodeError(err) from None

@override
def _validate_lock(self) -> None:
try:
super()._validate_lock()
except UnexpectedINIIOError as err:
raise UnexpectedSetupCFGIOError(err) from None

@override
def set_value(
self, *, keys: Sequence[Key], value: Any, exists_ok: bool = False
) -> None:
Expand All @@ -69,6 +76,7 @@ def set_value(
except INIValueAlreadySetError as err:
raise SetupCFGValueAlreadySetError(err) from None

@override
def __delitem__(self, keys: Sequence[Key]) -> None:
"""Remove a value from the pyproject.toml configuration file."""
try:
Expand Down
Loading
Loading