Skip to content

Commit

Permalink
Add ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed May 15, 2023
1 parent b9348bd commit 45cdc87
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ _build/
/sandbox/
/.ghtopdep_cache/
/worktrees/
/.ruff_cache/
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ install:

.PHONY: format
format:
pyupgrade --py37-plus --exit-zero-even-if-changed `find $(sources) -name "*.py" -type f`
isort $(sources)
black $(sources)
ruff --fix $(sources)

.PHONY: lint
lint:
flake8 $(sources)
isort $(sources) --check-only --df
ruff $(sources)
black $(sources) --check --diff

.PHONY: mypy
Expand Down
15 changes: 10 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ For example:

```py
import os
from pprint import pprint
from typing import Any, Callable, Set

from pydantic import (
AliasChoices,
AmqpDsn,
BaseModel,
ConfigDict,
Field,
ImportString,
RedisDsn,
PostgresDsn,
AmqpDsn,
Field,
RedisDsn,
)

from pydantic_settings import BaseSettings


Expand Down Expand Up @@ -62,7 +62,7 @@ class Settings(BaseSettings):
os.environ['my_auth_key'] = 'xxx'
os.environ['my_api_key'] = 'xxx'

pprint(Settings().model_dump())
print(Settings().model_dump())
"""
{
'auth_key': '',
Expand Down Expand Up @@ -225,6 +225,7 @@ import os
from typing import Any, List, Tuple, Type

from pydantic.fields import FieldInfo

from pydantic_settings import BaseSettings, EnvSettingsSource, PydanticBaseSettingsSource


Expand Down Expand Up @@ -431,7 +432,9 @@ The order of the returned callables decides the priority of inputs; first item i

```py
from typing import Tuple, Type

from pydantic import PostgresDsn

from pydantic_settings import BaseSettings, PydanticBaseSettingsSource


Expand Down Expand Up @@ -468,6 +471,7 @@ from typing import Any, Dict, Tuple, Type

from pydantic import ConfigDict
from pydantic.fields import FieldInfo

from pydantic_settings import BaseSettings, PydanticBaseSettingsSource


Expand Down Expand Up @@ -535,6 +539,7 @@ You might also want to disable a source:
from typing import Tuple, Type

from pydantic import ValidationError

from pydantic_settings import BaseSettings, PydanticBaseSettingsSource


Expand Down
2 changes: 1 addition & 1 deletion pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def _read_env_files(self, case_sensitive: bool) -> Mapping[str, str | None]:
def __call__(self) -> dict[str, Any]:
data: dict[str, Any] = super().__call__()

data_lower_keys: List[str] = []
data_lower_keys: list[str] = []
if not self.settings_cls.model_config.get('case_sensitive', False):
data_lower_keys = [x.lower() for x in data.keys()]

Expand Down
24 changes: 8 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ filterwarnings = [
'ignore:This is a placeholder until pydantic-settings.*:UserWarning',
]

[tool.flake8]
max_line_length = 120
max_complexity = 14
inline_quotes = 'single'
multiline_quotes = 'double'
ignore = ['E203', 'W503']

[tool.coverage.run]
source = ['pydantic_settings']
branch = true
Expand All @@ -86,21 +79,20 @@ source = [
'pydantic_settings/',
]

[tool.ruff]
line-length = 120
extend-select = ['Q', 'RUF100', 'C90', 'UP', 'I']
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
mccabe = { max-complexity = 14 }
isort = { known-first-party = ['pydantic_settings', 'tests'] }
target-version = "py37"

[tool.black]
color = true
line-length = 120
target-version = ['py310']
skip-string-normalization = true

[tool.isort]
line_length = 120
known_first_party = 'pydantic_settings'
known_third_party = 'pydantic'
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
combine_as_imports = true

