opencos-eda 0.2.51__py3-none-any.whl → 0.2.53__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 (43) hide show
  1. opencos/commands/__init__.py +2 -0
  2. opencos/commands/build.py +1 -1
  3. opencos/commands/deps_help.py +259 -0
  4. opencos/commands/export.py +1 -1
  5. opencos/commands/flist.py +3 -0
  6. opencos/commands/lec.py +1 -1
  7. opencos/commands/open.py +2 -0
  8. opencos/commands/proj.py +1 -1
  9. opencos/commands/shell.py +1 -1
  10. opencos/commands/sim.py +32 -8
  11. opencos/commands/synth.py +1 -1
  12. opencos/commands/upload.py +3 -0
  13. opencos/commands/waves.py +13 -2
  14. opencos/deps/defaults.py +1 -0
  15. opencos/deps/deps_file.py +30 -4
  16. opencos/deps/deps_processor.py +72 -2
  17. opencos/deps_schema.py +3 -0
  18. opencos/eda.py +66 -29
  19. opencos/eda_base.py +159 -20
  20. opencos/eda_config.py +2 -2
  21. opencos/eda_config_defaults.yml +83 -3
  22. opencos/eda_extract_targets.py +1 -58
  23. opencos/tests/helpers.py +16 -0
  24. opencos/tests/test_eda.py +13 -2
  25. opencos/tests/test_tools.py +227 -6
  26. opencos/tools/cocotb.py +492 -0
  27. opencos/tools/modelsim_ase.py +67 -51
  28. opencos/tools/quartus.py +638 -0
  29. opencos/tools/questa.py +167 -88
  30. opencos/tools/questa_fse.py +10 -0
  31. opencos/tools/riviera.py +1 -0
  32. opencos/tools/verilator.py +31 -0
  33. opencos/tools/vivado.py +3 -3
  34. opencos/util.py +22 -3
  35. opencos/utils/str_helpers.py +85 -0
  36. opencos/utils/vscode_helper.py +47 -0
  37. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/METADATA +2 -1
  38. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/RECORD +43 -39
  39. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/WHEEL +0 -0
  40. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/entry_points.txt +0 -0
  41. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/licenses/LICENSE +0 -0
  42. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/licenses/LICENSE.spdx +0 -0
  43. {opencos_eda-0.2.51.dist-info → opencos_eda-0.2.53.dist-info}/top_level.txt +0 -0
opencos/eda_base.py CHANGED
@@ -26,7 +26,7 @@ from opencos import eda_config
26
26
 
27
27
  from opencos.util import Colors
28
28
  from opencos.utils.str_helpers import sprint_time, strip_outer_quotes, string_or_space, \
29
- indent_wrap_long_text
29
+ indent_wrap_long_text, pretty_list_columns_manual
30
30
  from opencos.utils.subprocess_helpers import subprocess_run_background
31
31
  from opencos.utils import status_constants
32
32
 
@@ -68,6 +68,17 @@ def get_argparser_short_help() -> str:
68
68
  return util.get_argparser_short_help(parser=get_argparser())
69
69
 
70
70
 
71
+ def get_argparsers_args_list() -> list:
72
+ '''Returns list of all args that we know about from eda_config, util, eda.
73
+
74
+ All items will include the -- prefix (--help, etc)'''
75
+ return util.get_argparsers_args_list(parsers=[
76
+ eda_config.get_argparser(),
77
+ util.get_argparser(),
78
+ get_argparser()
79
+ ])
80
+
81
+
71
82
  def get_eda_exec(command: str = '') -> str:
72
83
  '''Returns the full path of `eda` executable to be used for a given eda <command>'''
73
84
  # NOTE(drew): This is kind of flaky. 'eda multi' reinvokes 'eda'. But the executable for 'eda'
@@ -184,7 +195,7 @@ class Tool:
184
195
  return
185
196
 
186
197
 
