Skip to content

Commit

Permalink
Merge pull request #366 from nicoddemus/improve-pre-commit
Browse files Browse the repository at this point in the history
Add reorder-python-imports and autoflake hooks
  • Loading branch information
nicoddemus authored Nov 15, 2022
2 parents 38561d7 + 5d21bc9 commit 450b851
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 123 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ jobs:
"ubuntu-py311",
"ubuntu-pypy3",
"ubuntu-benchmark",

"linting",
"docs",
]

include:
Expand Down Expand Up @@ -87,14 +84,6 @@ jobs:
python: "3.8"
os: ubuntu-latest
tox_env: "benchmark"
- name: "linting"
python: "3.8"
os: ubuntu-latest
tox_env: "linting"
- name: "docs"
python: "3.8"
os: ubuntu-latest
tox_env: "docs"

steps:
- uses: actions/checkout@v3
Expand Down
57 changes: 35 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
- repo: https://github.com/PyCQA/autoflake
rev: v1.7.7
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
- id: autoflake
name: autoflake
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
language: python
files: \.py$
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.10.0]
- id: reorder-python-imports
args: ['--application-directories=.:src', --py37-plus]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: flake8
additional_dependencies: [flake8-typing-imports]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.990
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: mypy
files: ^(src/|testing/)
args: []
additional_dependencies: [pytest]
- id: rst-backticks
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==22.10.0]
- repo: local
hooks:
- id: rst
Expand All @@ -31,12 +46,10 @@ repos:
files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst|changelog/.*)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: rst-backticks
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.990
hooks:
- id: pyupgrade
args: [--py37-plus]
- id: mypy
files: ^(src/|testing/)
args: []
additional_dependencies: [pytest]
5 changes: 3 additions & 2 deletions docs/examples/eggsample/eggsample/host.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import itertools
import random

import pluggy
from eggsample import hookspecs
from eggsample import lib

from eggsample import hookspecs, lib
import pluggy

condiments_tray = {"pickled walnuts": 13, "steak sauce": 4, "mushy peas": 2}

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/eggsample/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from setuptools import setup, find_packages
from setuptools import find_packages
from setuptools import setup