[tool.mypy]
python_version = '3.10'
show_error_codes = true
Expand Down
6 changes: 1 addition & 5 deletions requirements/linting.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
black
flake8
flake8-quotes
flake8-pyproject
isort
pyupgrade
ruff
mypy
pre-commit
32 changes: 4 additions & 28 deletions requirements/linting.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements/linting.txt requirements/linting.in
#
Expand All @@ -14,21 +14,8 @@ distlib==0.3.6
# via virtualenv
filelock==3.12.0
# via virtualenv
flake8==6.0.0
# via
# -r requirements/linting.in
# flake8-pyproject
# flake8-quotes
flake8-pyproject==1.2.3
# via -r requirements/linting.in
flake8-quotes==3.3.2
# via -r requirements/linting.in
identify==2.5.24
# via pre-commit
isort==5.12.0
# via -r requirements/linting.in
mccabe==0.7.0
# via flake8
mypy==1.3.0
# via -r requirements/linting.in
mypy-extensions==1.0.0
Expand All @@ -47,21 +34,10 @@ platformdirs==3.5.1
# virtualenv
pre-commit==3.3.1
# via -r requirements/linting.in
pycodestyle==2.10.0
# via flake8
pyflakes==3.0.1
# via flake8
pyupgrade==3.4.0
# via -r requirements/linting.in
pyyaml==6.0
# via pre-commit
tokenize-rt==5.0.0
# via pyupgrade
tomli==2.0.1
# via
# black
# flake8-pyproject
# mypy
ruff==0.0.265
# via -r requirements/linting.in
typing-extensions==4.5.0
# via mypy
virtualenv==20.23.0
Expand Down
1 change: 1 addition & 0 deletions requirements/testing.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pytest
pytest-mock
pytest-sugar
pytest-examples
pytest-pretty
42 changes: 24 additions & 18 deletions requirements/testing.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
#
# This file is autogenerated by pip-compile with python 3.7
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements/testing.txt requirements/testing.in
#
black==23.3.0
# via pytest-examples
click==8.1.3
# via black
coverage[toml]==7.2.5
# via -r requirements/testing.in
exceptiongroup==1.1.1
# via pytest
importlib-metadata==6.6.0
# via
# pluggy
# pytest
iniconfig==2.0.0
# via pytest
markdown-it-py==2.2.0
# via rich
mdurl==0.1.2
# via markdown-it-py
mypy-extensions==1.0.0
# via black
packaging==23.1
# via
# black
# pytest
# pytest-sugar
pathspec==0.11.1
# via black
platformdirs==3.5.1
# via black
pluggy==1.0.0
# via pytest
pygments==2.15.1
# via rich
pytest==7.3.1
# via
# -r requirements/testing.in
# pytest-examples
# pytest-mock
# pytest-pretty
# pytest-sugar
pytest-examples==0.0.9
# via -r requirements/testing.in
pytest-mock==3.10.0
# via -r requirements/testing.in
pytest-pretty==1.2.0
# via -r requirements/testing.in
pytest-sugar==0.9.7
# via -r requirements/testing.in
rich==13.3.5
# via pytest-pretty
ruff==0.0.265
# via pytest-examples
termcolor==2.3.0
# via pytest-sugar
tomli==2.0.1
# via
# coverage
# pytest
typed-ast==1.5.4
# via black
typing-extensions==4.5.0
# via importlib-metadata
zipp==3.15.0
# via importlib-metadata
14 changes: 1 addition & 13 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest
from pytest_examples import CodeExample, EvalExample, find_examples

INDEX_MAIN = None
DOCS_ROOT = Path(__file__).parent.parent / 'docs'


Expand Down Expand Up @@ -50,17 +49,6 @@ def print_callback(print_statement: str) -> str:
@pytest.mark.skipif(bool(skip_reason), reason=skip_reason or 'not skipping')
@pytest.mark.parametrize('example', find_examples(str(DOCS_ROOT), skip=sys.platform == 'win32'), ids=str)
def test_docs_examples(example: CodeExample, eval_example: EvalExample, tmp_path: Path, mocker): # noqa: C901
global INDEX_MAIN
if example.path.name == 'index.md':
if INDEX_MAIN is None:
INDEX_MAIN = example.source
else:
(tmp_path / 'index_main.py').write_text(INDEX_MAIN)
sys.path.append(str(tmp_path))

if example.path.name == 'devtools.md':
pytest.skip('tested below')

eval_example.print_callback = print_callback

prefix_settings = example.prefix_settings()
Expand All @@ -82,7 +70,7 @@ def test_docs_examples(example: CodeExample, eval_example: EvalExample, tmp_path
if group_name:
eval_example.set_config(ruff_ignore=['F821'])

eval_example.set_config(line_length=120)
# eval_example.set_config(line_length=120)
if lint_settings != 'skip':
if eval_example.update_examples:
eval_example.format(example)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
HttpUrl,
SecretStr,
ValidationError,
)
from pydantic import (
dataclasses as pydantic_dataclasses,
)
from pydantic.fields import FieldInfo
Expand Down

0 comments on commit 45cdc87

Please sign in to comment.