187
- class Command:
198
+ class Command: # pylint: disable=too-many-public-methods
188
199
  '''Base class for all: eda <command>
189
200
 
190
201
  The Command class should be used when you don't require files, otherwise consider
@@ -245,6 +256,8 @@ class Command:
245
256
  self.target_path = ""
246
257
  self.status = 0
247
258
  self.errors_log_f = None
259
+ self.auto_tool_applied = False
260
+ self.tool_changed_respawn = {}
248
261
 
249
262
 
250
263
  def error(self, *args, **kwargs) -> None:
@@ -267,7 +280,7 @@ class Command:
267
280
  typ='text', description='EDA reported errors'
268
281
  )
269
282
 
270
- except FileNotFoundError:
283
+ except Exception:
271
284
  pass
272
285
  if self.errors_log_f:
273
286
  print(
@@ -277,6 +290,18 @@ class Command:
277
290
 
278
291
  self.status = util.error(*args, **kwargs) # error_code passed and returned via kwargs
279
292
 
293
+ def stop_process_tokens_before_do_it(self) -> bool:
294
+ '''Used by derived classes process_tokens() to know an error was reached
295
+ and to not perform the command (avoid calling do_it())
296
+
297
+ Also used to know if a DEPS target requested a --tool=<value> change and that
298
+ we should respawn the job.'''
299
+ util.debug('stop_process_tokens_before_do_it:',
300
+ f'{self.status=} {self.tool_changed_respawn=} {self.args.get("tool", "")=}')
301
+ if self.tool_changed_respawn or self.status_any_error():
302
+ return True
303
+ return False
304
+
280
305
  def status_any_error(self, report=True) -> bool:
281
306
  '''Used by derived classes process_tokens() to know an error was reached
282
307
  and to not perform the command. Necessary for pytests that use eda.main()'''
@@ -288,6 +313,26 @@ class Command:
288
313
  '''Returns a str for the tool name used for the requested command'''
289
314
  return which_tool(command, config=self.config)
290
315
 
316
+ def safe_which_tool(self, command: str = '') -> str:
317
+ '''Returns a str for the tool name used for the requested command,
318
+
319
+ avoids NotImplementedError (for CommandMulti)'''
320
+
321
+ if getattr(self, '_TOOL', ''):
322
+ return self._TOOL
323
+
324
+ if not command:
325
+ command = getattr(self, 'command_name', '')
326
+
327
+ try:
328
+ if getattr(self, 'which_tool', None):
329
+ return self.which_tool(command)
330
+ except NotImplementedError:
331
+ pass
332
+
333
+ return which_tool(command, config=self.config)
334
+
335
+
291
336
  def create_work_dir( # pylint: disable=too-many-branches,too-many-statements
292
337
  self
293
338
  ) -> str:
@@ -361,7 +406,7 @@ class Command:
361
406
  # Do not allow other absolute path work dirs if it already exists.
362
407
  # This prevents you from --work-dir=~ and eda wipes out your home dir.
363
408
  self.error(f'Cannot use work-dir={self.args["work-dir"]} starting with',
364
- 'fabsolute path "/"')
409
+ 'absolute path "/"')
365
410
  elif str(Path('..')) in str(Path(self.args['work-dir'])):
366
411
  # Do not allow other ../ work dirs if it already exists.
367
412
  self.error(f'Cannot use work-dir={self.args["work-dir"]} with up-hierarchy'
@@ -370,9 +415,16 @@ class Command:
370
415
  # If we made it this far, on a directory that exists, that appears safe
371
416
  # to delete and re-create:
372
417
  util.info(f"Removing previous '{self.args['work-dir']}'")
373
- shutil.rmtree(self.args['work-dir'])
374
- util.safe_mkdir(self.args['work-dir'])
375
- util.debug(f'create_work_dir: created {self.args["work-dir"]}')
418
+ try:
419
+ shutil.rmtree(self.args['work-dir'])
420
+ util.safe_mkdir(self.args['work-dir'])
421
+ util.debug(f'create_work_dir: created {self.args["work-dir"]}')
422
+ except PermissionError as e:
423
+ self.error('Could not remove existing dir and create new due to filesystem',
424
+ f'PermissionError: {self.args["work-dir"]}; exception: {e}')
425
+ except Exception as e:
426
+ self.error('Could not remove existing dir and create new due to internal',
427
+ f'Exception: {self.args["work-dir"]}; exception: {e}')
376
428
  else:
377
429
  util.safe_mkdir(self.args['work-dir'])
378
430
  util.debug(f'create_work_dir: created {self.args["work-dir"]}')
@@ -492,12 +544,14 @@ class Command:
492
544
 
493
545
 
494
546
  def get_argparser( # pylint: disable=too-many-branches
495
- self, parser_arg_list=None
547
+ self, parser_arg_list=None, support_underscores: bool = True,
496
548
  ) -> argparse.ArgumentParser:
497
549
  ''' Returns an argparse.ArgumentParser() based on self.args (dict)
