99import libcst as cst
1010
1111from .models import GenerationConfig , ModuleArtifacts , CallbackMeta
12- from .utils import normalize_identifier , path_literal
12+ from .. import _normalize_prop
1313
1414
1515def module_relative_path_expr (module_dir : Path , target : Path ) -> str :
1616 try :
1717 rel = os .path .relpath (target , module_dir )
1818 except ValueError :
19- return f"Path( { path_literal ( target )} )"
19+ return repr ( target )
2020
2121 if rel in ("." , "" ):
2222 return "_MODULE_DIR"
@@ -50,14 +50,14 @@ def _stmt(code: str) -> cst.BaseStatement:
5050 include_expr_code = f"[{ ', ' .join (include_exprs )} ]" if include_exprs else "None"
5151
5252 library_items = [
53- f"{ path_literal ( name )} : { module_relative_path_expr (module_dir , lib_path )} "
53+ f"{ repr ( Path ( name ) )} : { module_relative_path_expr (module_dir , lib_path )} "
5454 for name , lib_path in config .library_paths .items ()
5555 ]
5656 library_expr_code = f"{{{ ', ' .join (library_items )} }}" if library_items else "None"
5757
58- style_expr = path_literal ( config .style ) if config .style else "None"
58+ style_expr = repr ( Path ( config .style ) ) if config .style else "None"
5959 domain_expr = (
60- path_literal ( config .translation_domain ) if config .translation_domain else "None"
60+ repr ( Path ( config .translation_domain ) ) if config .translation_domain else "None"
6161 )
6262
6363 export_bindings : dict [str , str ] = {}
@@ -69,7 +69,7 @@ def _stmt(code: str) -> cst.BaseStatement:
6969 export_bindings [enum .name ] = enum .py_name
7070
7171 export_items = list (export_bindings .values ()) + [
72- normalize_identifier (alias ) for _ , alias in artifacts .named_exports
72+ _normalize_prop (alias ) for _ , alias in artifacts .named_exports
7373 ]
7474
7575 header : list [cst .CSTNode ] = [
@@ -152,8 +152,8 @@ def _stmt(code: str) -> cst.BaseStatement:
152152 for original , binding in export_bindings .items ():
153153 body .append (_stmt (f"{ binding } = _module.{ original } " ))
154154 for orig , alias in artifacts .named_exports :
155- alias_name = normalize_identifier (alias )
156- target = export_bindings .get (orig , normalize_identifier (orig ))
155+ alias_name = _normalize_prop (alias )
156+ target = export_bindings .get (orig , _normalize_prop (orig ))
157157 body .append (_stmt (f"{ alias_name } = { target } " ))
158158
159159 module = cst .Module (body = header + body ) # type: ignore[arg-type]
@@ -187,7 +187,7 @@ def register_type(type_str: str) -> None:
187187 export_names += [struct .py_name for struct in artifacts .structs ]
188188 export_names += [enum .py_name for enum in artifacts .enums ]
189189 export_names += [
190- normalize_identifier (alias ) for _ , alias in artifacts .named_exports
190+ _normalize_prop (alias ) for _ , alias in artifacts .named_exports
191191 ]
192192 if export_names :
193193 all_list = cst .List (
@@ -354,8 +354,8 @@ def init_stub() -> cst.FunctionDef:
354354 bindings [enum_meta .name ] = enum_meta .py_name
355355
356356 for orig , alias in artifacts .named_exports :
357- alias_name = normalize_identifier (alias )
358- target = bindings .get (orig , normalize_identifier (orig ))
357+ alias_name = _normalize_prop (alias )
358+ target = bindings .get (orig , _normalize_prop (orig ))
359359 post_body .append (_stmt (f"{ alias_name } = { target } " ))
360360 post_body .append (cst .EmptyLine ())
361361
0 commit comments