diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 58a32a8..9c0e002 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v2 @@ -16,6 +16,6 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install Python Dependencies - run: pip install -r requirements/ci.txt + run: pip install -r requirements/nox-deps.txt - name: Run Tests - run: tox + run: nox -s test diff --git a/flake8_idom_hooks/__init__.py b/flake8_idom_hooks/__init__.py index 5937afe..689fb5d 100644 --- a/flake8_idom_hooks/__init__.py +++ b/flake8_idom_hooks/__init__.py @@ -1,7 +1,5 @@ -from pkg_resources import ( - get_distribution as _get_distribution, - DistributionNotFound as _DistributionNotFound, -) +from pkg_resources import DistributionNotFound as _DistributionNotFound +from pkg_resources import get_distribution as _get_distribution try: __version__: str = _get_distribution(__name__).version diff --git a/flake8_idom_hooks/exhaustive_deps.py b/flake8_idom_hooks/exhaustive_deps.py index b828284..7ce6620 100644 --- a/flake8_idom_hooks/exhaustive_deps.py +++ b/flake8_idom_hooks/exhaustive_deps.py @@ -1,8 +1,7 @@ import ast -from typing import Optional, Union, Set - -from .utils import is_hook_def, is_component_def, ErrorVisitor, set_current +from typing import Optional, Set, Union +from .utils import ErrorVisitor, is_component_def, is_hook_def, set_current HOOKS_WITH_DEPS = ("use_effect", "use_callback", "use_memo") diff --git a/flake8_idom_hooks/rules_of_hooks.py b/flake8_idom_hooks/rules_of_hooks.py index 5e54dc8..ead80ba 100644 --- a/flake8_idom_hooks/rules_of_hooks.py +++ b/flake8_idom_hooks/rules_of_hooks.py @@ -1,10 +1,10 @@ import ast -from typing import Union, Optional +from typing import Optional, Union from .utils import ( - is_hook_def, - is_component_def, ErrorVisitor, + is_component_def, + is_hook_def, is_hook_function_name, set_current, ) diff --git a/flake8_idom_hooks/run.py b/flake8_idom_hooks/run.py index 2760b6c..f734bac 100644 --- a/flake8_idom_hooks/run.py +++ b/flake8_idom_hooks/run.py @@ -2,9 +2,9 @@ import ast -from .utils import ErrorVisitor from .exhaustive_deps import ExhaustiveDepsVisitor from .rules_of_hooks import RulesOfHooksVisitor +from .utils import ErrorVisitor def run_checks( diff --git a/flake8_idom_hooks/utils.py b/flake8_idom_hooks/utils.py index ec2331a..14e501e 100644 --- a/flake8_idom_hooks/utils.py +++ b/flake8_idom_hooks/utils.py @@ -1,6 +1,6 @@ import ast from contextlib import contextmanager -from typing import List, Tuple, Iterator, Any +from typing import Any, Iterator, List, Tuple @contextmanager diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..77dfee3 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,45 @@ +from pathlib import Path + +from nox import Session, session + +ROOT = Path(".") +REQUIREMENTS_DIR = ROOT / "requirements" + + +@session +def test(session: Session) -> None: + session.notify("test_style") + session.notify("test_types") + session.notify("test_coverage") + session.notify("test_suite") + + +@session +def test_style(session: Session) -> None: + install_requirements(session, "style") + session.run("isort", "--check", ".") + session.run("flake8", ".") + + +@session +def test_types(session: Session) -> None: + install_requirements(session, "types") + session.run("mypy", "--strict", "flake8_idom_hooks") + + +@session +def test_suite(session: Session) -> None: + install_requirements(session, "test-env") + session.install(".") + session.run("pytest", "tests") + + +@session +def test_coverage(session: Session) -> None: + install_requirements(session, "test-env") + session.install("-e", ".") + session.run("pytest", "tests", "--cov=flake8_idom_hooks", "--cov-report=term") + + +def install_requirements(session: Session, name: str) -> None: + session.install("-r", str(REQUIREMENTS_DIR / f"{name}.txt")) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3c2aae9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.isort] +profile = "black" diff --git a/requirements.txt b/requirements.txt index eaed72c..6922360 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ --r requirements/dev.txt --r requirements/prod.txt --r requirements/test.txt --r requirements/lint.txt +-r requirements/nox-deps.txt +-r requirements/pkg-deps.txt +-r requirements/style.txt +-r requirements/test-env.txt +-r requirements/types.txt diff --git a/requirements/ci.txt b/requirements/ci.txt deleted file mode 100644 index bd5d03a..0000000 --- a/requirements/ci.txt +++ /dev/null @@ -1,3 +0,0 @@ -tox -tox-gh-actions -- dev.txt diff --git a/requirements/dev.txt b/requirements/dev.txt deleted file mode 100644 index 23932c6..0000000 --- a/requirements/dev.txt +++ /dev/null @@ -1,2 +0,0 @@ -tox -tox-wheel diff --git a/requirements/nox-deps.txt b/requirements/nox-deps.txt new file mode 100644 index 0000000..816817c --- /dev/null +++ b/requirements/nox-deps.txt @@ -0,0 +1 @@ +nox diff --git a/requirements/prod.txt b/requirements/pkg-deps.txt similarity index 68% rename from requirements/prod.txt rename to requirements/pkg-deps.txt index e4499d5..3edba2e 100644 --- a/requirements/prod.txt +++ b/requirements/pkg-deps.txt @@ -1 +1,2 @@ flake8 >=3.7 +black diff --git a/requirements/style.txt b/requirements/style.txt new file mode 100644 index 0000000..33afbed --- /dev/null +++ b/requirements/style.txt @@ -0,0 +1,4 @@ +flake8 >=3.7 +black +isort +flake8-tidy-imports diff --git a/requirements/test.txt b/requirements/test-env.txt similarity index 100% rename from requirements/test.txt rename to requirements/test-env.txt diff --git a/requirements/lint.txt b/requirements/types.txt similarity index 53% rename from requirements/lint.txt rename to requirements/types.txt index 6b8f0de..8d7fc1b 100644 --- a/requirements/lint.txt +++ b/requirements/types.txt @@ -1,4 +1,2 @@ -flake8 >=3.7 -black mypy types-setuptools diff --git a/setup.cfg b/setup.cfg index fc2e924..fc385a0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,10 +7,10 @@ warn_unused_ignores = True [flake8] ignore = E203, E266, E501, W503, F811, N802 max-line-length = 88 -max-complexity = 18 -exclude = - .eggs/* - .tox/* +extend-exclude = + .nox + venv + .venv tests/hook_usage_test_cases.py [coverage:report] @@ -26,4 +26,3 @@ exclude_lines = [tool:pytest] testpaths = tests xfail_strict = True -addopts = --cov=flake8_idom_hooks --cov-report term diff --git a/setup.py b/setup.py index 55f170d..24d7e78 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ import os + import setuptools # the name of the project @@ -46,7 +47,7 @@ requirements = [] -with open(os.path.join(here, "requirements", "prod.txt"), "r") as f: +with open(os.path.join(here, "requirements", "pkg-deps.txt"), "r") as f: for line in map(str.strip, f): if not line.startswith("#"): requirements.append(line) diff --git a/tests/test_flake8_idom_hooks.py b/tests/test_flake8_idom_hooks.py index bcdda1d..524b0ac 100644 --- a/tests/test_flake8_idom_hooks.py +++ b/tests/test_flake8_idom_hooks.py @@ -3,11 +3,14 @@ from flake8.options.manager import OptionManager -from flake8_idom_hooks import Plugin +import flake8_idom_hooks - -options_manager = OptionManager("test", "0.0.0") -Plugin.add_options(options_manager) +options_manager = OptionManager( + version="0.0.0", + plugin_versions=flake8_idom_hooks.__version__, + parents=[], +) +flake8_idom_hooks.Plugin.add_options(options_manager) def test_flake8_idom_hooks(): @@ -25,9 +28,11 @@ def test_flake8_idom_hooks(): lineno = index + 2 # use 2 since error should be on next line col_offset = len(line) - len(lstrip_line) message = line.replace("# error:", "", 1).strip() - expected_errors.add((lineno, col_offset, message, Plugin)) + expected_errors.add( + (lineno, col_offset, message, flake8_idom_hooks.Plugin) + ) - options, filenames = options_manager.parse_args(["--exhaustive-hook-deps"]) - Plugin.parse_options(options) + options = options_manager.parse_args(["--exhaustive-hook-deps"]) + flake8_idom_hooks.Plugin.parse_options(options) - assert set(Plugin(tree).run()) == expected_errors + assert set(flake8_idom_hooks.Plugin(tree).run()) == expected_errors