1+ # Copyright © SixtyFPS GmbH <[email protected] > 2+ # SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3+
14from __future__ import annotations
25
36import os
@@ -53,7 +56,9 @@ def _stmt(code: str) -> cst.BaseStatement:
5356 library_expr_code = f"{{{ ', ' .join (library_items )} }}" if library_items else "None"
5457
5558 style_expr = path_literal (config .style ) if config .style else "None"
56- domain_expr = path_literal (config .translation_domain ) if config .translation_domain else "None"
59+ domain_expr = (
60+ path_literal (config .translation_domain ) if config .translation_domain else "None"
61+ )
5762
5863 export_bindings : dict [str , str ] = {}
5964 for component in artifacts .components :
@@ -68,7 +73,9 @@ def _stmt(code: str) -> cst.BaseStatement:
6873 ]
6974
7075 header : list [cst .CSTNode ] = [
71- cst .EmptyLine (comment = cst .Comment (f"# Generated by slint.codegen from { source_relative } " ))
76+ cst .EmptyLine (
77+ comment = cst .Comment (f"# Generated by slint.codegen from { source_relative } " )
78+ )
7279 ]
7380
7481 body : list [cst .CSTNode ] = [
@@ -90,7 +97,11 @@ def _stmt(code: str) -> cst.BaseStatement:
9097 )
9198 body .append (
9299 cst .SimpleStatementLine (
93- [cst .Assign (targets = [cst .AssignTarget (cst .Name ("__all__" ))], value = all_list )]
100+ [
101+ cst .Assign (
102+ targets = [cst .AssignTarget (cst .Name ("__all__" ))], value = all_list
103+ )
104+ ]
94105 )
95106 )
96107 body .append (cst .EmptyLine ())
@@ -112,7 +123,7 @@ def _stmt(code: str) -> cst.BaseStatement:
112123
113124 load_source = (
114125 "def _load() -> types.SimpleNamespace:\n "
115- " \" \" \ " Load the compiled Slint module for this package.\" \" \ "\n "
126+ ' "" "Load the compiled Slint module for this package."" "\n '
116127 " package = __package__ or (__spec__.parent if __spec__ else None)\n "
117128 " if package:\n "
118129 " ctx = _resources.as_file(_resources.files(package).joinpath(_SLINT_RESOURCE))\n "
@@ -180,11 +191,17 @@ def register_type(type_str: str) -> None:
180191 ]
181192 if export_names :
182193 all_list = cst .List (
183- elements = [cst .Element (cst .SimpleString (repr (name ))) for name in export_names ]
194+ elements = [
195+ cst .Element (cst .SimpleString (repr (name ))) for name in export_names
196+ ]
184197 )
185198 post_body .append (
186199 cst .SimpleStatementLine (
187- [cst .Assign (targets = [cst .AssignTarget (cst .Name ("__all__" ))], value = all_list )]
200+ [
201+ cst .Assign (
202+ targets = [cst .AssignTarget (cst .Name ("__all__" ))], value = all_list
203+ )
204+ ]
188205 )
189206 )
190207 post_body .append (cst .EmptyLine ())
@@ -194,7 +211,9 @@ def ann_assign(name: str, type_expr: str) -> cst.BaseStatement:
194211 [
195212 cst .AnnAssign (
196213 target = cst .Name (name ),
197- annotation = cst .Annotation (annotation = cst .parse_expression (type_expr )),
214+ annotation = cst .Annotation (
215+ annotation = cst .parse_expression (type_expr )
216+ ),
198217 value = None ,
199218 )
200219 ]
@@ -253,7 +272,13 @@ def init_stub() -> cst.FunctionDef:
253272 post_body .append (
254273 cst .ClassDef (
255274 name = cst .Name (enum_meta .py_name ),
256- bases = [cst .Arg (value = cst .Attribute (value = cst .Name ("enum" ), attr = cst .Name ("Enum" )))],
275+ bases = [
276+ cst .Arg (
277+ value = cst .Attribute (
278+ value = cst .Name ("enum" ), attr = cst .Name ("Enum" )
279+ )
280+ )
281+ ],
257282 body = cst .IndentedBlock (body = enum_body ),
258283 )
259284 )
@@ -274,12 +299,16 @@ def init_stub() -> cst.FunctionDef:
274299 component_body .append (ann_assign (fn .py_name , annotation ))
275300 for global_meta in component .globals :
276301 component_body .append (
277- ann_assign (global_meta .py_name , f"{ component .py_name } .{ global_meta .py_name } " )
302+ ann_assign (
303+ global_meta .py_name , f"{ component .py_name } .{ global_meta .py_name } "
304+ )
278305 )
279306
280307 for global_meta in component .globals :
281308 inner_body : list [cst .BaseStatement ] = []
282- if not (global_meta .properties or global_meta .callbacks or global_meta .functions ):
309+ if not (
310+ global_meta .properties or global_meta .callbacks or global_meta .functions
311+ ):
283312 inner_body .append (ellipsis_line ())
284313 else :
285314 for prop in global_meta .properties :
@@ -306,7 +335,9 @@ def init_stub() -> cst.FunctionDef:
306335 name = cst .Name (component .py_name ),
307336 bases = [
308337 cst .Arg (
309- value = cst .Attribute (value = cst .Name ("slint" ), attr = cst .Name ("Component" ))
338+ value = cst .Attribute (
339+ value = cst .Name ("slint" ), attr = cst .Name ("Component" )
340+ )
310341 )
311342 ],
312343 body = cst .IndentedBlock (body = component_body ),
0 commit comments