setup(
name="eggsample",
Expand Down
6 changes: 4 additions & 2 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import sys
from subprocess import check_call

from colorama import init, Fore
from git import Repo, Remote
from colorama import Fore
from colorama import init
from git import Remote
from git import Repo


def create_branch(version):
Expand Down
11 changes: 9 additions & 2 deletions src/pluggy/_callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
Call loop machinery
"""
import sys
from typing import cast, Generator, List, Mapping, Sequence, Union
from typing import cast
from typing import Generator
from typing import List
from typing import Mapping
from typing import Sequence
from typing import TYPE_CHECKING
from typing import Union

from ._result import HookCallError, _Result, _raise_wrapfail
from ._result import _raise_wrapfail
from ._result import _Result
from ._result import HookCallError

if TYPE_CHECKING:
from ._hooks import HookImpl
Expand Down
28 changes: 13 additions & 15 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
import sys
import warnings
from types import ModuleType
from typing import (
AbstractSet,
Any,
Callable,
Generator,
List,
Mapping,
Optional,
overload,
Sequence,
Tuple,
TypeVar,
TYPE_CHECKING,
Union,
)
from typing import AbstractSet
from typing import Any
from typing import Callable
from typing import Generator
from typing import List
from typing import Mapping
from typing import Optional
from typing import overload
from typing import Sequence
from typing import Tuple
from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union

from ._result import _Result

Expand Down
50 changes: 23 additions & 27 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@
import sys
import types
import warnings
from typing import (
Any,
Callable,
cast,
Dict,
Iterable,
List,
Mapping,
Optional,
Sequence,
Set,
Tuple,
TYPE_CHECKING,
Union,
)
from typing import Any
from typing import Callable
from typing import cast
from typing import Dict
from typing import Iterable
from typing import List
from typing import Mapping
from typing import Optional
from typing import Sequence
from typing import Set
from typing import Tuple
from typing import TYPE_CHECKING
from typing import Union

from . import _tracing
from ._result import _Result
from ._callers import _multicall
from ._hooks import (
HookImpl,
HookSpec,
_HookCaller,
_SubsetHookCaller,
_HookImplFunction,
_HookRelay,
_Namespace,
normalize_hookimpl_opts,
_Plugin,
)
from ._hooks import _HookCaller
from ._hooks import _HookImplFunction
from ._hooks import _HookRelay
from ._hooks import _Namespace
from ._hooks import _Plugin
from ._hooks import _SubsetHookCaller
from ._hooks import HookImpl
from ._hooks import HookSpec
from ._hooks import normalize_hookimpl_opts
from ._result import _Result

if sys.version_info >= (3, 8):
from importlib import metadata as importlib_metadata
Expand Down
20 changes: 9 additions & 11 deletions src/pluggy/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
"""
import sys
from types import TracebackType
from typing import (
Callable,
cast,
Generator,
Generic,
Optional,
Tuple,
Type,
TYPE_CHECKING,
TypeVar,
)
from typing import Callable
from typing import cast
from typing import Generator
from typing import Generic
from typing import Optional
from typing import Tuple
from typing import Type
from typing import TYPE_CHECKING
from typing import TypeVar

if TYPE_CHECKING:
from typing import NoReturn
Expand Down
7 changes: 5 additions & 2 deletions testing/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
Benchmarking and performance tests.
"""
import pytest
from pluggy import HookspecMarker, HookimplMarker, PluginManager
from pluggy._hooks import HookImpl

from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluginManager
from pluggy._callers import _multicall
from pluggy._hooks import HookImpl


hookspec = HookspecMarker("example")
Expand Down
4 changes: 3 additions & 1 deletion testing/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from pluggy import HookspecMarker, PluginManager

from pluggy import HookspecMarker
from pluggy import PluginManager


@pytest.fixture(
Expand Down
5 changes: 4 additions & 1 deletion testing/test_details.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest
from pluggy import PluginManager, HookimplMarker, HookspecMarker

from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluginManager

hookspec = HookspecMarker("example")
hookimpl = HookimplMarker("example")
Expand Down
6 changes: 5 additions & 1 deletion testing/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from functools import wraps
from typing import Any, Callable, TypeVar, cast
from typing import Any
from typing import Callable
from typing import cast
from typing import TypeVar

from pluggy._hooks import varnames
from pluggy._manager import _formatdef

Expand Down
14 changes: 11 additions & 3 deletions testing/test_hookcaller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from typing import Callable, List, Sequence, TypeVar
from typing import Callable
from typing import List
from typing import Sequence
from typing import TypeVar

import pytest
from pluggy import HookimplMarker, HookspecMarker, PluginManager, PluginValidationError
from pluggy._hooks import HookImpl, _HookCaller

from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluginManager
from pluggy import PluginValidationError
from pluggy._hooks import _HookCaller
from pluggy._hooks import HookImpl

hookspec = HookspecMarker("example")
hookimpl = HookimplMarker("example")
Expand Down
6 changes: 5 additions & 1 deletion testing/test_invocations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest
from pluggy import PluginManager, PluginValidationError, HookimplMarker, HookspecMarker

from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluginManager
from pluggy import PluginValidationError


hookspec = HookspecMarker("example")
Expand Down
14 changes: 11 additions & 3 deletions testing/test_multicall.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from typing import Callable, Mapping, List, Sequence, Type, Union
from typing import Callable
from typing import List
from typing import Mapping
from typing import Sequence
from typing import Type
from typing import Union

import pytest
from pluggy import HookCallError, HookspecMarker, HookimplMarker
from pluggy._hooks import HookImpl

from pluggy import HookCallError
from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy._callers import _multicall
from pluggy._hooks import HookImpl


hookspec = HookspecMarker("example")
Expand Down
Loading

0 comments on commit 450b851

Please sign in to comment.