From 25cbe8de4be354c213d32b2b01a23e72289351f9 Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Fri, 10 Mar 2023 16:57:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20`isort`=20and=20`ruff`=20as?= =?UTF-8?q?=20dev=20dependencies;=20=E2=9E=96=20remove=20`flake8`=20depend?= =?UTF-8?q?ency=20(replaced=20by=20`ruff`);=20change=20`lint.sh`=20script?= =?UTF-8?q?=20to=20use=20`isort`,=20`ruff`,=20and=20`black`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 46 ++++++++++++++++++++++++--- requirements/dev.txt | 3 +- scripts/lint.sh | 4 ++- src/marshmallow_generic/_util.py | 1 - src/marshmallow_generic/decorators.py | 1 - tests/__main__.py | 1 - tests/test__util.py | 4 +-- 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c95c5fa..c1b750e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,10 +44,11 @@ dev = [ "black", "build", "coverage[toml]", - "flake8", + "isort", "mkdocs-material", "mkdocstrings[python]", "mypy", + "ruff", ] [project.urls] @@ -60,8 +61,8 @@ dependencies = { file = "requirements/common.txt" } readme = { file = ["README.md"] } version = {attr = "marshmallow_generic.__version__"} -######### -# Mypy: # +######################### +# Static type checking: # [tool.mypy] files = [ @@ -75,8 +76,8 @@ plugins = [ ] -############# -# Coverage: # +####################### +# Unit test coverage: # [tool.coverage.run] source = [ @@ -99,3 +100,38 @@ exclude_lines = [ omit = [ "tests/*", ] + +############################### +# Linting and style checking: # + +[tool.ruff] +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "D", # pydocstyle + "C", # flake8-comprehensions + "B", # flake8-bugbear + "PL", # pylint + "RUF", # ruff-specific +] +ignore = [ + "E501", # Line too long -> handled by black + "D203", # 1 blank line required before class docstring -> D211 is better + "D212", # Multi-line docstring summary should start at the first line -> ugly, D212 is better +] + +[tool.ruff.per-file-ignores] +"tests/*.py" = [ + "D100", # Missing docstring in public module + "D101", # Missing docstring in public class + "D102", # Missing docstring in public method + "D104", # Missing docstring in public package +] + +################### +# Import sorting: # + +[tool.isort] +profile = "black" +extra_standard_library = ["typing_extensions"] diff --git a/requirements/dev.txt b/requirements/dev.txt index 2124456..20431cc 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -2,7 +2,8 @@ black build coverage[toml] -flake8 +isort mkdocs-material mkdocstrings[python] mypy +ruff diff --git a/scripts/lint.sh b/scripts/lint.sh index 7bf4a58..7b46039 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -12,5 +12,7 @@ mypy echo echo 'Linting source and test files...' -flake8 src/ tests/ +isort src/ tests/ --check-only +ruff src/ tests/ +black src/ tests/ --check echo -e 'No issues found.' diff --git a/src/marshmallow_generic/_util.py b/src/marshmallow_generic/_util.py index bf9f152..3426876 100644 --- a/src/marshmallow_generic/_util.py +++ b/src/marshmallow_generic/_util.py @@ -1,6 +1,5 @@ from typing import Any, Generic, Optional, TypeVar, get_args, get_origin - _T = TypeVar("_T") diff --git a/src/marshmallow_generic/decorators.py b/src/marshmallow_generic/decorators.py index 1e46fc5..a33e7d5 100644 --- a/src/marshmallow_generic/decorators.py +++ b/src/marshmallow_generic/decorators.py @@ -4,7 +4,6 @@ from typing_extensions import ParamSpec from marshmallow.decorators import post_load as _post_load - _R = TypeVar("_R") _P = ParamSpec("_P") diff --git a/tests/__main__.py b/tests/__main__.py index fa3bae6..3acb7c1 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -1,7 +1,6 @@ import sys import unittest - if __name__ == "__main__": try: pattern = sys.argv[1] diff --git a/tests/test__util.py b/tests/test__util.py index ee09dfe..7d00205 100644 --- a/tests/test__util.py +++ b/tests/test__util.py @@ -12,9 +12,7 @@ class GenericInsightMixinTestCase(TestCase): mock_super.return_value = MagicMock(__init_subclass__=mock_super_meth) # Should be `None` by default: - self.assertIsNone( - _util.GenericInsightMixin._type_arg # type: ignore[misc] - ) + self.assertIsNone(_util.GenericInsightMixin._type_arg) # type: ignore[misc] # If the mixin type argument was not specified (still generic), # ensure that the attribute remains `None` on the subclass: