excel-codegen 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. excel_codegen/__init__.py +160 -0
  2. excel_codegen/__main__.py +8 -0
  3. excel_codegen/cli.py +1250 -0
  4. excel_codegen/derived.py +465 -0
  5. excel_codegen/example_pack.py +107 -0
  6. excel_codegen/examples/README.md +69 -0
  7. excel_codegen/examples/abs_fpi/ABS_FPI_load_cases.xlsx +0 -0
  8. excel_codegen/examples/abs_fpi/ABS_FPI_load_cases_render.bat +22 -0
  9. excel_codegen/examples/abs_fpi/ABS_FPI_load_cases_render.sh +23 -0
  10. excel_codegen/examples/abs_fpi/README.md +121 -0
  11. excel_codegen/examples/abs_fpi/abs_fpi.yaml +310 -0
  12. excel_codegen/examples/abs_fpi/abs_fpi_external.xlsx +0 -0
  13. excel_codegen/examples/abs_fpi/abs_fpi_external.yaml +162 -0
  14. excel_codegen/examples/abs_fpi/abs_fpi_external_render.bat +22 -0
  15. excel_codegen/examples/abs_fpi/abs_fpi_external_render.sh +23 -0
  16. excel_codegen/examples/abs_fpi/abs_fpi_internal.xlsx +0 -0
  17. excel_codegen/examples/abs_fpi/abs_fpi_internal.yaml +266 -0
  18. excel_codegen/examples/abs_fpi/abs_fpi_internal_render.bat +22 -0
  19. excel_codegen/examples/abs_fpi/abs_fpi_internal_render.sh +23 -0
  20. excel_codegen/examples/abs_fpi/compose.yaml +20 -0
  21. excel_codegen/examples/abs_fpi/generated/COT1-d20.559-mu60.js +124 -0
  22. excel_codegen/examples/abs_fpi/generated/COT1-d20.559-mu60_summary.md +30 -0
  23. excel_codegen/examples/abs_fpi/generated/EXT-T15-mu0-kf-1.js +91 -0
  24. excel_codegen/examples/abs_fpi/generated/EXT-T15-mu0-kf-1_summary.md +23 -0
  25. excel_codegen/examples/abs_fpi/generated/EXT-T15-mu90-kf+1.js +91 -0
  26. excel_codegen/examples/abs_fpi/generated/EXT-T15-mu90-kf+1_summary.md +23 -0
  27. excel_codegen/examples/abs_fpi/generated/EXT-T20.559-mu90-kf+1.js +91 -0
  28. excel_codegen/examples/abs_fpi/generated/EXT-T20.559-mu90-kf+1_summary.md +23 -0
  29. excel_codegen/examples/abs_fpi/generated/WBT6-d15.059-mu0.js +124 -0
  30. excel_codegen/examples/abs_fpi/generated/WBT6-d15.059-mu0_summary.md +30 -0
  31. excel_codegen/examples/abs_fpi/generated/WBT6-d8-mu90.js +124 -0
  32. excel_codegen/examples/abs_fpi/generated/WBT6-d8-mu90_summary.md +30 -0
  33. excel_codegen/examples/abs_fpi/generated/WBT7-d20.559-mu90.js +124 -0
  34. excel_codegen/examples/abs_fpi/generated/WBT7-d20.559-mu90_summary.md +30 -0
  35. excel_codegen/examples/abs_fpi/templates/ext_body.js.j2 +91 -0
  36. excel_codegen/examples/abs_fpi/templates/ext_summary.md.j2 +23 -0
  37. excel_codegen/examples/abs_fpi/templates/int_body.js.j2 +124 -0
  38. excel_codegen/examples/abs_fpi/templates/int_summary.md.j2 +30 -0
  39. excel_codegen/examples/basic/example.yaml +97 -0
  40. excel_codegen/examples/basic/example_formula.yaml +86 -0
  41. excel_codegen/examples/basic/generated/uart_init_Case1.c +6 -0
  42. excel_codegen/examples/basic/generated/uart_init_Case2.c +6 -0
  43. excel_codegen/examples/basic/generated/uart_summary_Case1.md +4 -0
  44. excel_codegen/examples/basic/generated/uart_summary_Case2.md +4 -0
  45. excel_codegen/examples/basic/generated_formula/uart_init_Case1.c +5 -0
  46. excel_codegen/examples/basic/generated_formula/uart_init_Case2.c +5 -0
  47. excel_codegen/examples/basic/generated_formula/uart_pins_Case1.csv +1 -0
  48. excel_codegen/examples/basic/generated_formula/uart_pins_Case2.csv +1 -0
  49. excel_codegen/examples/basic/template.xlsx +0 -0
  50. excel_codegen/examples/basic/template_formula.xlsx +0 -0
  51. excel_codegen/examples/basic/template_formula_render.bat +22 -0
  52. excel_codegen/examples/basic/template_formula_render.sh +23 -0
  53. excel_codegen/examples/basic/template_render.bat +22 -0
  54. excel_codegen/examples/basic/template_render.sh +23 -0
  55. excel_codegen/examples/nastran/generated/case_control.deck +18 -0
  56. excel_codegen/examples/nastran/generated/cc_01_LC1.inc +8 -0
  57. excel_codegen/examples/nastran/generated/cc_02_LC2.inc +8 -0
  58. excel_codegen/examples/nastran/generated/cc_03_LC3.inc +8 -0
  59. excel_codegen/examples/nastran/generated/cc_04_COMB4.inc +8 -0
  60. excel_codegen/examples/nastran/generated/cc_05_LC5.inc +8 -0
  61. excel_codegen/examples/nastran/generated/cc_summary_01_LC1.md +1 -0
  62. excel_codegen/examples/nastran/generated/cc_summary_02_LC2.md +1 -0
  63. excel_codegen/examples/nastran/generated/cc_summary_03_LC3.md +1 -0
  64. excel_codegen/examples/nastran/generated/cc_summary_04_COMB4.md +1 -0
  65. excel_codegen/examples/nastran/generated/cc_summary_05_LC5.md +1 -0
  66. excel_codegen/examples/nastran/nastran_case_control.xlsx +0 -0
  67. excel_codegen/examples/nastran/nastran_case_control.yaml +141 -0
  68. excel_codegen/examples/nastran/nastran_case_control_render.bat +22 -0
  69. excel_codegen/examples/nastran/nastran_case_control_render.sh +23 -0
  70. excel_codegen/excel_io.py +1885 -0
  71. excel_codegen/formula.py +674 -0
  72. excel_codegen/formula_eval.py +685 -0
  73. excel_codegen/jinja_env.py +92 -0
  74. excel_codegen/models.py +1008 -0
  75. excel_codegen/renderer.py +558 -0
  76. excel_codegen/utils.py +225 -0
  77. excel_codegen-0.9.0.dist-info/METADATA +179 -0
  78. excel_codegen-0.9.0.dist-info/RECORD +82 -0
  79. excel_codegen-0.9.0.dist-info/WHEEL +5 -0
  80. excel_codegen-0.9.0.dist-info/entry_points.txt +2 -0
  81. excel_codegen-0.9.0.dist-info/licenses/LICENSE +21 -0
  82. excel_codegen-0.9.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,8 @@
