diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..30f6dedd --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +ignore = E203,W503 +exclude = .git,.mypy_cache,.pytest_cache,.tox,.venv,__pycache__,build,dist,docs +max-line-length = 120 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1ae7b4b6..9cc136a1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,11 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 with: - python-version: 3.9 + python-version: '3.10' - name: Build wheel and source tarball run: | pip install wheel diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 559326c4..9352dbe5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,11 +7,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 with: - python-version: 3.9 + python-version: '3.10' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9a3bd5d..de78190d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,12 +9,12 @@ jobs: max-parallel: 10 matrix: sql-alchemy: ["1.2", "1.3", "1.4"] - python-version: ["3.6", "3.7", "3.8", "3.9"] + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -27,12 +27,12 @@ jobs: SQLALCHEMY: ${{ matrix.sql-alchemy }} TOXENV: ${{ matrix.toxenv }} - name: Upload coverage.xml - if: ${{ matrix.sql-alchemy == '1.4' && matrix.python-version == '3.9' }} - uses: actions/upload-artifact@v2 + if: ${{ matrix.sql-alchemy == '1.4' && matrix.python-version == '3.10' }} + uses: actions/upload-artifact@v3 with: name: graphene-sqlalchemy-coverage path: coverage.xml if-no-files-found: error - name: Upload coverage.xml to codecov - if: ${{ matrix.sql-alchemy == '1.4' && matrix.python-version == '3.9' }} - uses: codecov/codecov-action@v1 + if: ${{ matrix.sql-alchemy == '1.4' && matrix.python-version == '3.10' }} + uses: codecov/codecov-action@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c67ab03..66db3814 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,25 +1,22 @@ default_language_version: - python: python3.7 + python: python3.10 repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: c8bad492e1b1d65d9126dba3fe3bd49a5a52b9d6 # v2.1.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-merge-conflict - - id: check-yaml - - id: debug-statements - - id: end-of-file-fixer + - id: check-merge-conflict + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer exclude: ^docs/.*$ - - id: trailing-whitespace + - id: trailing-whitespace exclude: README.md -- repo: https://github.com/PyCQA/flake8 - rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7 + - repo: https://github.com/pycqa/isort + rev: 5.10.1 hooks: - - id: flake8 -- repo: https://github.com/asottile/seed-isort-config - rev: v1.7.0 + - id: isort + name: isort (python) + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.0 hooks: - - id: seed-isort-config -- repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.4 - hooks: - - id: isort + - id: flake8 diff --git a/graphene_sqlalchemy/__init__.py b/graphene_sqlalchemy/__init__.py index 060bd13b..18d34f1d 100644 --- a/graphene_sqlalchemy/__init__.py +++ b/graphene_sqlalchemy/__init__.py @@ -1,5 +1,5 @@ -from .types import SQLAlchemyObjectType from .fields import SQLAlchemyConnectionField +from .types import SQLAlchemyObjectType from .utils import get_query, get_session __version__ = "3.0.0b1" diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 5d75984b..60e14ddd 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -29,7 +29,8 @@ from typing import _ForwardRef as ForwardRef try: - from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, TSVectorType + from sqlalchemy_utils import (ChoiceType, JSONType, ScalarListType, + TSVectorType) except ImportError: ChoiceType = JSONType = ScalarListType = TSVectorType = object diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index ac69b697..e6c3d14c 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -25,15 +25,15 @@ class ORMField(OrderedType): def __init__( - self, - model_attr=None, - type_=None, - required=None, - description=None, - deprecation_reason=None, - batching=None, - _creation_counter=None, - **field_kwargs + self, + model_attr=None, + type_=None, + required=None, + description=None, + deprecation_reason=None, + batching=None, + _creation_counter=None, + **field_kwargs ): """ Use this to override fields automatically generated by SQLAlchemyObjectType. @@ -89,7 +89,7 @@ class Meta: def construct_fields( - obj_type, model, registry, only_fields, exclude_fields, batching, connection_field_factory + obj_type, model, registry, only_fields, exclude_fields, batching, connection_field_factory ): """ Construct all the fields for a SQLAlchemyObjectType. @@ -110,11 +110,11 @@ def construct_fields( inspected_model = sqlalchemy.inspect(model) # Gather all the relevant attributes from the SQLAlchemy model in order all_model_attrs = OrderedDict( - inspected_model.column_attrs.items() + - inspected_model.composites.items() + - [(name, item) for name, item in inspected_model.all_orm_descriptors.items() - if isinstance(item, hybrid_property)] + - inspected_model.relationships.items() + inspected_model.column_attrs.items() + + inspected_model.composites.items() + + [(name, item) for name, item in inspected_model.all_orm_descriptors.items() + if isinstance(item, hybrid_property)] + + inspected_model.relationships.items() ) # Filter out excluded fields @@ -191,21 +191,21 @@ class SQLAlchemyObjectTypeOptions(ObjectTypeOptions): class SQLAlchemyObjectType(ObjectType): @classmethod def __init_subclass_with_meta__( - cls, - model=None, - registry=None, - skip_registry=False, - only_fields=(), - exclude_fields=(), - connection=None, - connection_class=None, - use_connection=None, - interfaces=(), - id=None, - batching=False, - connection_field_factory=None, - _meta=None, - **options + cls, + model=None, + registry=None, + skip_registry=False, + only_fields=(), + exclude_fields=(), + connection=None, + connection_class=None, + use_connection=None, + interfaces=(), + id=None, + batching=False, + connection_field_factory=None, + _meta=None, + **options ): # Make sure model is a valid SQLAlchemy model if not is_mapped_class(model): diff --git a/graphene_sqlalchemy/utils.py b/graphene_sqlalchemy/utils.py index 301e782c..084f9b86 100644 --- a/graphene_sqlalchemy/utils.py +++ b/graphene_sqlalchemy/utils.py @@ -140,6 +140,7 @@ def sort_argument_for_model(cls, has_default=True): ) from graphene import Argument, List + from .enums import sort_enum_for_object_type enum = sort_enum_for_object_type( diff --git a/setup.py b/setup.py index da49f1d4..ac9ad7e6 100644 --- a/setup.py +++ b/setup.py @@ -41,9 +41,10 @@ "Intended Audience :: Developers", "Topic :: Software Development :: Libraries", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Programming Language :: Python :: Implementation :: PyPy", ], keywords="api graphql protocol rest relay graphene", @@ -52,8 +53,8 @@ extras_require={ "dev": [ "tox==3.7.0", # Should be kept in sync with tox.ini - "pre-commit==1.14.4", - "flake8==3.7.9", + "pre-commit==2.19", + "flake8==4.0.0", ], "test": tests_require, }, diff --git a/tox.ini b/tox.ini index b8ce0618..2802dee0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,14 @@ [tox] -envlist = pre-commit,py{36,37,38,39}-sql{12,13,14} +envlist = pre-commit,py{37,38,39,310}-sql{12,13,14} skipsdist = true minversion = 3.7.0 [gh-actions] python = - 3.6: py36 3.7: py37 3.8: py38 3.9: py39 + 3.10: py310 [gh-actions:env] SQLALCHEMY = @@ -27,14 +27,14 @@ commands = pytest graphene_sqlalchemy --cov=graphene_sqlalchemy --cov-report=term --cov-report=xml {posargs} [testenv:pre-commit] -basepython=python3.9 +basepython=python3.10 deps = .[dev] commands = pre-commit {posargs:run --all-files} [testenv:flake8] -basepython = python3.9 +basepython = python3.10 deps = -e.[dev] commands = flake8 --exclude setup.py,docs,examples,tests,.tox --max-line-length 120