Skip to content

Commit

Permalink
Ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Jan 10, 2024
1 parent 9503cc3 commit 7d412b4
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 26 deletions.
33 changes: 22 additions & 11 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ select = [
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf

# "PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
# "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
"PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
]

ignore = [
"RET501" # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/
"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/
"PLR1711", # https://docs.astral.sh/ruff/rules/useless-return/
]


Expand All @@ -50,15 +52,24 @@ ignore = [
quote-style = "single"


[lint.isort]
known-local-folder = ["easyconfig"]
known-first-party = ["tests", "helper"]
[lint.per-file-ignores]
"docs/*" = [
"A001", # A001 Variable `copyright` is shadowing a Python builtin
"E402", # E402 Module level import not at top of file
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
]

"tests/*" = [
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
"ISC002", # ISC002 Implicitly concatenated string literals over multiple lines
"PLR2004", # PLR2004 Magic value used in comparison, consider replacing 5 with a constant variable
]

[lint.flake8-builtins]
builtins-ignorelist = ["id"]
"setup.py" = ["PTH123"]
"src/easyconfig/yaml/from_model.py" = ["PLR0911"] # PLR0911 Too many return statements (7 > 6)


[lint.per-file-ignores]
"docs/conf.py" = ["INP001", "A001"]
"setup.py" = ["PTH123"]

[lint.isort]
# https://docs.astral.sh/ruff/settings/#isort-lines-after-imports
lines-after-imports = 2
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
import sys
from pathlib import Path


src_folder = Path(__file__).parent.with_name('src')
assert src_folder.is_dir()

# required for autodoc
sys.path.insert(0, str(src_folder))

import easyconfig # noqa: E402
import easyconfig


# -- Project information -----------------------------------------------------
project = 'easyconfig'
copyright = '2023, spacemanspiff2007'
copyright = '2024, spacemanspiff2007'
author = 'spacemanspiff2007'

# The full version, including alpha/beta/rc tags
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def load_req() -> typing.List[str]:
author='spaceman_spiff',
# author_email="",
description='Easy application configuration with yaml files',
keywords=['yaml', 'configuration', 'pydantic', 'settings', 'config'],
keywords=['yaml', 'configuration', 'pydantic', 'settings', 'config', 'yml'],
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/spacemanspiff2007/easyconfig',
Expand All @@ -57,6 +57,7 @@ def load_req() -> typing.List[str]:
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Software Development :: Libraries',
],
Expand Down
5 changes: 3 additions & 2 deletions src/easyconfig/config_objs/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from pathlib import Path
from typing import TYPE_CHECKING

from ..errors import FileDefaultsNotSetError
from .object_config import ConfigObj
from easyconfig.__const__ import MISSING, MISSING_TYPE
from easyconfig.config_objs.object_config import ConfigObj
from easyconfig.errors import FileDefaultsNotSetError
from easyconfig.expansion import expand_obj
from easyconfig.yaml import CommentedMap, cmap_from_model, write_aligned_yaml, yaml_rt


if TYPE_CHECKING:
from pydantic import BaseModel
from typing_extensions import Self
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/config_objs/object_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from easyconfig.config_objs import ConfigObjSubscription, SubscriptionParent
from easyconfig.errors import DuplicateSubscriptionError, FunctionCallNotAllowedError


if TYPE_CHECKING:
from pydantic.fields import FieldInfo

Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/config_objs/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from easyconfig.errors import SubscriptionAlreadyCanceledError


if TYPE_CHECKING:
import easyconfig

Expand Down
3 changes: 2 additions & 1 deletion src/easyconfig/create_app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from easyconfig.config_objs.app_config import AppConfig, yaml_rt
from easyconfig.errors import ExtraKwArgsNotAllowedError


TYPE_WRAPPED = TypeVar('TYPE_WRAPPED', bound=BaseModel)
TYPE_DEFAULTS = Union[BaseModel, Dict[str, Any]]

Expand Down Expand Up @@ -37,7 +38,7 @@ def check_field_args(model: AppConfig, allowed: FrozenSet[str]):


def get_file_values(
model: TYPE_WRAPPED, file_values: Union[MISSING_TYPE, None, TYPE_DEFAULTS, Callable[[], TYPE_DEFAULTS]] = MISSING
model: BaseModel, file_values: Union[MISSING_TYPE, None, TYPE_DEFAULTS, Callable[[], TYPE_DEFAULTS]] = MISSING
) -> Optional[BaseModel]:
# Implicit default
if file_values is MISSING:
Expand Down
2 changes: 1 addition & 1 deletion src/easyconfig/errors/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def default_exception_handler(e: Exception):


def set_exception_handler(handler: Callable[[Exception], Any]):
global HANDLER
global HANDLER # noqa: PLW0603
HANDLER = handler


Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/expansion/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .load_var import read_env_var
from .location import ExpansionLocation


RE_REPLACE = re.compile(r'''
(?<!\$)\$\{
(?P<value>.*?[^$])?
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/expansion/load_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .location import ExpansionLocation, log


# https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
RE_WIN_PATH = re.compile(
r'''
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/expansion/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from easyconfig.errors.errors import CyclicEnvironmentVariableReferenceError


log = logging.getLogger('easyconfig.expansion')


Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from easyconfig.models.config import ConfigMixin


if TYPE_CHECKING:
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from easyconfig.errors import FunctionCallNotAllowedError


if TYPE_CHECKING:
import easyconfig
import easyconfig.config_objs
Expand Down
2 changes: 1 addition & 1 deletion src/easyconfig/yaml/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def remove_none(obj: Union[dict]):
remove_none(value)
if not value:
rem.append(index)
else:
else: # noqa: PLR5501
if value is None:
rem.append(index)

Expand Down
2 changes: 0 additions & 2 deletions src/easyconfig/yaml/from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from easyconfig.__const__ import ARG_NAME_IN_FILE, MISSING
from easyconfig.yaml import CommentedMap, CommentedSeq

NoneType = type(None)


def _get_yaml_value(obj, parent_model: BaseModel, *, skip_none=True, obj_name: str | None = None):
if obj is None:
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/yaml/yaml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ruamel.yaml # type: ignore


yaml_rt = ruamel.yaml.YAML(typ='rt')
yaml_safe = ruamel.yaml.YAML(typ='safe')

Expand Down
3 changes: 2 additions & 1 deletion tests/helper/my_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path as _Path
from typing import Optional


_path_type = type(_Path())


Expand Down Expand Up @@ -39,7 +40,7 @@ def is_file(self) -> bool:
def get_value(self) -> str:
return self.contents.getvalue()

def open(self, *args, mode='r', **kwargs) -> TextIOWrapper: # noqa: A003
def open(self, *args, mode='r', **kwargs) -> TextIOWrapper:
if 'w' in mode and 'a' not in mode:
self._create_buffer()
return self.contents
Expand Down
3 changes: 1 addition & 2 deletions tests/test_implementation/test_load_file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from pydantic import BaseModel as PydanticBaseModel

from helper import Path
from pydantic import BaseModel as PydanticBaseModel

from easyconfig import AppBaseModel, BaseModel
from easyconfig.config_objs import AppConfig
Expand Down
2 changes: 0 additions & 2 deletions tests/yaml/test_model_to_yaml.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# ruff: noqa: ISC002
from datetime import datetime
from enum import Enum
from typing import List, Optional

from pydantic import AnyHttpUrl, BaseModel, ByteSize, Field

from tests.helper import dump_yaml

from easyconfig.__const__ import ARG_NAME_IN_FILE
Expand Down

0 comments on commit 7d412b4

Please sign in to comment.