498
550
 
499
551
  If parser_arg_list is not None, the ArgumentParser() is created using only the keys in
500
552
  self.args provided by the list parser_arg_list.
553
+
554
+ If support_underscores=False, then only return an ArgumentParser() with --arg-posix-dashes
501
555
  '''
502
556
 
503
557
  # Preference is --args-with-dashes, which then become parsed.args_with_dashes, b/c
@@ -519,9 +573,9 @@ class Command:
519
573
  util.warning(f'{key=} has _ chars, prefer -')
520
574
 
521
575
  keys = [key] # make a list
522
- if '_' in key:
576
+ if support_underscores and '_' in key:
523
577
  keys.append(key.replace('_', '-')) # switch to POSIX dashes for argparse
524
- elif '-' in key:
578
+ elif support_underscores and '-' in key:
525
579
  keys.append(key.replace('-', '_')) # also support --some_arg_with_underscores
526
580
 
527
581
  arguments = [] # list supplied to parser.add_argument(..) so one liner supports both.
@@ -546,7 +600,7 @@ class Command:
546
600
  # be --some-bool or --no-some-bool.
547
601
  parser.add_argument(
548
602
  *arguments, default=None, **bool_action_kwargs, **help_kwargs)
549
- elif isinstance(value, list):
603
+ elif isinstance(value, (list, set)):
550
604
  parser.add_argument(*arguments, default=value, action='append', **help_kwargs)
551
605
  elif isinstance(value, (int, str)):
552
606
  parser.add_argument(*arguments, default=value, type=type(value), **help_kwargs)
@@ -637,7 +691,8 @@ class Command:
637
691
  '''
638
692
 
639
693
  _, unparsed = self.run_argparser_on_list(tokens)
640
- if process_all and len(unparsed) > 0:
694
+ if process_all and unparsed:
695
+ self.warning_show_known_args()
641
696
  self.error(f"Didn't understand argument: '{unparsed=}' in",
642
697
  f" {self.command_name=} context, {pwd=}",
643
698
  error_code=status_constants.EDA_COMMAND_OR_ARGS_ERROR)
@@ -718,7 +773,7 @@ class Command:
718
773
 
719
774
 
720
775
  def help( # pylint: disable=dangerous-default-value,too-many-branches
721
- self, tokens: list = []
776
+ self, tokens: list = [], no_targets: bool = False
722
777
  ) -> None:
723
778
  '''Since we don't quite follow standard argparger help()/usage(), we'll format our own
724
779
 
@@ -733,7 +788,10 @@ class Command:
733
788
  # using bare 'print' here, since help was requested, avoids --color and --quiet
734
789
  print()
735
790
  print('Usage:')
736
- print(f' eda [options] {self.command_name} [options] [files|targets, ...]')
791
+ if no_targets:
792
+ print(f' eda [options] {self.command_name} [options]')
793
+ else:
794
+ print(f' eda [options] {self.command_name} [options] [files|targets, ...]')
737
795
  print()
738
796
 
739
797
  print_base_help()
@@ -780,6 +838,53 @@ class Command:
780
838
  if unparsed:
781
839
  print(f'Unparsed args: {unparsed}')
782
840
 
841
+ def get_argparsers_args_list(self) -> list:
842
+ '''Returns list of all args that we know about from eda_config, util, eda, and our self.args
843
+
844
+ All items will include the -- prefix (--help, etc)'''
845
+ return util.get_argparsers_args_list(parsers=[
846
+ eda_config.get_argparser(),
847
+ util.get_argparser(),
848
+ get_argparser(),
849
+ self.get_argparser(support_underscores=False)
850
+ ])
851
+
852
+ def pretty_str_known_args(self, command: str = '') -> str:
853
+ '''Returns multiple line column organized string of all known args'''
854
+ _command = command
855
+ if not _command:
856
+ _command = self.command_name
857
+
858
+ _args_list = self.get_argparsers_args_list()
859
+ _pretty_args_list = pretty_list_columns_manual(data=_args_list)
860
+ return (f"Known args for command '{_command}' :\n"
861
+ " " + "\n ".join(_pretty_args_list)
862
+ )
863
+
864
+ def warning_show_known_args(self, command: str = '') -> None:
865
+ '''Print a helpful warning showing available args for this eda command (or commands)'''
866
+
867
+ if not command:
868
+ commands = [self.command_name]
869
+ else:
870
+ commands = command.split() # support for command="multi sim"
871
+
872
+ _tool = self.safe_which_tool(commands[0]) # use first command if > 1 presented
873
+ lines = []
874
+ if _tool:
875
+ lines.append(f"To see all args for command(s) {commands}, tool '{_tool}', run:")
876
+ else:
877
+ lines.append(f"To see all args for command(s) {commands}, run:")
878
+
879
+ for cmd in commands:
880
+ if _tool:
881
+ lines.append(f" eda {cmd} --tool={_tool} --help")
882
+ else:
883
+ lines.append(f" eda {cmd} --help")
884
+
885
+ lines.append(self.pretty_str_known_args(command=commands[-1])) # use last command if > 1
886
+ util.warning("\n".join(lines))
887
+
783
888
 
784
889
  class CommandDesign(Command): # pylint: disable=too-many-instance-attributes
785
890
  '''CommandDesign is the eda base class for command handlers that need to track files.
