Skip to content

Add Python 3.10 Support & update pre-commit hooks #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = E203,W503
exclude = .git,.mypy_cache,.pytest_cache,.tox,.venv,__pycache__,build,dist,docs
max-line-length = 120
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
33 changes: 15 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
60 changes: 30 additions & 30 deletions graphene_sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions graphene_sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
},
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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