From 034b5385a5bcdaaf66c5902e9c634480ab306a41 Mon Sep 17 00:00:00 2001 From: Dan <3498629+dan98765@users.noreply.github.com> Date: Mon, 28 May 2018 11:18:54 -0700 Subject: [PATCH] Add isort precommit hook & run on all files (#743) * Add isort and seed-isort-config pre-commit hook * Fix erroneous isort moving comment to the top of file --- .editorconfig | 1 - .isort.cfg | 2 ++ .pre-commit-config.yaml | 11 ++++++++++- UPGRADE-v2.0.md | 10 +++++----- docs/conf.py | 2 +- docs/execution/dataloader.rst | 2 +- docs/relay/mutations.rst | 2 +- docs/testing/index.rst | 2 +- examples/starwars/tests/snapshots/snap_test_query.py | 1 - .../tests/snapshots/snap_test_connections.py | 1 - .../tests/snapshots/snap_test_mutation.py | 1 - .../tests/snapshots/snap_test_objectidentification.py | 1 - graphene/pyutils/compat.py | 1 + graphene/pyutils/signature.py | 4 ++-- graphene/relay/tests/test_connection.py | 3 ++- graphene/relay/tests/test_mutation.py | 1 - graphene/tests/issues/test_425.py | 5 +++-- graphene/types/abstracttype.py | 2 +- graphene/types/datetime.py | 2 +- graphene/types/enum.py | 3 +-- graphene/types/generic.py | 3 ++- graphene/types/mutation.py | 3 +-- graphene/types/scalars.py | 1 - graphene/types/schema.py | 2 +- graphene/types/tests/test_abstracttype.py | 6 +++--- graphene/types/tests/test_base.py | 2 +- graphene/types/tests/test_datetime.py | 3 +-- graphene/types/tests/test_dynamic.py | 1 + graphene/types/tests/test_enum.py | 2 +- graphene/types/tests/test_inputobjecttype.py | 4 ++-- graphene/types/tests/test_objecttype.py | 4 ++-- graphene/types/tests/test_query.py | 6 +++--- graphene/types/tests/test_typemap.py | 5 ++--- graphene/types/tests/test_uuid.py | 2 +- graphene/types/union.py | 1 - graphene/utils/annotate.py | 2 +- graphene/utils/resolve_only_args.py | 1 + graphene/utils/subclass_with_meta.py | 3 ++- graphene/utils/tests/test_annotate.py | 1 + graphene/utils/tests/test_deprecated.py | 4 +++- graphene/utils/tests/test_resolve_only_args.py | 2 +- setup.py | 7 ++++--- 42 files changed, 66 insertions(+), 56 deletions(-) create mode 100644 .isort.cfg diff --git a/.editorconfig b/.editorconfig index 5ebeb47b..568b3971 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,4 +11,3 @@ trim_trailing_whitespace = true [*.{py,rst,ini}] indent_style = space indent_size = 4 - diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..d4ed37be --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +known_third_party = aniso8601,graphql,graphql_relay,promise,pytest,pytz,pyutils,setuptools,six,snapshottest,sphinx_graphene_theme diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b6bb6ee3..085f7fa9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,6 @@ +repos: - repo: git://github.com/pre-commit/pre-commit-hooks - sha: v0.8.0 + rev: v1.2.3 hooks: - id: autopep8-wrapper args: @@ -15,3 +16,11 @@ - id: pretty-format-json args: - --autofix +- repo: https://github.com/asottile/seed-isort-config + rev: v1.0.0 + hooks: + - id: seed-isort-config +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.4 + hooks: + - id: isort diff --git a/UPGRADE-v2.0.md b/UPGRADE-v2.0.md index 96aac143..5dc76154 100644 --- a/UPGRADE-v2.0.md +++ b/UPGRADE-v2.0.md @@ -207,7 +207,7 @@ Before: ```python class SomeMutation(Mutation): ... - + @classmethod def mutate(cls, instance, args, context, info): ... @@ -218,7 +218,7 @@ With 2.0: ```python class SomeMutation(Mutation): ... - + def mutate(self, info, **args): ... ``` @@ -231,7 +231,7 @@ class SomeMutation(Mutation): first_name = String(required=True) last_name = String(required=True) ... - + def mutate(self, info, first_name, last_name): ... ``` @@ -250,7 +250,7 @@ If you are using Middelwares, you need to some adjustments: Before: ```python -class MyGrapheneMiddleware(object): +class MyGrapheneMiddleware(object): def resolve(self, next_mw, root, args, context, info): ## Middleware code @@ -261,7 +261,7 @@ class MyGrapheneMiddleware(object): With 2.0: ```python -class MyGrapheneMiddleware(object): +class MyGrapheneMiddleware(object): def resolve(self, next_mw, root, info, **args): context = info.context diff --git a/docs/conf.py b/docs/conf.py index 9d902f9a..ccb5305d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,5 @@ import os +import sphinx_graphene_theme on_rtd = os.environ.get('READTHEDOCS', None) == 'True' @@ -136,7 +137,6 @@ todo_include_todos = True # html_theme = 'alabaster' # if on_rtd: # html_theme = 'sphinx_rtd_theme' -import sphinx_graphene_theme html_theme = "sphinx_graphene_theme" diff --git a/docs/execution/dataloader.rst b/docs/execution/dataloader.rst index 3322acfd..522af161 100644 --- a/docs/execution/dataloader.rst +++ b/docs/execution/dataloader.rst @@ -88,7 +88,7 @@ Naively, if ``me``, ``bestFriend`` and ``friends`` each need to request the back there could be at most 13 database requests! -When using DataLoader, we could define the User type using our previous example with +When using DataLoader, we could define the User type using our previous example with leaner code and at most 4 database requests, and possibly fewer if there are cache hits. diff --git a/docs/relay/mutations.rst b/docs/relay/mutations.rst index d273c137..c6099594 100644 --- a/docs/relay/mutations.rst +++ b/docs/relay/mutations.rst @@ -41,7 +41,7 @@ Mutations can also accept files, that's how it will work with different integrat class Input: pass # nothing needed for uploading file - + # your return fields success = graphene.String() diff --git a/docs/testing/index.rst b/docs/testing/index.rst index 516f0e8d..0263a9aa 100644 --- a/docs/testing/index.rst +++ b/docs/testing/index.rst @@ -101,7 +101,7 @@ Here is a simple example on how our tests will look if we use ``pytest``: If we are using ``unittest``: .. code:: python - + from snapshottest import TestCase class APITestCase(TestCase): diff --git a/examples/starwars/tests/snapshots/snap_test_query.py b/examples/starwars/tests/snapshots/snap_test_query.py index 9314420b..51e7b37f 100644 --- a/examples/starwars/tests/snapshots/snap_test_query.py +++ b/examples/starwars/tests/snapshots/snap_test_query.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals from snapshottest import Snapshot - snapshots = Snapshot() snapshots['test_hero_name_query 1'] = { diff --git a/examples/starwars_relay/tests/snapshots/snap_test_connections.py b/examples/starwars_relay/tests/snapshots/snap_test_connections.py index cbf14d95..d2dff773 100644 --- a/examples/starwars_relay/tests/snapshots/snap_test_connections.py +++ b/examples/starwars_relay/tests/snapshots/snap_test_connections.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals from snapshottest import Snapshot - snapshots = Snapshot() snapshots['test_correct_fetch_first_ship_rebels 1'] = { diff --git a/examples/starwars_relay/tests/snapshots/snap_test_mutation.py b/examples/starwars_relay/tests/snapshots/snap_test_mutation.py index 27c3f9bb..8fff150b 100644 --- a/examples/starwars_relay/tests/snapshots/snap_test_mutation.py +++ b/examples/starwars_relay/tests/snapshots/snap_test_mutation.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals from snapshottest import Snapshot - snapshots = Snapshot() snapshots['test_mutations 1'] = { diff --git a/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py b/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py index a15d49d3..1682f2de 100644 --- a/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py +++ b/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals from snapshottest import Snapshot - snapshots = Snapshot() snapshots['test_correctly_fetches_id_name_rebels 1'] = { diff --git a/graphene/pyutils/compat.py b/graphene/pyutils/compat.py index 86452081..ef27f356 100644 --- a/graphene/pyutils/compat.py +++ b/graphene/pyutils/compat.py @@ -1,4 +1,5 @@ from __future__ import absolute_import + import six try: diff --git a/graphene/pyutils/signature.py b/graphene/pyutils/signature.py index 9d94a6ef..5ad6346c 100644 --- a/graphene/pyutils/signature.py +++ b/graphene/pyutils/signature.py @@ -4,11 +4,11 @@ Back port of Python 3.3's function signature tools from the inspect module, modified to be compatible with Python 2.7 and 3.2+. """ from __future__ import absolute_import, division, print_function -import itertools + import functools +import itertools import re import types - from collections import OrderedDict __version__ = "0.4" diff --git a/graphene/relay/tests/test_connection.py b/graphene/relay/tests/test_connection.py index c206f714..28dd929f 100644 --- a/graphene/relay/tests/test_connection.py +++ b/graphene/relay/tests/test_connection.py @@ -1,6 +1,7 @@ import pytest -from ...types import Argument, Field, Int, List, NonNull, ObjectType, String, Schema +from ...types import (Argument, Field, Int, List, NonNull, ObjectType, Schema, + String) from ..connection import Connection, ConnectionField, PageInfo from ..node import Node diff --git a/graphene/relay/tests/test_mutation.py b/graphene/relay/tests/test_mutation.py index aa5ce179..a830ffbe 100644 --- a/graphene/relay/tests/test_mutation.py +++ b/graphene/relay/tests/test_mutation.py @@ -1,5 +1,4 @@ import pytest - from promise import Promise from ...types import (ID, Argument, Field, InputField, InputObjectType, diff --git a/graphene/tests/issues/test_425.py b/graphene/tests/issues/test_425.py index d50edf84..cc77e730 100644 --- a/graphene/tests/issues/test_425.py +++ b/graphene/tests/issues/test_425.py @@ -1,9 +1,10 @@ # https://github.com/graphql-python/graphene/issues/425 # Adapted for Graphene 2.0 -from graphene.types.objecttype import ObjectType, ObjectTypeOptions -from graphene.types.inputobjecttype import InputObjectType, InputObjectTypeOptions from graphene.types.enum import Enum, EnumOptions +from graphene.types.inputobjecttype import (InputObjectType, + InputObjectTypeOptions) +from graphene.types.objecttype import ObjectType, ObjectTypeOptions # ObjectType diff --git a/graphene/types/abstracttype.py b/graphene/types/abstracttype.py index aaa0ff37..9d84d819 100644 --- a/graphene/types/abstracttype.py +++ b/graphene/types/abstracttype.py @@ -1,5 +1,5 @@ -from ..utils.subclass_with_meta import SubclassWithMeta from ..utils.deprecated import warn_deprecation +from ..utils.subclass_with_meta import SubclassWithMeta class AbstractType(SubclassWithMeta): diff --git a/graphene/types/datetime.py b/graphene/types/datetime.py index b750ea01..bdf45f55 100644 --- a/graphene/types/datetime.py +++ b/graphene/types/datetime.py @@ -2,8 +2,8 @@ from __future__ import absolute_import import datetime +from aniso8601 import parse_date, parse_datetime, parse_time from graphql.language import ast -from aniso8601 import parse_datetime, parse_date, parse_time from .scalars import Scalar diff --git a/graphene/types/enum.py b/graphene/types/enum.py index 67a3f6b2..4f571214 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -4,11 +4,10 @@ import six from graphene.utils.subclass_with_meta import SubclassWithMeta_Meta +from ..pyutils.compat import Enum as PyEnum from .base import BaseOptions, BaseType from .unmountedtype import UnmountedType -from ..pyutils.compat import Enum as PyEnum - def eq_enum(self, other): if isinstance(other, self.__class__): diff --git a/graphene/types/generic.py b/graphene/types/generic.py index 3170e38d..b2b15f00 100644 --- a/graphene/types/generic.py +++ b/graphene/types/generic.py @@ -1,9 +1,10 @@ from __future__ import unicode_literals -from graphene.types.scalars import MAX_INT, MIN_INT from graphql.language.ast import (BooleanValue, FloatValue, IntValue, ListValue, ObjectValue, StringValue) +from graphene.types.scalars import MAX_INT, MIN_INT + from .scalars import Scalar diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index 6b864e07..fdfd5515 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -1,12 +1,11 @@ from collections import OrderedDict +from ..utils.deprecated import warn_deprecation from ..utils.get_unbound_function import get_unbound_function from ..utils.props import props from .field import Field from .objecttype import ObjectType, ObjectTypeOptions from .utils import yank_fields_from_attrs -from ..utils.deprecated import warn_deprecation - # For static type checking with Mypy MYPY = False diff --git a/graphene/types/scalars.py b/graphene/types/scalars.py index 3b78185d..e34d7a10 100644 --- a/graphene/types/scalars.py +++ b/graphene/types/scalars.py @@ -1,5 +1,4 @@ import six - from graphql.language.ast import (BooleanValue, FloatValue, IntValue, StringValue) diff --git a/graphene/types/schema.py b/graphene/types/schema.py index 7fd513b2..72bae81f 100644 --- a/graphene/types/schema.py +++ b/graphene/types/schema.py @@ -1,6 +1,6 @@ import inspect -from graphql import GraphQLSchema, graphql, is_type, GraphQLObjectType +from graphql import GraphQLObjectType, GraphQLSchema, graphql, is_type from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective, GraphQLSkipDirective) from graphql.type.introspection import IntrospectionSchema diff --git a/graphene/types/tests/test_abstracttype.py b/graphene/types/tests/test_abstracttype.py index 6484deb8..73144bec 100644 --- a/graphene/types/tests/test_abstracttype.py +++ b/graphene/types/tests/test_abstracttype.py @@ -1,10 +1,10 @@ import pytest +from .. import abstracttype +from ..abstracttype import AbstractType +from ..field import Field from ..objecttype import ObjectType from ..unmountedtype import UnmountedType -from ..abstracttype import AbstractType -from .. import abstracttype -from ..field import Field class MyType(ObjectType): diff --git a/graphene/types/tests/test_base.py b/graphene/types/tests/test_base.py index 18ba6774..6399f69d 100644 --- a/graphene/types/tests/test_base.py +++ b/graphene/types/tests/test_base.py @@ -1,6 +1,6 @@ import pytest -from ..base import BaseType, BaseOptions +from ..base import BaseOptions, BaseType class CustomOptions(BaseOptions): diff --git a/graphene/types/tests/test_datetime.py b/graphene/types/tests/test_datetime.py index 2d79d9f7..80c1d3c1 100644 --- a/graphene/types/tests/test_datetime.py +++ b/graphene/types/tests/test_datetime.py @@ -1,10 +1,9 @@ import datetime import pytz - from graphql import GraphQLError -from ..datetime import DateTime, Date, Time +from ..datetime import Date, DateTime, Time from ..objecttype import ObjectType from ..schema import Schema diff --git a/graphene/types/tests/test_dynamic.py b/graphene/types/tests/test_dynamic.py index b31ccf4b..5e4dfca8 100644 --- a/graphene/types/tests/test_dynamic.py +++ b/graphene/types/tests/test_dynamic.py @@ -1,4 +1,5 @@ from functools import partial + from ..dynamic import Dynamic from ..scalars import String from ..structures import List, NonNull diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index fdd5f4e4..d35d555f 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -1,10 +1,10 @@ import six -from ..schema import Schema, ObjectType from ..argument import Argument from ..enum import Enum, PyEnum from ..field import Field from ..inputfield import InputField +from ..schema import ObjectType, Schema def test_enum_construction(): diff --git a/graphene/types/tests/test_inputobjecttype.py b/graphene/types/tests/test_inputobjecttype.py index 9f90055d..8d6ed904 100644 --- a/graphene/types/tests/test_inputobjecttype.py +++ b/graphene/types/tests/test_inputobjecttype.py @@ -4,9 +4,9 @@ from ..field import Field from ..inputfield import InputField from ..inputobjecttype import InputObjectType from ..objecttype import ObjectType -from ..unmountedtype import UnmountedType -from ..scalars import String, Boolean +from ..scalars import Boolean, String from ..schema import Schema +from ..unmountedtype import UnmountedType class MyType(object): diff --git a/graphene/types/tests/test_objecttype.py b/graphene/types/tests/test_objecttype.py index 73d3823c..766f62fe 100644 --- a/graphene/types/tests/test_objecttype.py +++ b/graphene/types/tests/test_objecttype.py @@ -3,10 +3,10 @@ import pytest from ..field import Field from ..interface import Interface from ..objecttype import ObjectType -from ..unmountedtype import UnmountedType -from ..structures import NonNull from ..scalars import String from ..schema import Schema +from ..structures import NonNull +from ..unmountedtype import UnmountedType class MyType(Interface): diff --git a/graphene/types/tests/test_query.py b/graphene/types/tests/test_query.py index a106af25..c4133970 100644 --- a/graphene/types/tests/test_query.py +++ b/graphene/types/tests/test_query.py @@ -1,19 +1,19 @@ import json from functools import partial -from graphql import GraphQLError, Source, execute, parse, ResolveInfo +from graphql import GraphQLError, ResolveInfo, Source, execute, parse +from ..context import Context from ..dynamic import Dynamic from ..field import Field from ..inputfield import InputField from ..inputobjecttype import InputObjectType from ..interface import Interface from ..objecttype import ObjectType -from ..scalars import Int, String, Boolean +from ..scalars import Boolean, Int, String from ..schema import Schema from ..structures import List, NonNull from ..union import Union -from ..context import Context def test_query(): diff --git a/graphene/types/tests/test_typemap.py b/graphene/types/tests/test_typemap.py index c0626a1a..94af960c 100644 --- a/graphene/types/tests/test_typemap.py +++ b/graphene/types/tests/test_typemap.py @@ -1,11 +1,9 @@ import pytest - from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue, GraphQLField, GraphQLInputObjectField, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLString) -from ..structures import List, NonNull from ..dynamic import Dynamic from ..enum import Enum from ..field import Field @@ -13,7 +11,8 @@ from ..inputfield import InputField from ..inputobjecttype import InputObjectType from ..interface import Interface from ..objecttype import ObjectType -from ..scalars import String, Int +from ..scalars import Int, String +from ..structures import List, NonNull from ..typemap import TypeMap, resolve_type diff --git a/graphene/types/tests/test_uuid.py b/graphene/types/tests/test_uuid.py index f1499e35..188ebcb8 100644 --- a/graphene/types/tests/test_uuid.py +++ b/graphene/types/tests/test_uuid.py @@ -1,6 +1,6 @@ -from ..uuid import UUID from ..objecttype import ObjectType from ..schema import Schema +from ..uuid import UUID class Query(ObjectType): diff --git a/graphene/types/union.py b/graphene/types/union.py index c5925e88..45e03b0c 100644 --- a/graphene/types/union.py +++ b/graphene/types/union.py @@ -1,7 +1,6 @@ from .base import BaseOptions, BaseType from .unmountedtype import UnmountedType - # For static type checking with Mypy MYPY = False if MYPY: diff --git a/graphene/utils/annotate.py b/graphene/utils/annotate.py index 51a87a78..9abb8e06 100644 --- a/graphene/utils/annotate.py +++ b/graphene/utils/annotate.py @@ -1,6 +1,6 @@ import six -from ..pyutils.compat import signature, func_name +from ..pyutils.compat import func_name, signature from .deprecated import warn_deprecation diff --git a/graphene/utils/resolve_only_args.py b/graphene/utils/resolve_only_args.py index 897e6223..7862dedd 100644 --- a/graphene/utils/resolve_only_args.py +++ b/graphene/utils/resolve_only_args.py @@ -1,4 +1,5 @@ from functools import wraps + from .deprecated import deprecated diff --git a/graphene/utils/subclass_with_meta.py b/graphene/utils/subclass_with_meta.py index 61205be0..b0c8dee2 100644 --- a/graphene/utils/subclass_with_meta.py +++ b/graphene/utils/subclass_with_meta.py @@ -1,6 +1,7 @@ -import six from inspect import isclass +import six + from ..pyutils.init_subclass import InitSubclassMeta from .props import props diff --git a/graphene/utils/tests/test_annotate.py b/graphene/utils/tests/test_annotate.py index e4930b62..446fbbfe 100644 --- a/graphene/utils/tests/test_annotate.py +++ b/graphene/utils/tests/test_annotate.py @@ -1,4 +1,5 @@ import pytest + from ..annotate import annotate diff --git a/graphene/utils/tests/test_deprecated.py b/graphene/utils/tests/test_deprecated.py index cd0e2dcb..0af06763 100644 --- a/graphene/utils/tests/test_deprecated.py +++ b/graphene/utils/tests/test_deprecated.py @@ -1,6 +1,8 @@ import pytest + from .. import deprecated -from ..deprecated import deprecated as deprecated_decorator, warn_deprecation +from ..deprecated import deprecated as deprecated_decorator +from ..deprecated import warn_deprecation def test_warn_deprecation(mocker): diff --git a/graphene/utils/tests/test_resolve_only_args.py b/graphene/utils/tests/test_resolve_only_args.py index 35554e9b..11a6bbdb 100644 --- a/graphene/utils/tests/test_resolve_only_args.py +++ b/graphene/utils/tests/test_resolve_only_args.py @@ -1,5 +1,5 @@ -from ..resolve_only_args import resolve_only_args from .. import deprecated +from ..resolve_only_args import resolve_only_args def test_resolve_only_args(mocker): diff --git a/setup.py b/setup.py index 102f46c4..f84bfc2d 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ -from setuptools import find_packages, setup -from setuptools.command.test import test as TestCommand -import sys import ast import re +import sys + +from setuptools import find_packages, setup +from setuptools.command.test import test as TestCommand _version_re = re.compile(r'VERSION\s+=\s+(.*)')