@@ -1345,10 +1450,11 @@ class CommandDesign(Command): # pylint: disable=too-many-instance-attributes
1345
1450
  plusarg = strip_outer_quotes(token)
1346
1451
  self.process_plusarg(plusarg, pwd=pwd)
1347
1452
  remove_list.append(token)
1453
+
1348
1454
  for x in remove_list:
1349
1455
  unparsed.remove(x)
1350
1456
 
1351
- if not unparsed and self.error_on_no_files_or_targets:
1457
+ if self.error_on_no_files_or_targets and not unparsed:
1352
1458
  # derived classes can set error_on_no_files_or_targets=True
1353
1459
  # For example: CommandSim will error (requires files/targets),
1354
1460
  # CommandWaves does not (files/targets not required)
@@ -1367,13 +1473,27 @@ class CommandDesign(Command): # pylint: disable=too-many-instance-attributes
1367
1473
  util.warning(f"For command '{self.command_name}' no files or targets were",
1368
1474
  f"presented at the command line, so using '{target}' from",
1369
1475
  f"{deps.deps_file}")
1370
- if len(unparsed) == 0:
1476
+ if not unparsed:
1371
1477
  # If unparsed is still empty, then error.
1372
1478
  self.error(f"For command '{self.command_name}' no files or targets were",
1373
1479
  f"presented at the command line: {orig_tokens}",
1374
1480
  error_code=status_constants.EDA_COMMAND_OR_ARGS_ERROR)
1375
1481
 
1376
1482
  # by this point hopefully this is a target ... is it a simple filename?
1483
+
1484
+ # Before we look for files, check for stray --some-arg in unparsed, we don't want to treat
1485
+ # these as potential targets if process_all=True, but someone might have a file named
1486
+ # --my_file.sv, so those are technically allowed until the tool would fail on them.
1487
+ possible_unparsed_args = [
1488
+ x for x in unparsed if x.startswith('--') and not os.path.isfile(x)
1489
+ ]
1490
+ if process_all and possible_unparsed_args:
1491
+ _tool = self.safe_which_tool()
1492
+ self.warning_show_known_args()
1493
+ self.error(f"Didn't understand unparsed args: {possible_unparsed_args}, for command",
1494
+ f"'{self.command_name}', tool '{_tool}'",
1495
+ error_code=status_constants.EDA_COMMAND_OR_ARGS_ERROR)
1496
+
1377
1497
  remove_list = []
1378
1498
  last_potential_top_file = ('', '') # (top, fpath)
1379
1499
  last_potential_top_target = ('', '') # (top, path/to/full-target-name)
@@ -1405,6 +1525,10 @@ class CommandDesign(Command): # pylint: disable=too-many-instance-attributes
1405
1525
 
1406
1526
  # we appear to be dealing with a target name which needs to be resolved (usually
1407
1527
  # recursively)
