diff --git a/python_coderunner/src/command_builder/interpolator_command_builder.py b/python_coderunner/src/command_builder/interpolator_command_builder.py index 4843bef..84e08c2 100644 --- a/python_coderunner/src/command_builder/interpolator_command_builder.py +++ b/python_coderunner/src/command_builder/interpolator_command_builder.py @@ -7,14 +7,14 @@ class TInterpolatorCommandBuilder(ICommandBuilder): - WORKSPACE_ROOT_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$workspaceRoot") - FULL_FILE_NAME_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$fullFileName") - FILE_NAME_WITHOUT_EXT_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$fileNameWithoutExt") - FILE_NAME_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$fileName") - FILE_EXT: ClassVar[re.Pattern[str]] = re.compile(r"\$fileExt") - DRIVE_LETTER_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$driveLetter") - DIR_WITHOUT_TRAILING_SLASH_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$dirWithoutTrailingSlash") - DIR_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$dir") + _WORKSPACE_ROOT_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$workspaceRoot") + _FULL_FILE_NAME_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$fullFileName") + _FILE_NAME_WITHOUT_EXT_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$fileNameWithoutExt") + _FILE_NAME_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$fileName") + _FILE_EXT: ClassVar[re.Pattern[str]] = re.compile(r"\$fileExt") + _DRIVE_LETTER_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$driveLetter") + _DIR_WITHOUT_TRAILING_SLASH_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$dirWithoutTrailingSlash") + _DIR_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"\$dir") def __init__( self, @@ -34,23 +34,23 @@ def _interpolate(self, file_path_abs: str) -> str: The reverse alphabetical order is important so that substitutions are performed greedily, i.e. $dirWithoutTrailingSlash must be before $dir. """ - interpolated_str: str = self.WORKSPACE_ROOT_PATTERN.sub( + interpolated_str: str = self._WORKSPACE_ROOT_PATTERN.sub( self._project_info_extractor.get_workspace_root(), self._template_string ) - interpolated_str = self.FULL_FILE_NAME_PATTERN.sub(file_path_abs, interpolated_str) - interpolated_str = self.FILE_NAME_WITHOUT_EXT_PATTERN.sub( + interpolated_str = self._FULL_FILE_NAME_PATTERN.sub(file_path_abs, interpolated_str) + interpolated_str = self._FILE_NAME_WITHOUT_EXT_PATTERN.sub( self._file_info_extractor.get_file_name_without_ext(file_path_abs), interpolated_str ) - interpolated_str = self.FILE_NAME_PATTERN.sub( + interpolated_str = self._FILE_NAME_PATTERN.sub( self._file_info_extractor.get_file_name(file_path_abs), interpolated_str ) - interpolated_str = self.FILE_EXT.sub(self._file_info_extractor.get_file_ext(file_path_abs), interpolated_str) - interpolated_str = self.DRIVE_LETTER_PATTERN.sub( + interpolated_str = self._FILE_EXT.sub(self._file_info_extractor.get_file_ext(file_path_abs), interpolated_str) + interpolated_str = self._DRIVE_LETTER_PATTERN.sub( self._file_info_extractor.get_drive_letter(file_path_abs), interpolated_str ) - interpolated_str = self.DIR_WITHOUT_TRAILING_SLASH_PATTERN.sub( + interpolated_str = self._DIR_WITHOUT_TRAILING_SLASH_PATTERN.sub( self._file_info_extractor.get_dir_without_trailing_slash(file_path_abs), interpolated_str ) - interpolated_str = self.DIR_PATTERN.sub(self._file_info_extractor.get_dir(file_path_abs), interpolated_str) + interpolated_str = self._DIR_PATTERN.sub(self._file_info_extractor.get_dir(file_path_abs), interpolated_str) return interpolated_str diff --git a/python_coderunner/src/config/config_field.py b/python_coderunner/src/config/config_field.py index 2aa73d0..7a8c808 100644 --- a/python_coderunner/src/config/config_field.py +++ b/python_coderunner/src/config/config_field.py @@ -32,9 +32,11 @@ def get(self) -> ValueType: try: raw_value: Any = self._getter() except UndefinedValueError as e: - raise ConfigFieldUndefinedValueError.from_undefined_value_error(e, self._allowed_values_description) + raise ConfigFieldUndefinedValueError.from_undefined_value_error(e, self._allowed_values_description) from e try: return self._validator(raw_value) except ValidationError as e: - raise ConfigFieldValidationError.from_validation_error(e, self._name, self._allowed_values_description) + raise ConfigFieldValidationError.from_validation_error( + e, self._name, self._allowed_values_description + ) from e diff --git a/python_coderunner/src/config/getter/interface.py b/python_coderunner/src/config/getter/interface.py index 8456121..92f6b87 100644 --- a/python_coderunner/src/config/getter/interface.py +++ b/python_coderunner/src/config/getter/interface.py @@ -1,3 +1,14 @@ -from typing import Any, Callable, TypeAlias +from abc import ABC, abstractmethod +from typing import Any -IConfigValueGetter: TypeAlias = Callable[[], Any] + +class IConfigValueGetter(ABC): + @abstractmethod + def __call__(self) -> Any: + """ + Gets config value from external source. + + Raises: + UndefinedValueError: If the config value is not defined. + """ + raise NotImplementedError diff --git a/python_coderunner/src/config/getter/vim_config_value_getter.py b/python_coderunner/src/config/getter/vim_config_value_getter.py index 4f4a95c..3391ef5 100644 --- a/python_coderunner/src/config/getter/vim_config_value_getter.py +++ b/python_coderunner/src/config/getter/vim_config_value_getter.py @@ -3,9 +3,10 @@ import vim from .exceptions import UndefinedValueError +from .interface import IConfigValueGetter -class TBaseVimConfigValueGetter: +class TBaseVimConfigValueGetter(IConfigValueGetter): """Base class for getting Vim config values""" def _get_vim_var(self, var_name: str) -> Any: diff --git a/python_coderunner/src/config/interface.py b/python_coderunner/src/config/interface.py index 2015e00..c931af9 100644 --- a/python_coderunner/src/config/interface.py +++ b/python_coderunner/src/config/interface.py @@ -9,8 +9,6 @@ class EDispatchersTypes(StrEnum): class IConfig(ABC): - """Configuration interface""" - @abstractmethod def get_by_file_ext(self) -> dict[str, str]: """Gets config for file extension-based dispatching""" diff --git a/python_coderunner/src/config/validator/interface.py b/python_coderunner/src/config/validator/interface.py index e30e4ef..534e0e5 100644 --- a/python_coderunner/src/config/validator/interface.py +++ b/python_coderunner/src/config/validator/interface.py @@ -9,6 +9,8 @@ class IValidator(ABC, Generic[ValueType]): def __call__(self, value: Any) -> ValueType: """ Validates value and returns typed result. - Raises ValidationError on validation failure. + + Raises: + ValidationError on validation failure. """ raise NotImplementedError