Skip to content

Commit 54c2790

Browse files
committed
Fix placing of self and format output file with black
1 parent 9702db2 commit 54c2790

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

generate/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
module_path = Path(__file__).parent.parent / "cayley" / "path.py"
66

7-
with module_path.open("w+") as file:
8-
file.write(generate())
7+
generate(module_path)
8+
99
print(f"Generated {module_path}", file=sys.stderr)

generate/generate.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import ast
2-
import astor
32
import json
4-
from collections.abc import Iterable
3+
import subprocess
54
from pathlib import Path
5+
from collections.abc import Iterable
6+
import astor
67
from typing import Dict, List, Tuple, Iterator, Set
8+
import black
79
from . import snake_case
810

911
directory = Path(__file__).parent
@@ -112,7 +114,7 @@ def get_domains(_property: dict) -> Iterator[dict]:
112114
yield domain
113115

114116

115-
def generate() -> str:
117+
def generate(module_path: Path) -> str:
116118
module = astor.code_to_ast.parse_file(header_path)
117119
# print(astor.dump_tree(tree))
118120
with schema_path.open() as file:
@@ -153,9 +155,15 @@ def generate() -> str:
153155
(ast.Constant("@type"), ast.Constant(step_class["@id"]))
154156
]
155157
properties = properties_by_domain.get(step_class["@id"], [])
158+
sorted_properties = sorted(
159+
properties,
160+
key=lambda _property: ""
161+
if _property["@id"] == "linkedql:from"
162+
else _property["@id"],
163+
)
156164
positional_args = []
157165
kwonlyargs = []
158-
for _property in sorted(properties, key=lambda _property: _property["@id"]):
166+
for _property in sorted_properties:
159167
argument_name = remove_linked_ql(_property["@id"])
160168
if argument_name == "from":
161169
is_method = True
@@ -211,4 +219,8 @@ def generate() -> str:
211219
class_def.body.append(function_def)
212220
else:
213221
module.body.append(function_def)
214-
return astor.to_source(module)
222+
generated_code = astor.to_source(module)
223+
with module_path.open("w+") as file:
224+
file.write(generated_code)
225+
subprocess.run(["black", str(module_path)])
226+

0 commit comments

Comments
 (0)