1528
+ if token.startswith('-'):
1529
+ # We are not going to handle targets that start with a -, it's likely
1530
+ # an unparsed arg.
1531
+ continue
1408
1532
  if token.startswith(os.sep):
1409
1533
  target_name = token # if it's absolute path, don't prepend anything
1410
1534
  else:
@@ -1424,8 +1548,10 @@ class CommandDesign(Command): # pylint: disable=too-many-instance-attributes
1424
1548
  unparsed.remove(x)
1425
1549
 
1426
1550
  # we were unable to figure out what this command line token is for...
1427
- if process_all and len(unparsed) > 0:
1428
- self.error(f"Didn't understand command remaining tokens {unparsed=} in CommandDesign",
1551
+ if process_all and unparsed:
1552
+ self.warning_show_known_args()
1553
+ self.error(f"Didn't understand remaining args or targets {unparsed=} for command",
1554
+ f"'{self.command_name}'",
1429
1555
  error_code=status_constants.EDA_COMMAND_OR_ARGS_ERROR)
1430
1556
 
1431
1557
  # handle a missing self.args['top'] with last filepath or last target:
@@ -1462,6 +1588,14 @@ class CommandDesign(Command): # pylint: disable=too-many-instance-attributes
1462
1588
  f"'{self.command_name}' for tool={self.args.get('tool', None)}",
1463
1589
  error_code=status_constants.EDA_COMMAND_MISSING_TOP)
1464
1590
 
1591
+ if self.tool_changed_respawn:
1592
+ util.warning(
1593
+ 'CommandDesign: need to respawn due to tool change to',
1594
+ f'\'{self.tool_changed_respawn["tool"]}\' from',
1595
+ f'\'{self.tool_changed_respawn["orig_tool"]}\'',
1596
+ f'(from DEPS, {self.tool_changed_respawn["from"]})'
1597
+ )
1598
+
1465
1599
  return unparsed
1466
1600
 
1467
1601
 
@@ -1961,6 +2095,7 @@ class CommandParallel(Command):
1961
2095
  # There should not be any single_cmd_unparsed args starting with '-'
1962
2096
  bad_remaining_args = [x for x in single_cmd_unparsed if x.startswith('-')]
1963
2097
  if bad_remaining_args:
2098
+ self.warning_show_known_args(command=f'{self.command_name} {command}')
1964
2099
  self.error(f'for {self.command_name} {command=} the following args are unknown',
1965
2100
  f'{bad_remaining_args}',
1966
2101
  error_code=status_constants.EDA_COMMAND_OR_ARGS_ERROR)
@@ -2020,8 +2155,12 @@ class CommandParallel(Command):
2020
2155
  tpath, _ = os.path.split(job_dict['target'])
2021
2156
 
2022
2157
  # prepend path information to job-name:
2023
- patched_target_path = os.path.relpath(tpath).replace(os.sep, '_')
2024
- new_job_name = f'{patched_target_path}.{key}'
2158
+ patched_target_path = os.path.relpath(tpath).replace(os.sep, '_').lstrip('.')
2159
+ if patched_target_path:
2160
+ new_job_name = f'{patched_target_path}.{key}'
2161
+ else:
2162
+ continue # there's nothing to "patch", our job-name will be unchanged.
2163
+
2025
2164
  replace_job_arg(job_dict, arg_name='job-name', new_value=new_job_name)
2026
2165
 
2027
2166
  # prepend path information to force-logfile (if present):
opencos/eda_config.py CHANGED
@@ -28,7 +28,7 @@ class Defaults:
28
28
  config_yml = ''
29
29
 
