Skip to content

Commit fa3e822

Browse files
ssantoluSalvador Santoluctio
andauthored
Users/ssantolu/refactor (#25)
* refactor config settings flow * update version * ran lint tools --------- Co-authored-by: Salvador Santoluctio <salvador.santolucito@ni.com>
1 parent b03b827 commit fa3e822

25 files changed

Lines changed: 1286 additions & 435 deletions

README.md

Lines changed: 235 additions & 45 deletions
Large diffs are not rendered by default.

labview_fpga_hdl_tools/__main__.py

Lines changed: 111 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from . import (
1515
__version__,
1616
check_syntax,
17+
command_hooks,
1718
common,
1819
compile_project,
1920
create_lvbitx,
@@ -40,79 +41,101 @@ def cli(ctx):
4041

4142

4243
@cli.command("migrate-clip", help="Migrate CLIP files for FlexRIO custom devices")
43-
@click.option("--config", default=None, help="Path to INI settings file")
44+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
4445
@click.pass_context
4546
def migrate_clip_cmd(ctx, config):
4647
"""Migrate CLIP files for FlexRIO custom devices."""
4748
try:
48-
result = migrate_clip.migrate_clip(config_path=config)
49+
result = command_hooks.run_with_hooks(
50+
"migrate_clip",
51+
migrate_clip.migrate_clip,
52+
command_config_path=config,
53+
)
4954
return result
5055
except Exception as e:
5156
handle_exception(e)
5257
return 1
5358

5459

5560
@cli.command("install-target", help="Install LabVIEW FPGA target support files")
56-
@click.option("--config", default=None, help="Path to INI settings file")
61+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
5762
@click.pass_context
5863
def install_target_cmd(ctx, config):
5964
"""Install LabVIEW FPGA target support files."""
6065
try:
61-
result = install_labview_target_plugin.install_lv_target_support(config_path=config)
66+
result = command_hooks.run_with_hooks(
67+
"install_target",
68+
install_labview_target_plugin.install_lv_target_support,
69+
command_config_path=config,
70+
)
6271
return result
6372
except Exception as e:
6473
handle_exception(e)
6574
return 1
6675

6776

6877
@cli.command("get-window", help="Extract window netlist from Vivado project")
69-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't run Vivado")
70-
@click.option("--vivado", "--Vivado", "vivado", default=None, help="Override Vivado path")
71-
@click.option("--config", default=None, help="Path to INI settings file")
78+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
7279
@click.pass_context
73-
def get_window_cmd(ctx, test, vivado, config):
80+
def get_window_cmd(ctx, config):
7481
"""Extract window netlist from Vivado project."""
7582
try:
76-
result = get_window_netlist.get_window(test=test, config_path=config, vivado_path=vivado)
83+
result = command_hooks.run_with_hooks(
84+
"get_window",
85+
get_window_netlist.get_window,
86+
command_config_path=config,
87+
)
7788
return result
7889
except Exception as e:
7990
handle_exception(e)
8091
return 1
8192

8293

8394
@cli.command("gen-target", help="Generate LabVIEW FPGA target support files")
84-
@click.option("--config", default=None, help="Path to INI settings file")
95+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
8596
@click.pass_context
8697
def gen_target_cmd(ctx, config):
8798
"""Generate LabVIEW FPGA target support files."""
8899
try:
89-
result = gen_labview_target_plugin.gen_lv_target_support(config_path=config)
100+
result = command_hooks.run_with_hooks(
101+
"gen_target",
102+
gen_labview_target_plugin.gen_lv_target_support,
103+
command_config_path=config,
104+
)
90105
return result
91106
except Exception as e:
92107
handle_exception(e)
93108
return 1
94109

95110

96111
@cli.command("gen-hdl", help="Generate Window VHDL files from CSV/templates")
97-
@click.option("--config", default=None, help="Path to INI settings file")
112+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
98113
@click.pass_context
99114
def gen_hdl_cmd(ctx, config):
100115
"""Generate Window VHDL files only."""
101116
try:
102-
result = gen_labview_target_plugin.gen_window_vhdl(config_path=config)
117+
result = command_hooks.run_with_hooks(
118+
"gen_hdl",
119+
gen_labview_target_plugin.gen_window_vhdl,
120+
command_config_path=config,
121+
)
103122
return result
104123
except Exception as e:
105124
handle_exception(e)
106125
return 1
107126

108127

109128
@cli.command("gen-xdc", help="Generate XDC constraint files from templates")
110-
@click.option("--config", default=None, help="Path to INI settings file")
129+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
111130
@click.pass_context
112131
def gen_xdc_cmd(ctx, config):
113132
"""Generate XDC constraint files from templates."""
114133
try:
115-
result = process_constraints.process_constraints(config_path=config)
134+
result = command_hooks.run_with_hooks(
135+
"gen_xdc",
136+
process_constraints.process_constraints,
137+
command_config_path=config,
138+
)
116139
return result
117140
except Exception as e:
118141
handle_exception(e)
@@ -122,19 +145,17 @@ def gen_xdc_cmd(ctx, config):
122145
@cli.command("create-project", help="Create or update Vivado project")
123146
@click.option("--overwrite", "-o", is_flag=True, help="Overwrite and create a new project")
124147
@click.option("--update", "-u", is_flag=True, help="Update files in the existing project")
125-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't run Vivado")
126-
@click.option("--vivado", "--Vivado", "vivado", default=None, help="Override Vivado path")
127-
@click.option("--config", default=None, help="Path to INI settings file")
148+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
128149
@click.pass_context
129-
def create_project_cmd(ctx, overwrite, update, test, vivado, config):
150+
def create_project_cmd(ctx, overwrite, update, config):
130151
"""Create or update Vivado project."""
131152
try:
132-
result = create_vivado_project.create_project(
153+
result = command_hooks.run_with_hooks(
154+
"create_project",
155+
create_vivado_project.create_project,
156+
command_config_path=config,
133157
overwrite=overwrite,
134158
update=update,
135-
test=test,
136-
config_path=config,
137-
vivado_path=vivado,
138159
)
139160
return result
140161
except Exception as e:
@@ -143,44 +164,50 @@ def create_project_cmd(ctx, overwrite, update, test, vivado, config):
143164

144165

145166
@cli.command("check-syntax", help="Check Vivado RTL syntax and hierarchy quickly")
146-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't run Vivado")
147-
@click.option("--vivado", "--Vivado", "vivado", default=None, help="Override Vivado path")
148-
@click.option("--config", default=None, help="Path to INI settings file")
167+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
149168
@click.pass_context
150-
def check_syntax_cmd(ctx, test, vivado, config):
169+
def check_syntax_cmd(ctx, config):
151170
"""Check Vivado RTL syntax and hierarchy using RTL elaboration."""
152171
try:
153-
result = check_syntax.check_syntax(test=test, config_path=config, vivado_path=vivado)
172+
result = command_hooks.run_with_hooks(
173+
"check_syntax",
174+
check_syntax.check_syntax,
175+
command_config_path=config,
176+
)
154177
return result
155178
except Exception as e:
156179
handle_exception(e)
157180
return 1
158181

159182

160183
@cli.command("compile-project", help="Compile Vivado project and generate a LabVIEW FPGA bitfile")
161-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't run Vivado")
162-
@click.option("--vivado", "--Vivado", "vivado", default=None, help="Override Vivado path")
163-
@click.option("--config", default=None, help="Path to INI settings file")
184+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
164185
@click.pass_context
165-
def compile_project_cmd(ctx, test, vivado, config):
186+
def compile_project_cmd(ctx, config):
166187
"""Compile Vivado project and generate a LabVIEW FPGA bitfile."""
167188
try:
168-
result = compile_project.compile_project(test=test, config_path=config, vivado_path=vivado)
189+
result = command_hooks.run_with_hooks(
190+
"compile_project",
191+
compile_project.compile_project,
192+
command_config_path=config,
193+
)
169194
return result
170195
except Exception as e:
171196
handle_exception(e)
172197
return 1
173198

174199

175200
@cli.command("launch-vivado", help="Launch Vivado with the current project")
176-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't launch Vivado")
177-
@click.option("--vivado", "--Vivado", "vivado", default=None, help="Override Vivado path")
178-
@click.option("--config", default=None, help="Path to INI settings file")
201+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
179202
@click.pass_context
180-
def launch_vivado_cmd(ctx, test, vivado, config):
203+
def launch_vivado_cmd(ctx, config):
181204
"""Launch Vivado with the current project."""
182205
try:
183-
result = launch_vivado.launch_vivado(test=test, config_path=config, vivado_path=vivado)
206+
result = command_hooks.run_with_hooks(
207+
"launch_vivado",
208+
launch_vivado.launch_vivado,
209+
command_config_path=config,
210+
)
184211
return result
185212
except Exception as e:
186213
handle_exception(e)
@@ -191,12 +218,18 @@ def launch_vivado_cmd(ctx, test, vivado, config):
191218
@click.option("--delete", is_flag=True, help="Automatically delete and re-clone without prompting")
192219
@click.option("--pre", is_flag=True, help="Include pre-release versions when resolving versions")
193220
@click.option("--latest", is_flag=True, help="Use latest version for all dependencies")
221+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
194222
@click.pass_context
195-
def install_deps_cmd(ctx, delete, pre, latest):
223+
def install_deps_cmd(ctx, delete, pre, latest, config):
196224
"""Install GitHub dependencies from dependencies.toml."""
197225
try:
198-
result = install_dependencies.install_dependencies(
199-
delete_allowed=delete, allow_prerelease=pre, use_latest=latest
226+
result = command_hooks.run_with_hooks(
227+
"install_deps",
228+
install_dependencies.install_dependencies,
229+
command_config_path=config,
230+
delete_allowed=delete,
231+
allow_prerelease=pre,
232+
use_latest=latest,
200233
)
201234
return result
202235
except Exception as e:
@@ -206,18 +239,16 @@ def install_deps_cmd(ctx, delete, pre, latest):
206239

207240
@cli.command("create-modelsim", help="Create a ModelSim project for simulation")
208241
@click.option("--overwrite", "-o", is_flag=True, help="Overwrite existing ModelSim project")
209-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't create project")
210-
@click.option("--modelsim", default=None, help="Override ModelSim install path")
211-
@click.option("--config", default=None, help="Path to INI settings file")
242+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
212243
@click.pass_context
213-
def create_modelsim_cmd(ctx, overwrite, test, modelsim, config):
244+
def create_modelsim_cmd(ctx, overwrite, config):
214245
"""Create a ModelSim project for HDL simulation."""
215246
try:
216-
result = create_modelsim_project.create_modelsim_project(
247+
result = command_hooks.run_with_hooks(
248+
"create_modelsim",
249+
create_modelsim_project.create_modelsim_project,
250+
command_config_path=config,
217251
overwrite=overwrite,
218-
test=test,
219-
config_path=config,
220-
modelsim_path=modelsim,
221252
)
222253
return result
223254
except Exception as e:
@@ -226,18 +257,16 @@ def create_modelsim_cmd(ctx, overwrite, test, modelsim, config):
226257

227258

228259
@cli.command("launch-modelsim", help="Launch ModelSim with the current project")
229-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't launch")
230260
@click.option("--batch", is_flag=True, help="Run simulation in batch mode (no GUI)")
231-
@click.option("--modelsim", default=None, help="Override ModelSim install path")
232-
@click.option("--config", default=None, help="Path to INI settings file")
261+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
233262
@click.pass_context
234-
def launch_modelsim_cmd(ctx, test, batch, modelsim, config):
263+
def launch_modelsim_cmd(ctx, batch, config):
235264
"""Launch ModelSim with the current project."""
236265
try:
237-
result = launch_modelsim.launch_modelsim(
238-
test=test,
239-
config_path=config,
240-
modelsim_path=modelsim,
266+
result = command_hooks.run_with_hooks(
267+
"launch_modelsim",
268+
launch_modelsim.launch_modelsim,
269+
command_config_path=config,
241270
batch=batch,
242271
)
243272
return result
@@ -247,16 +276,16 @@ def launch_modelsim_cmd(ctx, test, batch, modelsim, config):
247276

248277

249278
@cli.command("sim-modelsim", help="Run ModelSim simulation in batch mode")
250-
@click.option("--test", is_flag=True, help="Test mode - validate settings but don't run")
251279
@click.option("--do-file", default=None, help="Custom .do file to run instead of default")
252-
@click.option("--config", default=None, help="Path to INI settings file")
280+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
253281
@click.pass_context
254-
def sim_modelsim_cmd(ctx, test, do_file, config):
282+
def sim_modelsim_cmd(ctx, do_file, config):
255283
"""Run ModelSim simulation in batch mode and report results."""
256284
try:
257-
result = sim_modelsim.sim_modelsim(
258-
test=test,
259-
config_path=config,
285+
result = command_hooks.run_with_hooks(
286+
"sim_modelsim",
287+
sim_modelsim.sim_modelsim,
288+
command_config_path=config,
260289
do_file=do_file,
261290
)
262291
return result
@@ -266,28 +295,41 @@ def sim_modelsim_cmd(ctx, test, do_file, config):
266295

267296

268297
@cli.command("create-lvbitx", help="Create LabVIEW FPGA bitfile from Vivado output")
269-
@click.option("--test", is_flag=True, help="Test mode - validate settings only")
270-
@click.option("--config", default=None, help="Path to INI settings file")
298+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
271299
@click.pass_context
272-
def create_lvbitx_cmd(ctx, test, config):
300+
def create_lvbitx_cmd(ctx, config):
273301
"""Create LabVIEW FPGA bitfile from Vivado output."""
274302
try:
275-
result = create_lvbitx.create_lv_bitx(test=test, config_path=config)
303+
result = command_hooks.run_with_hooks(
304+
"create_lvbitx",
305+
create_lvbitx.create_lv_bitx,
306+
command_config_path=config,
307+
)
276308
return result
277309
except Exception as e:
278310
handle_exception(e)
279311
return 1
280312

281313

282314
@cli.command("gen-guid", help="Generate a new GUID for LabVIEW FPGA target plugins")
315+
@click.option("--config", default=None, help="Path to nihdlcommandconfig.py")
283316
@click.pass_context
284-
def gen_guid_cmd(ctx):
317+
def gen_guid_cmd(ctx, config):
285318
"""Generate a new GUID for LabVIEW FPGA target plugins."""
286-
try:
319+
320+
def _gen_guid(**kwargs):
287321
guid = common.generate_guid()
288322
print("Generated GUID:", guid)
289323
print("Copy and paste this GUID into LVTargetGUID in the projectsettings.ini file.")
290324
return 0
325+
326+
try:
327+
result = command_hooks.run_with_hooks(
328+
"gen_guid",
329+
_gen_guid,
330+
command_config_path=config,
331+
)
332+
return result
291333
except Exception as e:
292334
handle_exception(e)
293335
return 1

0 commit comments

Comments
 (0)