openc3-cosmos-script-engine-cstol 1.2.0 → 1.3.0

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cstol_script_engine.py +51 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09b27bfb1b01bd2a21ff41078e7d25e2112d9024d9dfb2ab4663a2bd1b419780'
4
- data.tar.gz: 8fd1660731f16948ea44cd2539408b100f34018534d8e7df47bb045d18ff2984
3
+ metadata.gz: bf6da20d0573092cb540326e468769c97ff84a6c28f13dcf34e35f14de64686c
4
+ data.tar.gz: d2d54f8b7eba61bdc7cf5b3645fc2b6454f3a55d15cc8a7020af981e67f866b0
5
5
  SHA512:
6
- metadata.gz: ee0cf899dd95e9c5aa305a9e228bef5cbaad1d41d357cc76a7eba36b51cdaf16777bf43ac7f7fbea875853319b9b34bedd73c798779a8746056079c047e6e844
7
- data.tar.gz: 4d3600530bec3d984aeb07529ba87d67314254a4233c6bb7bec010a78ac6fce08d5e5c49193af70a50f182e8b95c23b3a5928eeb2e7f44698b0bab34c3f19336
6
+ metadata.gz: ee15613e7146e593cce0b3b4e2bf542433f9b5ab7e5751e28bbea83c6eba04cd891ac92e67c7897eec88b96d2f9d2dea9f30e376ac31ae276d87ca94d0234caa
7
+ data.tar.gz: 2fb8c91c241e6a2047c3382318cd305f74981b66586e2b2ffd1af90541d4b729ef24197cfd2825898a00436dd45aca34fa0dd2531eb29e025f6272e0f3dcd8ee
@@ -123,6 +123,14 @@ class CstolVariables:
123
123
  """
124
124
  return self.local_variables.get(name.upper(), None)
125
125
 
126
+ def has_local_variable(self, name):
127
+ """
128
+ Returns True if the local variable has been set (case insensitive).
129
+ Note this is different from get_local_variable returning None because
130
+ a variable can be legitimately set to None.
131
+ """
132
+ return name.upper() in self.local_variables
133
+
126
134
  def set_special_variable(self, name, value):
127
135
  """
128
136
  Sets a special variable, which is a variable that starts with '$$'.
@@ -765,9 +773,13 @@ class CstolScriptEngine(ScriptEngine):
765
773
  success = False
766
774
  fail_message = f"not equal to {vs_value}"
767
775
  else:
768
- # No VS - Just a print check
776
+ # No VS but could be a relational or logical expression
769
777
  source = " ".join(expr)
770
778
  value = self.evaluate_expression(expr)
779
+ # Relational/logical expressions evaluate to a bool and must be True
780
+ if value is False:
781
+ success = False
782
+ fail_message = "expression is false"
771
783
 
772
784
  formatted_value = self.apply_format(format_spec, value)
773
785
 
@@ -923,6 +935,10 @@ class CstolScriptEngine(ScriptEngine):
923
935
  f"Expected '=' after variable name in DECLARE command at line {line_no}"
924
936
  )
925
937
  default_value = self.evaluate_tokens([tokens[4]])[0]
938
+ if mode == "INPUT" and self.variables.has_local_variable(variable_name):
939
+ # INPUT variables are passed in by the PROC argument list, so the
940
+ # default value is only applied when an argument wasn't given
941
+ return
926
942
  self.variables.set_local_variable(variable_name, default_value)
927
943
 
928
944
  def handle_display(self, tokens, line_no):
@@ -1170,13 +1186,42 @@ class CstolScriptEngine(ScriptEngine):
1170
1186
  if token == ",":
1171
1187
  continue
1172
1188
  elif token.startswith("$"):
1173
- self.variables.set_local_variable(token, os.getenv(f"CSTOL_ARG_{index}"))
1189
+ value = os.getenv(f"CSTOL_ARG_{index}")
1190
+ if value is not None:
1191
+ # START stores the type alongside the value so the local
1192
+ # variable gets the type the caller passed rather than a string
1193
+ value = self.convert_arg(value, os.getenv(f"CSTOL_ARG_{index}_TYPE"))
1194
+ self.variables.set_local_variable(token, value)
1174
1195
  index += 1
1175
1196
  else:
1176
1197
  raise ValueError(
1177
1198
  f"Invalid variable '{token}' in PROC command at line {line_no}"
1178
1199
  )
1179
1200
 
1201
+ @staticmethod
1202
+ def convert_arg(value, type_name):
1203
+ """
1204
+ Converts a CSTOL_ARG environment variable string back into the type it
1205
+ had when START was called. Returns the string unchanged if the type is
1206
+ unknown or the value can't be converted.
1207
+ """
1208
+ try:
1209
+ match type_name:
1210
+ case "int":
1211
+ return int(value)
1212
+ case "float":
1213
+ return float(value)
1214
+ case "complex":
1215
+ return complex(value)
1216
+ case "bool":
1217
+ return value == "True"
1218
+ case "NoneType":
1219
+ return None
1220
+ case _:
1221
+ return value
1222
+ except ValueError:
1223
+ return value
1224
+
1180
1225
  def handle_return(self, tokens, lines, line_no):
1181
1226
  if len(tokens) > 1 and tokens[1].upper() == "ALL":
1182
1227
  raise StopScriptError
@@ -1216,15 +1261,14 @@ class CstolScriptEngine(ScriptEngine):
1216
1261
  # Remove quotes
1217
1262
  proc_name = proc_name[1:-1]
1218
1263
 
1219
- args = []
1220
1264
  if len(tokens) > 2:
1221
1265
  # Handle argument list
1222
1266
  expressions = self.extract_expressions(tokens[2:], ",")
1223
1267
  results = self.evaluate_expressions(expressions)
1224
- args = [str(result) for result in results]
1225
- for index, arg in enumerate(args):
1226
- # Set the environment variable for the argument
1227
- os.environ[f"CSTOL_ARG_{index}"] = arg
1268
+ for index, result in enumerate(results):
1269
+ # Set the environment variables for the argument and its type
1270
+ os.environ[f"CSTOL_ARG_{index}"] = str(result)
1271
+ os.environ[f"CSTOL_ARG_{index}_TYPE"] = type(result).__name__
1228
1272
  start(proc_name, bind_variables=False)
1229
1273
 
1230
1274
  def handle_switch(self, tokens, line_no):
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openc3-cosmos-script-engine-cstol
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenC3, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-17 00:00:00.000000000 Z
11
+ date: 2026-10-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " This plugin provides a script engine to support CSTOL in Script Runner\n"
14
14
  email: