Skip to content

Commit

Permalink
blacked
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Aug 23, 2024
1 parent c7b9117 commit 6978c74
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 106 deletions.
8 changes: 4 additions & 4 deletions turms/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def load_introspection_from_url(
raise GenerationError(
f"Failed to fetch schema from {url} Graphql error: {x['errors']}"
)

if "data" not in x:
raise GenerationError(f"Failed to fetch schema from {url}. Did not receive data attripute: {x}")


if "data" not in x:
raise GenerationError(
f"Failed to fetch schema from {url}. Did not receive data attripute: {x}"
)

return x["data"]

Expand Down
3 changes: 1 addition & 2 deletions turms/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ class Parser(BaseModel):
def parse_ast(
self,
asts: List[ast.AST],
) -> List[ast.AST]:
... # pragma: no cover
) -> List[ast.AST]: ... # pragma: no cover
7 changes: 3 additions & 4 deletions turms/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from graphql.utilities.build_client_schema import GraphQLSchema
from turms.config import LogFunction


class PluginConfig(BaseSettings):
type: str

Expand All @@ -30,10 +31,8 @@ def generate_ast(
config,
client_schema: GraphQLSchema,
registry,
) -> List[ast.AST]:
... # pragma: no cover

) -> List[ast.AST]: ... # pragma: no cover

class Config:
extra = "forbid"
arbitrary_types_allowed = True
arbitrary_types_allowed = True
98 changes: 53 additions & 45 deletions turms/plugins/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,32 +785,36 @@ def generate_operation_func(
),
body=[
doc,
genereate_async_call(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
)
if definition.type != OperationType.SUBSCRIPTION
else genereate_async_iterator(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
(
genereate_async_call(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
)
if definition.type != OperationType.SUBSCRIPTION
else genereate_async_iterator(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
)
),
],
decorator_list=[],
returns=return_type
if definition.type != OperationType.SUBSCRIPTION
else ast.Subscript(
value=ast.Name(id="AsyncIterator", ctx=ast.Load()),
slice=return_type,
returns=(
return_type
if definition.type != OperationType.SUBSCRIPTION
else ast.Subscript(
value=ast.Name(id="AsyncIterator", ctx=ast.Load()),
slice=return_type,
)
),
)
)
Expand All @@ -831,31 +835,35 @@ def generate_operation_func(
),
body=[
doc,
genereate_sync_call(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
)
if definition.type != OperationType.SUBSCRIPTION
else genereate_sync_iterator(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
(
genereate_sync_call(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
)
if definition.type != OperationType.SUBSCRIPTION
else genereate_sync_iterator(
definition,
o,
client_schema,
config,
plugin_config,
registry,
collapse,
)
),
],
decorator_list=[],
returns=return_type
if definition.type != OperationType.SUBSCRIPTION
else ast.Subscript(
value=ast.Name(id="Iterator", ctx=ast.Load()), slice=return_type
returns=(
return_type
if definition.type != OperationType.SUBSCRIPTION
else ast.Subscript(
value=ast.Name(id="Iterator", ctx=ast.Load()), slice=return_type
)
),
)
)
Expand Down
10 changes: 6 additions & 4 deletions turms/plugins/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ def generate_inputs(
if field_name != value_key:
registry.register_import("pydantic.Field")
keywords = [
ast.keyword(
arg="alias", value=ast.Constant(value=value_key)
)
ast.keyword(arg="alias", value=ast.Constant(value=value_key))
]
if not isinstance(value.type, GraphQLNonNull):
keywords.append(
Expand Down Expand Up @@ -215,7 +213,11 @@ def generate_inputs(
is_optional=True,
),
simple=1,
value=ast.Constant(None) if not isinstance(value.type, GraphQLNonNull) else None,
value=(
ast.Constant(None)
if not isinstance(value.type, GraphQLNonNull)
else None
),
)

potential_comment = (
Expand Down
25 changes: 17 additions & 8 deletions turms/plugins/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,22 @@ def generate_object_field_annotation(
and config.freeze.convert_list_to_tuple
):
registry.register_import("typing.Tuple")

def list_builder(x):
return ast.Subscript(value=ast.Name("Tuple", ctx=ast.Load()), slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()), ctx=ast.Load())
return ast.Subscript(
value=ast.Name("Tuple", ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()),
ctx=ast.Load(),
)

else:

registry.register_import("typing.List")

def list_builder(x):
return ast.Subscript(value=ast.Name("List", ctx=ast.Load()), slice=x, ctx=ast.Load())
return ast.Subscript(
value=ast.Name("List", ctx=ast.Load()), slice=x, ctx=ast.Load()
)

if is_optional:
registry.register_import("typing.Optional")
Expand Down Expand Up @@ -223,12 +232,12 @@ def generate_types(
)
}

interface_map: Dict[
str, List[str]
] = {} # A list of interfaces with the union classes attached
interface_base_map: Dict[
str, str
] = {} # A list of interfaces with its respective base
interface_map: Dict[str, List[str]] = (
{}
) # A list of interfaces with the union classes attached
interface_base_map: Dict[str, str] = (
{}
) # A list of interfaces with its respective base

for base in plugin_config.types_bases:
registry.register_import(base)
Expand Down
16 changes: 10 additions & 6 deletions turms/plugins/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ def generate_operation(
ast.keyword(
arg="default",
value=ast.Constant(
value=parse_value_node(v.default_value)
if v.default_value is not None
else None
value=(
parse_value_node(v.default_value)
if v.default_value is not None
else None
)
),
),
],
Expand Down Expand Up @@ -289,9 +291,11 @@ def generate_operation(
ast.keyword(
arg="default",
value=ast.Constant(
value=parse_value_node(v.default_value)
if v.default_value is not None
else None
value=(
parse_value_node(v.default_value)
if v.default_value is not None
else None
)
),
),
],
Expand Down
15 changes: 7 additions & 8 deletions turms/plugins/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def __call__(
config: GeneratorConfig,
plugin_config: "StrawberryPluginConfig",
registry: ClassRegistry,
) -> List[ast.AST]:
... # pragma: no cover
) -> List[ast.AST]: ... # pragma: no cover


def default_generate_directives(
Expand Down Expand Up @@ -708,12 +707,12 @@ def generate_types(
}
registry.register_import("strawberry")

interface_map: Dict[
str, List[str]
] = {} # A list of interfaces with the union classes attached
interface_base_map: Dict[
str, str
] = {} # A list of interfaces with its respective base
interface_map: Dict[str, List[str]] = (
{}
) # A list of interfaces with the union classes attached
interface_base_map: Dict[str, str] = (
{}
) # A list of interfaces with its respective base

for key, object_type in sorted_objects.items():
additional_bases = get_additional_bases_for_type(
Expand Down
3 changes: 1 addition & 2 deletions turms/processors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class Processor(BaseModel):
config: ProcessorConfig

@abstractmethod
def run(gen_file: str, config: GeneratorConfig):
... # pragma: no cover
def run(gen_file: str, config: GeneratorConfig): ... # pragma: no cover
30 changes: 18 additions & 12 deletions turms/recurse.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ class X(BaseModel):
)
cls = ast.ClassDef(
inline_fragment_name,
bases=additional_bases + [
ast.Name(id=base.split(".")[-1], ctx=ast.Load())
for base in config.object_bases
],
bases=additional_bases
+ [
ast.Name(id=base.split(".")[-1], ctx=ast.Load())
for base in config.object_bases
],
decorator_list=[],
keywords=[],
body=inline_fragment_fields
Expand Down Expand Up @@ -166,9 +167,6 @@ class X(BaseModel):
else:
return ast.Name(id=union_class_names[0], ctx=ast.Load())




if isinstance(type, GraphQLInterfaceType):
# Lets Create Base Class to Inherit from for this
mother_class_fields = []
Expand Down Expand Up @@ -294,9 +292,9 @@ class X(BaseModel):
)

elif isinstance(sub_sub_node, FragmentSpreadNode):
additional_bases.append(registry.reference_fragment(
sub_sub_node.name.value, parent
))
additional_bases.append(
registry.reference_fragment(sub_sub_node.name.value, parent)
)

cls = ast.ClassDef(
inline_fragment_name,
Expand Down Expand Up @@ -490,14 +488,22 @@ class X(BaseModel):

if config.freeze.enabled:
registry.register_import("typing.Tuple")

def list_builder(x):
return ast.Subscript(value=ast.Name("Tuple", ctx=ast.Load()), slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()), ctx=ast.Load())
return ast.Subscript(
value=ast.Name("Tuple", ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()),
ctx=ast.Load(),
)

else:

registry.register_import("typing.List")

def list_builder(x):
return ast.Subscript(value=ast.Name("List", ctx=ast.Load()), slice=x, ctx=ast.Load())
return ast.Subscript(
value=ast.Name("List", ctx=ast.Load()), slice=x, ctx=ast.Load()
)

if is_optional:
registry.register_import("typing.Optional")
Expand Down
Loading

0 comments on commit 6978c74

Please sign in to comment.