diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f9da16d5..136f8e7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,3 +15,11 @@ repos: rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7 hooks: - id: flake8 +- repo: git://github.com/asottile/seed-isort-config + rev: v1.7.0 + hooks: + - id: seed-isort-config +- repo: git://github.com/pre-commit/mirrors-isort + rev: v4.3.4 + hooks: + - id: isort diff --git a/docs/conf.py b/docs/conf.py index d729246a..3fa6391d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -136,7 +136,7 @@ # html_theme = 'alabaster' # if on_rtd: # html_theme = 'sphinx_rtd_theme' -import sphinx_graphene_theme +import sphinx_graphene_theme # isort:skip html_theme = "sphinx_graphene_theme" diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 26f0cb2b..bc5ee62d 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -93,7 +93,7 @@ Create ``flask_sqlalchemy/schema.py`` and type the following: import graphene from graphene import relay from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField - from models import db_session, Department as DepartmentModel, Employee as EmployeeModel + from .models import db_session, Department as DepartmentModel, Employee as EmployeeModel class Department(SQLAlchemyObjectType): @@ -146,8 +146,8 @@ installed makes this task quite easy. from flask import Flask from flask_graphql import GraphQLView - from models import db_session - from schema import schema, Department + from .models import db_session + from .schema import schema, Department app = Flask(__name__) app.debug = True @@ -175,7 +175,7 @@ Creating some data $ python - >>> from models import engine, db_session, Base, Department, Employee + >>> from .models import engine, db_session, Base, Department, Employee >>> Base.metadata.create_all(bind=engine) >>> # Fill the tables with some data diff --git a/examples/flask_sqlalchemy/app.py b/examples/flask_sqlalchemy/app.py index 64390aa6..a4d3f29e 100755 --- a/examples/flask_sqlalchemy/app.py +++ b/examples/flask_sqlalchemy/app.py @@ -2,9 +2,10 @@ from flask import Flask -from database import db_session, init_db from flask_graphql import GraphQLView -from schema import schema + +from .database import db_session, init_db +from .schema import schema app = Flask(__name__) app.debug = True diff --git a/examples/flask_sqlalchemy/database.py b/examples/flask_sqlalchemy/database.py index ca4d4122..01e76ca6 100644 --- a/examples/flask_sqlalchemy/database.py +++ b/examples/flask_sqlalchemy/database.py @@ -14,7 +14,7 @@ def init_db(): # import all modules here that might define models so that # they will be registered properly on the metadata. Otherwise # you will have to import them first before calling init_db() - from models import Department, Employee, Role + from .models import Department, Employee, Role Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine) diff --git a/examples/flask_sqlalchemy/models.py b/examples/flask_sqlalchemy/models.py index 119aca02..e164c015 100644 --- a/examples/flask_sqlalchemy/models.py +++ b/examples/flask_sqlalchemy/models.py @@ -1,7 +1,7 @@ from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func from sqlalchemy.orm import backref, relationship -from database import Base +from .database import Base class Department(Base): diff --git a/examples/flask_sqlalchemy/schema.py b/examples/flask_sqlalchemy/schema.py index 434a9db2..cbee081c 100644 --- a/examples/flask_sqlalchemy/schema.py +++ b/examples/flask_sqlalchemy/schema.py @@ -1,9 +1,11 @@ import graphene from graphene import relay -from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType, utils -from models import Department as DepartmentModel -from models import Employee as EmployeeModel -from models import Role as RoleModel +from graphene_sqlalchemy import (SQLAlchemyConnectionField, + SQLAlchemyObjectType, utils) + +from .models import Department as DepartmentModel +from .models import Employee as EmployeeModel +from .models import Role as RoleModel class Department(SQLAlchemyObjectType): diff --git a/examples/nameko_sqlalchemy/app.py b/examples/nameko_sqlalchemy/app.py index 18302ce6..42a40a0c 100755 --- a/examples/nameko_sqlalchemy/app.py +++ b/examples/nameko_sqlalchemy/app.py @@ -1,8 +1,9 @@ -from database import db_session, init_db -from schema import schema - from graphql_server import (HttpQueryError, default_format_error, - encode_execution_results, json_encode,load_json_body, run_http_query) + encode_execution_results, json_encode, + load_json_body, run_http_query) + +from .database import db_session, init_db +from .schema import schema class App(): diff --git a/examples/nameko_sqlalchemy/database.py b/examples/nameko_sqlalchemy/database.py index ca4d4122..01e76ca6 100644 --- a/examples/nameko_sqlalchemy/database.py +++ b/examples/nameko_sqlalchemy/database.py @@ -14,7 +14,7 @@ def init_db(): # import all modules here that might define models so that # they will be registered properly on the metadata. Otherwise # you will have to import them first before calling init_db() - from models import Department, Employee, Role + from .models import Department, Employee, Role Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine) diff --git a/examples/nameko_sqlalchemy/models.py b/examples/nameko_sqlalchemy/models.py index 119aca02..e164c015 100644 --- a/examples/nameko_sqlalchemy/models.py +++ b/examples/nameko_sqlalchemy/models.py @@ -1,7 +1,7 @@ from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func from sqlalchemy.orm import backref, relationship -from database import Base +from .database import Base class Department(Base): diff --git a/examples/nameko_sqlalchemy/schema.py b/examples/nameko_sqlalchemy/schema.py index 5d9d3b72..fa747350 100644 --- a/examples/nameko_sqlalchemy/schema.py +++ b/examples/nameko_sqlalchemy/schema.py @@ -1,9 +1,10 @@ import graphene from graphene import relay from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType -from models import Department as DepartmentModel -from models import Employee as EmployeeModel -from models import Role as RoleModel + +from .models import Department as DepartmentModel +from .models import Employee as EmployeeModel +from .models import Role as RoleModel class Department(SQLAlchemyObjectType): diff --git a/examples/nameko_sqlalchemy/service.py b/examples/nameko_sqlalchemy/service.py index d83ab861..98157508 100644 --- a/examples/nameko_sqlalchemy/service.py +++ b/examples/nameko_sqlalchemy/service.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from nameko.web.handlers import http -from app import App + +from .app import App class DepartmentService: diff --git a/graphene_sqlalchemy/__init__.py b/graphene_sqlalchemy/__init__.py index 810150f0..eee98090 100644 --- a/graphene_sqlalchemy/__init__.py +++ b/graphene_sqlalchemy/__init__.py @@ -2,7 +2,7 @@ from .fields import SQLAlchemyConnectionField from .utils import get_query, get_session -__version__ = "2.1.0" +__version__ = "2.1.1" __all__ = [ "__version__", diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 72089613..053aa8b5 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -3,7 +3,8 @@ from sqlalchemy.dialects import postgresql from sqlalchemy.orm import interfaces -from graphene import ID, Boolean, Dynamic, Enum, Field, Float, Int, List, String +from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List, + String) from graphene.types.json import JSONString from .fields import createConnectionField diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index bf3522b4..7e313625 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -1,5 +1,6 @@ from functools import partial -from promise import is_thenable, Promise + +from promise import Promise, is_thenable from sqlalchemy.orm.query import Query from graphene.relay import Connection, ConnectionField diff --git a/graphene_sqlalchemy/tests/test_connectionfactory.py b/graphene_sqlalchemy/tests/test_connectionfactory.py index 8ed3190e..796be5a4 100644 --- a/graphene_sqlalchemy/tests/test_connectionfactory.py +++ b/graphene_sqlalchemy/tests/test_connectionfactory.py @@ -1,9 +1,7 @@ -from graphene_sqlalchemy.fields import ( - SQLAlchemyConnectionField, - registerConnectionFieldFactory, - unregisterConnectionFieldFactory, -) import graphene +from graphene_sqlalchemy.fields import (SQLAlchemyConnectionField, + registerConnectionFieldFactory, + unregisterConnectionFieldFactory) def test_register(): diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index c6c49bba..d205427b 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -1,10 +1,10 @@ import enum from py.test import raises -from sqlalchemy import Column, Table, case, types, select, func +from sqlalchemy import Column, Table, case, func, select, types from sqlalchemy.dialects import postgresql from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import composite, column_property +from sqlalchemy.orm import column_property, composite from sqlalchemy.sql.elements import Label from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType @@ -13,11 +13,9 @@ from graphene.types.datetime import DateTime from graphene.types.json import JSONString -from ..converter import ( - convert_sqlalchemy_column, - convert_sqlalchemy_composite, - convert_sqlalchemy_relationship, -) +from ..converter import (convert_sqlalchemy_column, + convert_sqlalchemy_composite, + convert_sqlalchemy_relationship) from ..fields import UnsortedSQLAlchemyConnectionField from ..registry import Registry from ..types import SQLAlchemyObjectType diff --git a/graphene_sqlalchemy/tests/test_fields.py b/graphene_sqlalchemy/tests/test_fields.py index 33ec442c..ff616b30 100644 --- a/graphene_sqlalchemy/tests/test_fields.py +++ b/graphene_sqlalchemy/tests/test_fields.py @@ -1,10 +1,12 @@ -from graphene.relay import Connection import pytest +from graphene.relay import Connection + from ..fields import SQLAlchemyConnectionField from ..types import SQLAlchemyObjectType from ..utils import sort_argument_for_model -from .models import Pet as PetModel, Editor +from .models import Editor +from .models import Pet as PetModel class Pet(SQLAlchemyObjectType): diff --git a/graphene_sqlalchemy/tests/test_query.py b/graphene_sqlalchemy/tests/test_query.py index 8bb4891c..146c54e6 100644 --- a/graphene_sqlalchemy/tests/test_query.py +++ b/graphene_sqlalchemy/tests/test_query.py @@ -5,11 +5,11 @@ import graphene from graphene.relay import Connection, Node -from ..registry import reset_global_registry from ..fields import SQLAlchemyConnectionField +from ..registry import reset_global_registry from ..types import SQLAlchemyObjectType from ..utils import sort_argument_for_model, sort_enum_for_model -from .models import Article, Base, Editor, Pet, Reporter, Hairkind +from .models import Article, Base, Editor, Hairkind, Pet, Reporter db = create_engine("sqlite:///test_sqlalchemy.sqlite3") diff --git a/graphene_sqlalchemy/tests/test_registry.py b/graphene_sqlalchemy/tests/test_registry.py index 8894314d..1945af6d 100644 --- a/graphene_sqlalchemy/tests/test_registry.py +++ b/graphene_sqlalchemy/tests/test_registry.py @@ -1,8 +1,8 @@ import pytest -from .models import Pet from ..registry import Registry from ..types import SQLAlchemyObjectType +from .models import Pet def test_register_incorrect_objecttype(): diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index b6dce726..5eaf0137 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -1,13 +1,15 @@ from collections import OrderedDict -from graphene import Field, Int, Interface, ObjectType -from graphene.relay import Node, is_node, Connection + import six # noqa F401 from promise import Promise +from graphene import Field, Int, Interface, ObjectType +from graphene.relay import Connection, Node, is_node + +from ..fields import SQLAlchemyConnectionField from ..registry import Registry from ..types import SQLAlchemyObjectType, SQLAlchemyObjectTypeOptions from .models import Article, Reporter -from ..fields import SQLAlchemyConnectionField registry = Registry() diff --git a/graphene_sqlalchemy/tests/test_utils.py b/graphene_sqlalchemy/tests/test_utils.py index 664b2595..a7b902fe 100644 --- a/graphene_sqlalchemy/tests/test_utils.py +++ b/graphene_sqlalchemy/tests/test_utils.py @@ -1,8 +1,9 @@ -from graphene import Enum, List, ObjectType, Schema, String import sqlalchemy as sa -from ..utils import get_session, sort_enum_for_model, sort_argument_for_model -from .models import Pet, Editor +from graphene import Enum, List, ObjectType, Schema, String + +from ..utils import get_session, sort_argument_for_model, sort_enum_for_model +from .models import Editor, Pet def test_get_session(): diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index 300af684..dde746ec 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -1,8 +1,8 @@ from collections import OrderedDict import sqlalchemy -from sqlalchemy.inspection import inspect as sqlalchemyinspect from sqlalchemy.ext.hybrid import hybrid_property +from sqlalchemy.inspection import inspect as sqlalchemyinspect from sqlalchemy.orm.exc import NoResultFound from graphene import Field # , annotate, ResolveInfo @@ -10,12 +10,10 @@ from graphene.types.objecttype import ObjectType, ObjectTypeOptions from graphene.types.utils import yank_fields_from_attrs -from .converter import ( - convert_sqlalchemy_column, - convert_sqlalchemy_composite, - convert_sqlalchemy_relationship, - convert_sqlalchemy_hybrid_method, -) +from .converter import (convert_sqlalchemy_column, + convert_sqlalchemy_composite, + convert_sqlalchemy_hybrid_method, + convert_sqlalchemy_relationship) from .registry import Registry, get_global_registry from .utils import get_query, is_mapped_class, is_mapped_instance diff --git a/graphene_sqlalchemy/utils.py b/graphene_sqlalchemy/utils.py index 7ac1a703..276a8075 100644 --- a/graphene_sqlalchemy/utils.py +++ b/graphene_sqlalchemy/utils.py @@ -1,9 +1,10 @@ -from graphene import Argument, Enum, List from sqlalchemy.exc import ArgumentError from sqlalchemy.inspection import inspect from sqlalchemy.orm import class_mapper, object_mapper from sqlalchemy.orm.exc import UnmappedClassError, UnmappedInstanceError +from graphene import Argument, Enum, List + def get_session(context): return context.get("session") diff --git a/setup.cfg b/setup.cfg index 88221f21..7fd23df6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,9 +5,12 @@ test=pytest exclude = setup.py,docs/*,examples/*,tests max-line-length = 120 -# TODO Add isort as a pre-commit hook [isort] -known_first_party=graphene,graphene_sqlalchemy +known_graphene=graphene,graphql_relay,flask_graphql,graphql_server,sphinx_graphene_theme +known_first_party=graphene_sqlalchemy +known_third_party=flask,nameko,promise,py,pytest,setuptools,singledispatch,six,sqlalchemy,sqlalchemy_utils +sections=FUTURE,STDLIB,THIRDPARTY,GRAPHENE,FIRSTPARTY,LOCALFOLDER +no_lines_before=FIRSTPARTY [bdist_wheel] universal=1 diff --git a/setup.py b/setup.py index 0648381c..66704b28 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,8 @@ -from setuptools import find_packages, setup -import sys import ast import re +import sys + +from setuptools import find_packages, setup _version_re = re.compile(r"__version__\s+=\s+(.*)")