Skip to content

Commit

Permalink
build: 🛠 Convert everything to use ruff and just
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed Aug 10, 2023
1 parent 9b0825f commit 0cf3901
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 140 deletions.
29 changes: 0 additions & 29 deletions .flake8

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
run: |
python -m pip install --upgrade poetry
poetry install
- name: Lint with flake8
- name: Lint with ruff & mypy
run: |
poetry run flake8 pydantic_changedetect tests
poetry run ruff check pydantic_changedetect tests
poetry run mypy pydantic_changedetect
29 changes: 4 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,11 @@ repos:
- id: check-merge-conflict
- id: check-docstring-first
- id: debug-statements
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
hooks:
- id: flake8
args: ["--config=.flake8"]
additional_dependencies:
- flake8-builtins
- flake8-annotations
- flake8-commas
- flake8-isort
- flake8-print
- flake8-debugger
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.0
hooks:
- id: add-trailing-comma
args: ["--py36-plus"]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.3.1
hooks:
Expand Down
60 changes: 0 additions & 60 deletions build/Taskfile

This file was deleted.

30 changes: 30 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
install-pre-commit:
#!/usr/bin/env bash
if ( which pre-commit > /dev/null 2>&1 )
then
pre-commit install --install-hooks
else
echo "-----------------------------------------------------------------"
echo "pre-commit is not installed - cannot enable pre-commit hooks!"
echo "Recommendation: Install pre-commit ('brew install pre-commit')."
echo "-----------------------------------------------------------------"
fi
install: install-pre-commit (poetry "install")

update: (poetry "install")

poetry *args:
poetry {{args}}

test *args: (poetry "run" "pytest" "--cov=pydantic_changedetect" "--cov-report" "term-missing:skip-covered" args)

test-all: (poetry "run" "tox")

ruff *args: (poetry "run" "ruff" "check" "pydantic_changedetect" "tests" args)

mypy *args: (poetry "run" "mypy" "pydantic_changedetect" args)

lint: ruff mypy

publish: (poetry "publish" "--build")
2 changes: 1 addition & 1 deletion pydantic_changedetect/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")

if PYDANTIC_V1: # pragma: no cover
class PydanticCompat: # noqa: F811
class PydanticCompat:
obj: pydantic.BaseModel

