Skip to content

Commit a084895

Browse files
authored
Fix Lint & Publish CI workflow (#229)
* feat(CI/CD): Add GitHub Action workflow to publish to PyPI * fix: Used isinstance instead of type() to validate type instance * feat: Use PyPI Trusted Publisher * fix: Ruff formatting, fix type issue
1 parent 8828d6b commit a084895

File tree

8 files changed

+66
-31
lines changed

8 files changed

+66
-31
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
15-
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
15+
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1616
runs-on: ${{ matrix.os }}
1717
steps:
1818
- uses: actions/checkout@v3
1919
- name: Set up Python ${{ matrix.python }}
2020
uses: actions/setup-python@v3
2121
with:
2222
python-version: ${{ matrix.python }}
23-
- name: Lint with flake8
24-
run: |
25-
python -m pip install flake8
26-
flake8 graphene_mongo --count --show-source --statistics
2723
- name: Install dependencies
2824
run: |
2925
python -m pip install poetry
3026
poetry config virtualenvs.create false
3127
poetry install --with dev
28+
- name: Lint
29+
run: |
30+
make lint
3231
- name: Run Tests
3332
run: make test
3433
- name: Build Package

graphene_mongo/converter.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,15 @@ def reference_resolver(root, *args, **kwargs):
197197
if model in to_resolve_models:
198198
futures.append(
199199
pool.submit(
200-
get_reference_objects, (model, object_id_list, registry, args)
200+
get_reference_objects,
201+
(model, object_id_list, registry, args),
201202
)
202203
)
203204
else:
204205
futures.append(
205206
pool.submit(
206-
get_non_querying_object, (model, object_id_list, registry, args)
207+
get_non_querying_object,
208+
(model, object_id_list, registry, args),
207209
)
208210
)
209211
result = list()
@@ -325,7 +327,9 @@ async def reference_resolver_async(root, *args, **kwargs):
325327
base_type = type(base_type)
326328

327329
return graphene.List(
328-
base_type, description=get_field_description(field, registry), required=field.required
330+
base_type,
331+
description=get_field_description(field, registry),
332+
required=field.required,
329333
)
330334

331335

@@ -634,7 +638,9 @@ def dynamic_type():
634638
return None
635639
if isinstance(field, mongoengine.EmbeddedDocumentField):
636640
return graphene.Field(
637-
_type, description=get_field_description(field, registry), required=field.required
641+
_type,
642+
description=get_field_description(field, registry),
643+
required=field.required,
638644
)
639645
field_resolver = None
640646
required = False
@@ -764,5 +770,7 @@ def convert_field_to_enum(field, registry=None, executor: ExecutorEnum = Executo
764770
registry.register_enum(field._enum_cls)
765771
_type = registry.get_type_for_enum(field._enum_cls)
766772
return graphene.Field(
767-
_type, description=get_field_description(field, registry), required=field.required
773+
_type,
774+
description=get_field_description(field, registry),
775+
required=field.required,
768776
)

graphene_mongo/fields.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ def get_queryset(
296296
reference_obj = reference_fields[arg_name].document_type(pk=arg)
297297
hydrated_references[arg_name] = reference_obj
298298
elif arg_name in self.model._fields_ordered and isinstance(
299-
getattr(self.model, arg_name), mongoengine.fields.GenericReferenceField
299+
getattr(self.model, arg_name),
300+
mongoengine.fields.GenericReferenceField,
300301
):
301302
try:
302303
reference_obj = get_document(
@@ -306,7 +307,8 @@ def get_queryset(
306307
reference_obj = get_document(arg["_cls"])(pk=arg["_ref"].id)
307308
hydrated_references[arg_name] = reference_obj
308309
elif "__near" in arg_name and isinstance(
309-
getattr(self.model, arg_name.split("__")[0]), mongoengine.fields.PointField
310+
getattr(self.model, arg_name.split("__")[0]),
311+
mongoengine.fields.PointField,
310312
):
311313
location = args.pop(arg_name, None)
312314
hydrated_references[arg_name] = location["coordinates"]
@@ -383,7 +385,8 @@ def default_resolver(self, _root, info, required_fields=None, resolved=None, **a
383385
elif field_name in _root._fields_ordered and not (
384386
isinstance(_root._fields[field_name].field, mongoengine.EmbeddedDocumentField)
385387
or isinstance(
386-
_root._fields[field_name].field, mongoengine.GenericEmbeddedDocumentField
388+
_root._fields[field_name].field,
389+
mongoengine.GenericEmbeddedDocumentField,
387390
)
388391
):
389392
if getattr(_root, field_name, []) is not None:
@@ -464,13 +467,16 @@ def default_resolver(self, _root, info, required_fields=None, resolved=None, **a
464467
elif (
465468
isinstance(getattr(self.model, key), mongoengine.fields.ReferenceField)
466469
or isinstance(
467-
getattr(self.model, key), mongoengine.fields.GenericReferenceField
470+
getattr(self.model, key),
471+
mongoengine.fields.GenericReferenceField,
468472
)
469473
or isinstance(
470-
getattr(self.model, key), mongoengine.fields.LazyReferenceField
474+
getattr(self.model, key),
475+
mongoengine.fields.LazyReferenceField,
471476
)
472477
or isinstance(
473-
getattr(self.model, key), mongoengine.fields.CachedReferenceField
478+
getattr(self.model, key),
479+
mongoengine.fields.CachedReferenceField,
474480
)
475481
):
476482
if not isinstance(args_copy[key], ObjectId):
@@ -603,7 +609,7 @@ def chained_resolver(self, resolver, is_partial, root, info, **args):
603609
connection_fields = [
604610
field
605611
for field in self.fields
606-
if type(self.fields[field]) == MongoengineConnectionField
612+
if isinstance(self.fields[field], MongoengineConnectionField)
607613
]
608614

609615
def filter_connection(x):

graphene_mongo/fields_async.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ async def default_resolver(self, _root, info, required_fields=None, resolved=Non
7676
elif field_name in _root._fields_ordered and not (
7777
isinstance(_root._fields[field_name].field, mongoengine.EmbeddedDocumentField)
7878
or isinstance(
79-
_root._fields[field_name].field, mongoengine.GenericEmbeddedDocumentField
79+
_root._fields[field_name].field,
80+
mongoengine.GenericEmbeddedDocumentField,
8081
)
8182
):
8283
if getattr(_root, field_name, []) is not None:
@@ -170,13 +171,16 @@ async def default_resolver(self, _root, info, required_fields=None, resolved=Non
170171
elif (
171172
isinstance(getattr(self.model, key), mongoengine.fields.ReferenceField)
172173
or isinstance(
173-
getattr(self.model, key), mongoengine.fields.GenericReferenceField
174+
getattr(self.model, key),
175+
mongoengine.fields.GenericReferenceField,
174176
)
175177
or isinstance(
176-
getattr(self.model, key), mongoengine.fields.LazyReferenceField
178+
getattr(self.model, key),
179+
mongoengine.fields.LazyReferenceField,
177180
)
178181
or isinstance(
179-
getattr(self.model, key), mongoengine.fields.CachedReferenceField
182+
getattr(self.model, key),
183+
mongoengine.fields.CachedReferenceField,
180184
)
181185
):
182186
if not isinstance(args_copy[key], ObjectId):
@@ -304,7 +308,7 @@ async def chained_resolver(self, resolver, is_partial, root, info, **args):
304308
connection_fields = [
305309
field
306310
for field in self.fields
307-
if type(self.fields[field]) == AsyncMongoengineConnectionField
311+
if isinstance(self.fields[field], AsyncMongoengineConnectionField)
308312
]
309313

310314
def filter_connection(x):

graphene_mongo/tests/test_relay_query_async.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,8 @@ async def test_should_get_queryset_returns_dict_filters_async(fixtures):
801801
class Query(graphene.ObjectType):
802802
node = Node.Field()
803803
articles = AsyncMongoengineConnectionField(
804-
nodes_async.ArticleAsyncNode, get_queryset=lambda *_, **__: {"headline": "World"}
804+
nodes_async.ArticleAsyncNode,
805+
get_queryset=lambda *_, **__: {"headline": "World"},
805806
)
806807

807808
query = """
@@ -1032,7 +1033,9 @@ class Query(graphene.ObjectType):
10321033

10331034

10341035
@pytest.mark.asyncio
1035-
async def test_should_filter_mongoengine_queryset_by_id_and_other_fields_async(fixtures):
1036+
async def test_should_filter_mongoengine_queryset_by_id_and_other_fields_async(
1037+
fixtures,
1038+
):
10361039
class Query(graphene.ObjectType):
10371040
players = AsyncMongoengineConnectionField(nodes_async.PlayerAsyncNode)
10381041

graphene_mongo/tests/types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from . import models
2-
from ..types import MongoengineObjectType, MongoengineInterfaceType, MongoengineInputType
2+
from ..types import (
3+
MongoengineObjectType,
4+
MongoengineInterfaceType,
5+
MongoengineInputType,
6+
)
37
from graphene.types.union import Union
48

59

graphene_mongo/types_async.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ def resolve_id(self, info):
189189
return AsyncGrapheneMongoengineGenericType, AsyncMongoengineGenericObjectTypeOptions
190190

191191

192-
AsyncMongoengineObjectType, AsyncMongoengineObjectTypeOptions = create_graphene_generic_class_async(
193-
ObjectType, ObjectTypeOptions
194-
)
192+
(
193+
AsyncMongoengineObjectType,
194+
AsyncMongoengineObjectTypeOptions,
195+
) = create_graphene_generic_class_async(ObjectType, ObjectTypeOptions)
195196

196197
(
197198
AsyncMongoengineInterfaceType,
198199
MongoengineInterfaceTypeOptions,
199200
) = create_graphene_generic_class_async(Interface, InterfaceOptions)
200201

201-
AsyncGrapheneMongoengineObjectTypes = (AsyncMongoengineObjectType, AsyncMongoengineInterfaceType)
202+
AsyncGrapheneMongoengineObjectTypes = (
203+
AsyncMongoengineObjectType,
204+
AsyncMongoengineInterfaceType,
205+
)

graphene_mongo/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,18 @@ def find_skip_and_limit(first, last, after, before, count=None):
256256

257257

258258
def connection_from_iterables(
259-
edges, start_offset, has_previous_page, has_next_page, connection_type, edge_type, pageinfo_type
259+
edges,
260+
start_offset,
261+
has_previous_page,
262+
has_next_page,
263+
connection_type,
264+
edge_type,
265+
pageinfo_type,
260266
):
261267
edges_items = [
262268
edge_type(
263-
node=node, cursor=offset_to_cursor((0 if start_offset is None else start_offset) + i)
269+
node=node,
270+
cursor=offset_to_cursor((0 if start_offset is None else start_offset) + i),
264271
)
265272
for i, node in enumerate(edges)
266273
]

0 commit comments

Comments
 (0)