|
1 | 1 | """Formatting utils and functions."""
|
2 | 2 | import textwrap
|
3 | 3 |
|
| 4 | +import attr |
| 5 | + |
4 | 6 | from .utils import variables_dict
|
5 | 7 | from .variable import VarIntent, VarType
|
6 | 8 |
|
@@ -85,23 +87,53 @@ def _summarize_var(var, process, col_width):
|
85 | 87 |
|
86 | 88 |
|
87 | 89 | def var_details(var, max_line_length=70):
|
88 |
| - var_metadata = var.metadata.copy() |
| 90 | + meta = var.metadata |
| 91 | + subsections = [] |
| 92 | + |
| 93 | + if meta["description"]: |
| 94 | + wrapped_descr = textwrap.fill( |
| 95 | + meta["description"].capitalize(), width=max_line_length |
| 96 | + ) |
| 97 | + subsections.append(wrapped_descr) |
| 98 | + else: |
| 99 | + subsections.append("No description given") |
89 | 100 |
|
90 |
| - description = textwrap.fill( |
91 |
| - var_metadata.pop("description").capitalize(), width=max_line_length |
92 |
| - ) |
93 |
| - if not description: |
94 |
| - description = "(no description given)" |
| 101 | + info = [f"- type : ``{meta['var_type'].value}``"] |
95 | 102 |
|
96 |
| - detail_items = [ |
97 |
| - ("type", var_metadata.pop("var_type").value), |
98 |
| - ("intent", var_metadata.pop("intent").value), |
99 |
| - ] |
100 |
| - detail_items += list(var_metadata.items()) |
| 103 | + if meta["var_type"] is VarType.FOREIGN: |
| 104 | + ref_cls = meta["other_process_cls"] |
| 105 | + ref_var = meta["var_name"] |
| 106 | + info.append(f"- reference variable : :attr:`{ref_cls.__qualname__}.{ref_var}`") |
| 107 | + |
| 108 | + info.append(f"- intent : ``{meta['intent'].value}``") |
| 109 | + |
| 110 | + if meta.get("dims", False): |
| 111 | + info.append("- dimensions : " + " or ".join(f"{d!r}" for d in meta["dims"])) |
| 112 | + |
| 113 | + if meta.get("groups", False): |
| 114 | + info.append("- groups : " + ", ".join(meta["groups"])) |
| 115 | + |
| 116 | + if var.default != attr.NOTHING: |
| 117 | + info.append(f"- default value : {var.default}") |
| 118 | + |
| 119 | + if meta.get("static", False): |
| 120 | + info.append("- static : ``True``") |
| 121 | + |
| 122 | + subsections.append("Variable properties:\n\n" + "\n".join(info)) |
| 123 | + |
| 124 | + if meta.get("attrs", False): |
| 125 | + subsections.append( |
| 126 | + "Other attributes:\n\n" |
| 127 | + + "\n".join(f"- {k} : {v}" for k, v in meta["attrs"].items()) |
| 128 | + ) |
101 | 129 |
|
102 |
| - details = "\n".join([f"- {k} : {v}" for k, v in detail_items]) |
| 130 | + if meta.get("encoding", False): |
| 131 | + subsections.append( |
| 132 | + "Encoding options:\n\n" |
| 133 | + + "\n".join(f"- {k} : {v}" for k, v in meta["encoding"].items()) |
| 134 | + ) |
103 | 135 |
|
104 |
| - return description + "\n\n" + details + "\n" |
| 136 | + return "\n\n".join(subsections) + "\n" |
105 | 137 |
|
106 | 138 |
|
107 | 139 | def add_attribute_section(process, placeholder="{{attributes}}"):
|
|
0 commit comments