30
30
  supported_config_keys = set([
31
- 'DEFAULT_HANDLERS',
31
+ 'DEFAULT_HANDLERS', 'DEFAULT_HANDLERS_HELP',
32
32
  'defines',
33
33
  'dep_command_enables',
34
34
  'dep_tags_enables',
@@ -46,7 +46,7 @@ class Defaults:
46
46
  supported_config_auto_tools_order_keys = set([
47
47
  'exe', 'handlers',
48
48
  'requires_env', 'requires_py', 'requires_cmd', 'requires_in_exe_path',
49
- 'requires_vsim_helper',
49
+ 'requires_vsim_helper', 'requires_vscode_extension',
50
50
  'disable-tools-multi',
51
51
  ])
52
52
  supported_config_tool_keys = set([
@@ -20,11 +20,33 @@ DEFAULT_HANDLERS:
20
20
  sweep : opencos.commands.CommandSweep
21
21
  flist : opencos.commands.CommandFList
22
22
  # These commands (waves, export, targets) do not require a tool, or
23
- # will self determine the tool:
23
+ # will self determine the tool. See command_tool_is_optional in this config file.
24
24
  waves : opencos.commands.CommandWaves
25
25
  export : opencos.commands.CommandExport
26
26
  shell : opencos.commands.CommandShell
27
27
  targets : opencos.commands.CommandTargets
28
+ deps-help : opencos.commands.CommandDepsHelp
29
+
30
+ DEFAULT_HANDLERS_HELP:
31
+ sim: Simulates a DEPS target.
32
+ elab: Elaborates a DEPS target (lint, tool specific).
33
+ synth: Synthesizes a DEPS target.
34
+ flist: Create dependency from a DEPS target.
35
+ proj: Create a project from a DEPS target for GUI sim/waves/debug.
36
+ multi: Run multiple DEPS targets, serially or in parallel.
37
+ tools-multi: Same as 'multi' but run on all available tools, or specfied using --tools.
38
+ sweep: Sweep one or more arguments across a range, serially or in parallel.
39
+ build: Build for a board, creating a project and running build flow.
40
+ waves: Opens waveform from prior simulation.
41
+ upload: Uploads a finished design into hardware.
42
+ open: Opens a project.
43
+ export: Export files related to a target, tool independent.
44
+ shell: Runs only commands for DEPS target (like sim or elab, but stops prior to tool).
45
+ targets: List all possible targets given glob path.
46
+ lec: Run equivalence on two designs.
47
+ deps-help: Provide help about DEPS markup files, or schema using --verbose or --help.
48
+ help: This help (without args), or i.e. "eda help sim" for specific help.
49
+
28
50
 
29
51
 
30
52
  defines: { } # Add these defines to every eda call
@@ -40,6 +62,7 @@ dep_command_enables:
40
62
  dep_tags_enables:
41
63
  with-tools: true
42
64
  with-args: true
65
+ with-commands: true
43
66
  args: true
44
67
  replace-config-tools: true
45
68
  additive-config-tools: true
@@ -83,6 +106,7 @@ command_tool_is_optional:
83
106
  - flist
84
107
  - export
85
108
  - targets
109
+ - deps-help
86
110
 
87
111
 
88
112
  tools:
@@ -234,6 +258,9 @@ tools:
234
258
  - 2555 # 2555 - assignment to input port myname
235
259
  - 2583 # 2583 - [SVCHK] - Extra checking for conflicts with always_comb and
236
260
  # always_latch variables is done at vopt time.
261
+ - 13159 # 13159, 2685, 2718 are all related to module instance port default values.
262
+ - 2685
263
+ - 2718
237
264
  simulate-waivers:
238
265
  - 3009 # 3009: [TSCALE] - Module 'myname' does not have a timeunit/timeprecision
239
266
  # specification in effect, but other modules do.
@@ -256,6 +283,9 @@ tools:
256
283
  - 2555 # 2555 - assignment to input port myname
257
284
  - 2583 # 2583 - [SVCHK] - Extra checking for conflicts with always_comb and
258
285
  # always_latch variables is done at vopt time.
286
+ - 13159 # 13159, 2685, 2718 are all related to module instance port default values.
287
+ - 2685
288
+ - 2718
259
289
  simulate-waivers:
260
290
  - 3009 # 3009: [TSCALE] - Module 'myname' does not have a timeunit/timeprecision
261
291
  # specification in effect, but other modules do.
@@ -280,6 +310,24 @@ tools:
280
310
  simulate-waves-args: |
281
311
  +trace
282
312
 
313
+ cocotb:
314
+ defines:
315
+ OC_TOOL_COCOTB: null
316
+ log-bad-strings:
317
+ - "ERROR"
318
+ - "FAILED"
319
+ - "AssertionError"
320
+ - "Exception"
321
+ - "Traceback"
322
+ - "COCOTB_TEST_FAILED"
323
+ log-must-strings:
324
+ - "passed"
325
+ - "Cocotb test completed successfully!"
326
+
327
+
328
+ quartus:
329
+ defines:
330
+ OC_TOOL_QUARTUS: null
283
331
 
284
332
  vivado:
285
333
  sim-libraries:
@@ -345,11 +393,32 @@ auto_tools_order:
345
393
  handlers:
346
394
  elab: opencos.tools.invio.CommandElabInvio
347
395
 
396
+ vaporview:
397
+ exe: code
398
+ requires_vscode_extension:
399
+ - lramseyer.vaporview
400
+ handlers: { }
401
+
402
+ surfer:
403
+ exe: code
404
+ requires_vscode_extension:
405
+ - surfer-project.surfer
406
+ handlers: { }
348
407
 
349
408
  gtkwave:
350
409
  exe: gtkwave
351
410
  handlers: { }
352
411
 
412
+ quartus:
413
+ exe: quartus_sh
414
+ handlers:
415
+ synth: opencos.tools.quartus.CommandSynthQuartus
416
+ build: opencos.tools.quartus.CommandBuildQuartus
417
+ flist: opencos.tools.quartus.CommandFListQuartus
418
+ proj: opencos.tools.quartus.CommandProjQuartus
419
+ upload: opencos.tools.quartus.CommandUploadQuartus
420
+ open: opencos.tools.quartus.CommandOpenQuartus
421
+
353
422
  vivado:
354
423
  exe: vivado
355
424
  handlers:
@@ -400,8 +469,9 @@ auto_tools_order:
400
469
  exe: qrun
401
470
  requires_vsim_helper: True
402
471
  handlers:
403
- elab: opencos.tools.queta.CommandElabQuesta
404
- sim: opencos.tools.queta.CommandSimQuesta
472
+ elab: opencos.tools.questa.CommandElabQuesta
473
+ sim: opencos.tools.questa.CommandSimQuesta
474
+ flist: opencos.tools.questa.CommandFListQuesta
405
475
 
406
476
  riviera:
407
477
  exe: vsim
@@ -425,9 +495,19 @@ auto_tools_order:
425
495
  handlers:
426
496
  elab: opencos.tools.questa_fse.CommandElabQuestaFse
427
497
  sim: opencos.tools.questa_fse.CommandSimQuestaFse
498
+ flist: opencos.tools.questa_fse.CommandFListQuestaFse
428
499
 
429
500
  iverilog:
430
501
  exe: iverilog
431
502
  handlers:
432
503
  elab: opencos.tools.iverilog.CommandElabIverilog
433
504
  sim: opencos.tools.iverilog.CommandSimIverilog
505
+
506
+ cocotb:
507
+ exe: python
508
+ requires_cmd:
509
+ - python -c "import cocotb; print(cocotb.__version__)"
510
+ requires_py:
511
+ - cocotb
512
+ handlers:
513
+ sim: opencos.tools.cocotb.CommandSimCocotb
@@ -10,68 +10,11 @@ import os
10
10
  from pathlib import Path
11
11
 
12
12
  from opencos.deps.deps_file import get_all_targets
13
+ from opencos.utils.str_helpers import print_columns_manual
13
14
 
14
15
  PATH_LPREFIX = str(Path('.')) + os.path.sep
15
16
 
16
17
 
17
- def get_terminal_columns():
18
- """
19
- Retrieves the number of columns (width) of the terminal window.
20
-
21
- Returns:
22
- int: The number of columns in the terminal, or a default value (e.g., 80)
23
- if the terminal size cannot be determined.
24
- """
25
- try:
26
- size = os.get_terminal_size()
27
- return size.columns
28
- except OSError:
29
- # Handle cases where the terminal size cannot be determined (e.g., not in a TTY)
30
- return 80 # Default to 80 columns
31
-
32
- return 80 # else default to 80.
33
-
34
-
35
- def print_columns_manual(data: list, num_columns: int = 4, auto_columns: bool = True) -> None:
36
- """Prints a list of strings in columns, manually aligning them."""
37
-
38
- if not data:
39
- print()
40
- return
41
-
42
- _spacing = 2
43
-
44
- # Calculate maximum width for each column
45
- max_lengths = [0] * num_columns
46
- max_item_len = 0
47
- for i, item in enumerate(data):
48
- col_index = i % num_columns
49
- max_lengths[col_index] = max(max_lengths[col_index], len(item))
50
- max_item_len = max(max_item_len, len(item))
51
-
52
- if auto_columns and num_columns > 1:
53
- window_cols = get_terminal_columns()
54
- max_line_len = 0
55
- for x in max_lengths:
56
- max_line_len += x + _spacing
57
- if max_line_len > window_cols:
58
- # subtract a column (already >= 2):
59
- print_columns_manual(data=data, num_columns=num_columns-1, auto_columns=True)
60
- return
61
- if max_line_len + max_item_len + _spacing < window_cols:
62
- # add 1 more column if we're guaranteed to have room.
63
- print_columns_manual(data=data, num_columns=num_columns+1, auto_columns=True)
64
- return
65
- # else continue
66
-
67
- # Print data in columns
68
- for i, item in enumerate(data):
69
- col_index = i % num_columns
70
- print(item.ljust(max_lengths[col_index] + _spacing), end="") # Add padding
71
- if col_index == num_columns - 1 or i == len(data) - 1:
72
- print() # New line at the end of a row or end of data
73
-
74
-
75
18
  def get_path_and_pattern(partial_path: str = '', base_path=str(Path('.'))) -> (str, str):
76
19
  '''Returns tuple of (partial_path, partial_target or filter)'''
77
20
 
opencos/tests/helpers.py CHANGED
@@ -12,6 +12,22 @@ from contextlib import redirect_stdout, redirect_stderr
12
12
  from opencos import eda
13
13
  from opencos import deps_schema
14
14
  from opencos.utils.markup_helpers import yaml_safe_load
15
+ from opencos.utils import status_constants
16
+
17
+
18
+ def eda_wrap_is_sim_fail(rc: int, quiet: bool = False) -> bool:
19
+ '''Because eda_wrap calls eda_main(..) and will continue running
20
+
21
+ after the first error, we may get a higher return code.'''
22
+ if not quiet:
23
+ print(f'eda_wrap_is_sim_fail({rc=})')
24
+ return rc in (
25
+ status_constants.EDA_COMMAND_MISSING_TOP,
26
+ status_constants.EDA_SIM_LOG_HAS_BAD_STRING,
27
+ status_constants.EDA_SIM_LOG_MISSING_MUST_STRING,
28
+ status_constants.EDA_EXEC_NONZERO_RETURN_CODE2,
29
+ status_constants.EDA_DEFAULT_ERROR
30
+ )
15
31
 
16
32
  def can_run_eda_command(*commands, config: dict) -> bool:
17
33
  '''Returns True if we have any installed tool that can run: eda <command>'''
opencos/tests/test_eda.py CHANGED
@@ -589,9 +589,15 @@ class TestDepsResolveErrorMessages(Helpers):
589
589
  assert rc > 1
590
590
  assert self.is_in_log(
591
591
  "Trying to resolve command-line target=./nope_target0: was not",
592
- "found in deps_file=./DEPS.yml, possible targets in deps file = ['foo'",
592
+ "found in deps_file=./DEPS.yml",
593
593
  windows_path_support=True
594
594
  )
595
+ assert self.is_in_log(
596
+ "Targets available in deps_file=./DEPS.yml:",
597
+ windows_path_support=True
598
+ )
599
+ assert self.is_in_log(" foo")
600
+
595
601
 
596
602
  def test_cmd_line_bad1(self):
597
603
  '''EDA calling a non-existent target in DEPS file, with file that exists.'''
@@ -600,9 +606,14 @@ class TestDepsResolveErrorMessages(Helpers):
600
606
  assert rc > 1
601
607
  assert self.is_in_log(
602
608
  "Trying to resolve command-line target=./nope_target1: was not",
603
- "found in deps_file=./DEPS.yml, possible targets in deps file = ['foo'",
609
+ "found in deps_file=./DEPS.yml",
610
+ windows_path_support=True
611
+ )
612
+ assert self.is_in_log(
613
+ "Targets available in deps_file=./DEPS.yml:",
604
614
  windows_path_support=True
605
615
  )
616
+ assert self.is_in_log(" foo")
606
617
 
607
618
  def test_cmd_line_bad2(self):
608
619
  '''EDA calling a non-existent file w/out DEPS'''