def __init__(
Expand Down
11 changes: 10 additions & 1 deletion pydantic_changedetect/changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def model_dump_json(

return super().model_dump_json(
**self._get_changed_export_includes(
indent=indent,
include=include,
exclude=exclude,
by_alias=by_alias,
Expand All @@ -373,12 +374,13 @@ def copy(
*,
include: "Union[AbstractSetIntStr, MappingIntStrAny, None]" = None,
exclude: "Union[AbstractSetIntStr, MappingIntStrAny, None]" = None,
update: Optional[Dict[str, Any]] = None, # noqa UP006
update: Optional[Dict[str, Any]] = None,
deep: bool = False,
) -> "Model":
warnings.warn(
"copy(...) is deprecated even in pydantic v2, use model_copy(...) instead",
DeprecationWarning,
stacklevel=2,
)
clone = cast(
"Model",
Expand Down Expand Up @@ -559,6 +561,7 @@ def reset_changed(self) -> None:
warnings.warn(
"reset_changed() is deprecated, use model_reset_changed() instead",
DeprecationWarning,
stacklevel=2,
)
self.model_reset_changed()

Expand All @@ -567,6 +570,7 @@ def __original__(self) -> Dict[str, Any]:
warnings.warn(
"__original__ is deprecated, use model_original instead",
DeprecationWarning,
stacklevel=2,
)
return self.model_original

Expand All @@ -575,6 +579,7 @@ def __self_changed_fields__(self) -> Set[str]:
warnings.warn(
"__self_changed_fields__ is deprecated, use model_self_changed_fields instead",
DeprecationWarning,
stacklevel=2,
)
return self.model_self_changed_fields

Expand All @@ -583,6 +588,7 @@ def __changed_fields__(self) -> Set[str]:
warnings.warn(
"__changed_fields__ is deprecated, use model_changed_fields instead",
DeprecationWarning,
stacklevel=2,
)
return self.model_changed_fields

Expand All @@ -591,6 +597,7 @@ def __changed_fields_recursive__(self) -> Set[str]:
warnings.warn(
"__changed_fields_recursive__ is deprecated, use model_changed_fields_recursive instead",
DeprecationWarning,
stacklevel=2,
)
return self.model_changed_fields_recursive

Expand All @@ -599,6 +606,7 @@ def has_changed(self) -> bool:
warnings.warn(
"has_changed is deprecated, use model_has_changed instead",
DeprecationWarning,
stacklevel=2,
)
return self.model_has_changed

Expand All @@ -612,5 +620,6 @@ def set_changed(self, *fields: str, original: Any = NO_VALUE) -> None:
warnings.warn(
"set_changed(...) is deprecated, use model_set_changed(...) instead",
DeprecationWarning,
stacklevel=2,
)
self.model_set_changed(*fields, original=original)
1 change: 1 addition & 0 deletions pydantic_changedetect/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def safe_issubclass(cls: Any, type_: Any) -> bool:
warnings.warn(
"safe_issubclass() is deprecated and will be removed",
DeprecationWarning,
stacklevel=2,
)

if not isinstance(cls, type):
Expand Down
25 changes: 12 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ pydantic = ">=1.9.0,<3.0.0"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.1.2,<8.0.0"
isort = "^5.10.1"
mypy = ">=0.971,<2.0"
flake8 = ">=5.0.4,<7.0.0"
flake8-builtins = ">=1.5.3,<3.0.0"
flake8-annotations = ">=2.9.1,<4.0.0"
flake8-commas = "^2.1.0"
flake8-isort = ">=4.2,<7.0"
flake8-print = "^5.0.0"
flake8-debugger = "^4.1.2"
pytest-cov = ">=3,<5"
mypy = ">=0.971,<2.0"
tox = ">=3.26,<5.0"
ruff = "^0.0.284"

[tool.ruff]
select = ["F","E","W","C","I","N","UP","ANN","S","B","A","COM","C4","T20","PT","ARG","TD","RUF"]
line-length = 115
target-version = "py38"
ignore = ["A001","A002","A003","ANN101","ANN102","ANN401","C901","N8","B008","F405","F821"]

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
line_length = 115
[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"conftest.py" = ["S101","ANN","F401"]
"test_*.py" = ["S101","ANN","F401"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
18 changes: 9 additions & 9 deletions tests/test_changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,22 @@ def test_changed_base_is_resetable_with_v1_api():
def test_pickle_keeps_state():
obj = Something(id=1)

assert not pickle.loads(pickle.dumps(obj)).model_has_changed
assert pickle.loads(pickle.dumps(obj)).model_changed_fields == set()
assert not pickle.loads(pickle.dumps(obj)).model_has_changed # noqa: S301
assert pickle.loads(pickle.dumps(obj)).model_changed_fields == set() # noqa: S301

obj.id = 2

assert pickle.loads(pickle.dumps(obj)).model_has_changed
assert pickle.loads(pickle.dumps(obj)).model_changed_fields == {"id"}
assert pickle.loads(pickle.dumps(obj)).model_has_changed # noqa: S301
assert pickle.loads(pickle.dumps(obj)).model_changed_fields == {"id"} # noqa: S301


def test_pickle_even_works_when_changed_state_is_missing():
obj = SomethingWithBrokenPickleState(id=1)
obj.id = 2

# Now we cannot use the changed state, but nothing fails
assert not pickle.loads(pickle.dumps(obj)).model_has_changed
assert pickle.loads(pickle.dumps(obj)).model_changed_fields == set()
assert not pickle.loads(pickle.dumps(obj)).model_has_changed # noqa: S301
assert pickle.loads(pickle.dumps(obj)).model_changed_fields == set() # noqa: S301


def test_stores_original():
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_nested_changed_state():


@pytest.mark.parametrize(
"parent_class, list_type", [
("parent_class", "list_type"), [
(NestedList, list),
(NestedTuple, tuple),
],
Expand Down Expand Up @@ -409,7 +409,7 @@ def test_model_construct_works():


@pytest.mark.skipif(PYDANTIC_V1, reason="pydantic v1 does not trigger warnings")
def test_construct_works():
def test_construct_works_on_v2():
with pytest.warns(DeprecationWarning):
something = Something.construct(id=1)

Expand All @@ -421,7 +421,7 @@ def test_construct_works():


@pytest.mark.skipif(PYDANTIC_V2, reason="pydantic v2 does trigger warnings")
def test_construct_works():
def test_construct_works_on_v1():
something = Something.construct(id=1)

assert something.model_has_changed is False
Expand Down

0 comments on commit 0cf3901

Please sign in to comment.