1
+ SUBCASE 2
2
+
3
+ SUBTITLE = BEAM SEA
4
+
5
+
6
+ LOAD = 1002
7
+ SPC = 1
8
+
@@ -0,0 +1,8 @@
1
+ SUBCASE 3
2
+ LABEL = QTR
3
+ SUBTITLE = QUARTERING SEA
4
+
5
+ METHOD = 1
6
+ LOAD = 1003
7
+ SPC = 2
8
+
@@ -0,0 +1,8 @@
1
+ SUBCOM 4
2
+
3
+ SUBTITLE = COMBINED 1.0 / 1.2 / 1.3
4
+
5
+
6
+
7
+
8
+ SUBSEQ = 1, 1.2, 1.3
@@ -0,0 +1 @@
1
+ SUBCASE 1 | SUBTITLE=HEAD SEA | METHOD= | LOAD=1001 | SPC=1 | SUBSEQ=
@@ -0,0 +1 @@
1
+ SUBCASE 2 | SUBTITLE=BEAM SEA | METHOD= | LOAD=1002 | SPC=1 | SUBSEQ=
@@ -0,0 +1 @@
1
+ SUBCASE 3 | SUBTITLE=QUARTERING SEA | METHOD=1 | LOAD=1003 | SPC=2 | SUBSEQ=
@@ -0,0 +1 @@
1
+ SUBCOM 4 | SUBTITLE=COMBINED 1.0 / 1.2 / 1.3 | METHOD= | LOAD= | SPC= | SUBSEQ=1, 1.2, 1.3
@@ -0,0 +1 @@
1
+ SUBCASE 5 | SUBTITLE= | METHOD= | LOAD= | SPC= | SUBSEQ=
@@ -0,0 +1,141 @@
1
+ version: 1
2
+
3
+ # =========================================================================== #
4
+ # 示例:生成 NASTRAN 工况控制语句(Case Control)
5
+ #
6
+ # 为什么要用 local_direction: vertical(指南 §19):
7
+ # 工况控制语句在工程实践里就是"一行一个子工况、一列一条语句"的形态
8
+ # (SUBCASE / SUBTITLE / LOAD / SPC / SUBSEQ …),通常是从别处(表格、文本、
9
+ # 另一个软件)整块拿到的。竖向的 Local 表可以**直接整块粘贴**,不用逐列转置;
10
+ # 而生成的代码仍然横着排(direction: horizontal),方便并排比较。
11
+ #
12
+ # 引擎用 engine: excel(**公式模式**):Code 表里写的是 Excel 公式,改 Global / Local
13
+ # 里的参数后**打开 Excel 就重算**,不需要跑任何命令 —— 也可以直接把一列参数粘进去。
14
+ # 代价是模板只能用"占位符 + 单行 {% if %}"(指南 §14.1.1)。
15
+ #
16
+ # 每一条语句都是**可选的**:留空就不输出。
17
+ # 模板里用 `{% if x.value %}` 判断(公式模式的条件必须写 .value),一条语句占一行:
18
+ # 条件不成立时那一格是**空的**(Excel 里就没有这条语句的文本),
19
+ # 所以一行只填 subcase_id 也是合法的,输出就只有一条 `SUBCASE n`。
20
+ #
21
+ # 注意:Excel 里"空语句"是一格空单元格(横向布局下这一行是所有工况共用的,
22
+ # 没法为某个工况单独删掉一整行)。把一列粘到文本编辑器后删掉空行即可:
23
+ # excel-codegen render -c nastran_case_control.yaml --outdir deck
24
+ # sed '/^$/d' deck/cc_*.inc > deck/case_control.deck
25
+ # 快照模式(engine: snapshot)能用"把换行写进 if 里面"的办法完全不留空行 ——
26
+ # 见指南 §20.2;这里为了"改 Excel 就改输出"选了公式模式。
27
+ #
28
+ # 关于语句本身(MSC / NX Nastran 的 Case Control 段):
29
+ # * `SUBCASE n` 开一个子工况;后面的语句作用于它,直到下一个 SUBCASE / SUBCOM;
30
+ # * `SUBCOM n` 开一个**组合**子工况:它不重新定义载荷,而是用 `SUBSEQ` 把已经
31
+ # 定义过的子工况按比例线性组合起来(`SUBSEQ = 1, 1.2, 1.3` 表示子工况
32
+ # 1 / 2 / 3 分别按 1.0 / 1.2 / 1.3 加权 —— 具体写法以手头版本的参考手册为准,
33
+ # 所以这里把它当成一段**原样输出的文本**,工具不解释它);
34
+ # * `SUBTITLE` / `LABEL` / `METHOD` / `LOAD` / `SPC` / `ANALYSIS` 都是子工况级语句。
35
+ #
36
+ # 本示例只生成"子工况块"这一部分。整份输入文件仍然是:
37
+ # SOL 101 / CEND / <本示例生成的各子工况块> / BEGIN BULK
38
+ # 前面的执行控制段与后面的 BULK 段不属于 case control,一笔手写即可。
39
+ # =========================================================================== #
40
+
41
+ excel:
42
+ output: "nastran_case_control.xlsx"
43
+ template_sheet: "Template"
44
+ howto_sheet: "HOWTO"
45
+ # 一个子工况一行(A 列写 Case 名,第 1 行 B 列起写语句名)
46
+ local_direction: "vertical"
47
+ sheets:
48
+ global: "Global Parameter"
49
+ local: "Local Parameter"
50
+ outputs: ["Case Control", "Summary"]
51
+
52
+ variables:
53
+ global:
54
+ - name: analysis
55
+ description: "ANALYSIS 语句的取值(整份模型共用);留空则这条语句不输出"
56
+ # 默认留空:清空 Global 表的这一格就等于"不输出 ANALYSIS"(填 STATICS 才会输出)
57
+ default: ""
58
+ type: string
59
+
60
+ local:
61
+ - name: seq
62
+ description: "排序号:只用来给导出文件排序(建议 01 / 02 …),不进入生成的语句"
63
+ default: "01"
64
+ type: string
65
+ - name: kind
66
+ description: "这一行的类型:SUBCASE(普通子工况)/ SUBCOM(组合子工况)"
67
+ default: "SUBCASE"
68
+ type: string
69
+ choices: ["SUBCASE", "SUBCOM"]
70
+ - name: subcase_id
71
+ description: "子工况编号 [i](SUBCASE / SUBCOM 后面的整数)"
72
+ default: 1
73
+ type: int
74
+ min: 1
75
+ - name: label
76
+ description: "LABEL 语句;留空不输出"
77
+ default: ""
78
+ type: string
79
+ - name: subtitle
80
+ description: "SUBTITLE 语句;留空不输出"
81
+ default: ""
82
+ type: string
83
+ - name: method
84
+ description: "METHOD 语句(实特征值提取方法集号);留空不输出"
85
+ default: ""
86
+ type: string
87
+ - name: load
88
+ description: "LOAD 语句(静力载荷集号);留空不输出"
89
+ default: ""
90
+ type: string
91
+ - name: spc
92
+ description: "SPC 语句(单点约束集号);留空不输出"
93
+ default: ""
94
+ type: string
95
+ - name: subseq
96
+ description: "SUBSEQ 语句的内容,原样输出(如 1, 1.2, 1.3);留空不输出。只有 SUBCOM 用"
97
+ default: ""
98
+ type: string
99
+
100
+ # 组合校验(指南 §3.6):留空的语义是"不输出",所以填错地方不会报错、只会悄悄少一条语句
101
+ asserts:
102
+ - "kind.value != 'SUBCOM' or subseq.value != ''" # 组合子工况必须给 SUBSEQ,否则这一行没有组合信息
103
+ - "kind.value != 'SUBCASE' or subseq.value == ''" # SUBSEQ 只对 SUBCOM 有意义,写在 SUBCASE 行上是笔误
104
+
105
+ templates:
106
+ # --------------------------------------------------------------------- 主产物 --
107
+ # 一个子工况一个 .inc 片段。拼成整段 case control 就是按 seq 顺序连起来
108
+ # (空语句在文件里是空行,删掉即可):
109
+ # excel-codegen render -c nastran_case_control.yaml --outdir deck
110
+ # sed '/^$/d' deck/cc_*.inc > deck/case_control.deck
111
+ - name: case_control
112
+ description: "NASTRAN Case Control 子工况块(每个子工况一列,公式模式)"
113
+ output_sheet: "Case Control"
114
+ start_cell: "B2"
115
+ direction: "horizontal"
116
+ write_case_headers: true
117
+ engine: "excel"
118
+ filename: "cc_{{ seq }}_{{ case_name }}.inc"
119
+ # 一行一条语句 —— 公式模式下每一行编译成一格公式,
120
+ # 所以 {% if %} 必须和它管的语句写在同一行里(多行 {% if %} 公式模式表达不了)。
121
+ code: |
122
+ {{ kind }} {{ subcase_id }}
123
+ {% if label.value %}LABEL = {{ label }}{% endif %}
124
+ {% if subtitle.value %}SUBTITLE = {{ subtitle }}{% endif %}
125
+ {% if analysis.value %}ANALYSIS = {{ analysis }}{% endif %}
126
+ {% if method.value %}METHOD = {{ method }}{% endif %}
127
+ {% if load.value %}LOAD = {{ load }}{% endif %}
128
+ {% if spc.value %}SPC = {{ spc }}{% endif %}
129
+ {% if subseq.value %}SUBSEQ = {{ subseq }}{% endif %}
130
+
131
+ # ----------------------------------------------------------------- 人读的对照表 --
132
+ - name: cc_summary
133
+ description: "工况控制语句一览(一行一个子工况,公式模式)"
134
+ output_sheet: "Summary"
135
+ start_cell: "B2"
136
+ direction: "vertical"
137
+ write_case_headers: true
138
+ engine: "excel"
139
+ filename: "cc_summary_{{ seq }}_{{ case_name }}.md"
140
+ code: |-
141
+ {{ kind }} {{ subcase_id }} | SUBTITLE={{ subtitle }} | METHOD={{ method }} | LOAD={{ load }} | SPC={{ spc }} | SUBSEQ={{ subseq }}
@@ -0,0 +1,22 @@
1
+ @echo off
2
+ REM ===========================================================================
3
+ REM 由 excel_codegen 生成 —— 改完参数双击本文件即可把结果写回 Output 表。
4
+ REM 重新生成工作簿(init)时会一并覆盖本文件。
5
+ REM ===========================================================================
6
+ cd /d "%~dp0"
7
+
8
+ where uv >nul 2>nul
9
+ if %errorlevel%==0 (
10
+ uv run excel-codegen render -c "nastran_case_control.yaml" -x "nastran_case_control.xlsx" --write-excel
11
+ ) else (
12
+ excel-codegen render -c "nastran_case_control.yaml" -x "nastran_case_control.xlsx" --write-excel
13
+ )
14
+
15
+ echo.
16
+ if errorlevel 1 (
17
+ echo [失败] 上面有报错信息。常见原因:依赖没装(跑一次 setup.sh / uv sync)、
18
+ echo 或者 Excel 正开着这个文件(先关掉再试)。
19
+ ) else (
20
+ echo [完成] 回到 Excel 打开「Output」表看结果。
21
+ )
22
+ pause
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # ===========================================================================
3
+ # 由 excel_codegen 生成 —— 改完参数跑一次本文件即可把结果写回 Output 表。
4
+ # 重新生成工作簿(init)时会一并覆盖本文件。
5
+ # ===========================================================================
6
+ set -uo pipefail
7
+ cd "$(dirname "$0")"
8
+
9
+ if command -v uv >/dev/null 2>&1; then
10
+ uv run excel-codegen render -c "nastran_case_control.yaml" -x "nastran_case_control.xlsx" --write-excel
11
+ else
12
+ excel-codegen render -c "nastran_case_control.yaml" -x "nastran_case_control.xlsx" --write-excel
13
+ fi
14
+ status=$?
15
+
16
+ echo
17
+ if [ "$status" -ne 0 ]; then
18
+ echo "[失败] 上面有报错信息。常见原因:依赖没装(跑一次 ./setup.sh 或 uv sync)、"
19
+ echo " 或者 Excel / WPS 正开着这个文件(先关掉再试)。"
20
+ else
21
+ echo "[完成] 回到 Excel 打开「Output」表看结果。"
22
+ fi
23
+ exit "$status"