@@ -236,6 +236,12 @@ def _(subparsers: argparse._SubParsersAction) -> None:
236236 type = str ,
237237 )
238238
239+ run_parser .add_argument (
240+ "--pyra" ,
241+ help = "Path to the pyramid scheme interpreter" ,
242+ type = str ,
243+ )
244+
239245 run_parser .add_argument ("input" , help = "Input pyramid scheme file." )
240246
241247
@@ -251,6 +257,7 @@ def _(args: argparse.Namespace, extra: list[str]) -> tuple[argparse.Namespace, l
251257 raise ArgumentError ("Input file does not have .pyra extension" )
252258
253259 args .ruby = check_ruby (args .ruby )
260+ args .pyra = check_pyra (args .pyra , args .verbose )
254261
255262 return args , extra
256263
@@ -280,6 +287,12 @@ def _(subparsers: argparse._SubParsersAction) -> None:
280287 type = str ,
281288 )
282289
290+ compile_and_run_parser .add_argument (
291+ "--pyra" ,
292+ help = "Path to the pyramid scheme interpreter" ,
293+ type = str ,
294+ )
295+
283296 compile_and_run_parser .add_argument (
284297 "input" ,
285298 help = ("Input file written in the pyramid scheme (lisp (like)) syntax, with the .psll extension." ),
@@ -303,6 +316,26 @@ def check_ruby(ruby: str) -> str:
303316 return ruby
304317
305318
319+ def check_pyra (pyra : str , verbose : int = 0 ) -> str :
320+ if pyra :
321+ # Check if the specified pyra.rb file exists
322+ if not op .exists (pyra ):
323+ raise ArgumentError (f"Pyra.rb file '{ pyra } ' does not exist." )
324+ if not op .isfile (pyra ):
325+ raise ArgumentError (f"'{ pyra } ' is not a file." )
326+ else :
327+ # Try to find pyra.rb
328+ found_pyra = find_pyra_rb (verbose )
329+ if found_pyra is None :
330+ raise ArgumentError (
331+ "Pyra.rb file not found. Please specify the path to the pyra.rb file."
332+ "Or use the `download-pyra` command to download it."
333+ )
334+ pyra = found_pyra
335+
336+ return pyra
337+
338+
306339@register_validate_options (Subcommand .COMPILE_AND_RUN )
307340def _ (args : argparse .Namespace , extra : list [str ]) -> tuple [argparse .Namespace , list [str ]]:
308341 """Validate options for the compile-and-run subcommand"""
@@ -318,6 +351,7 @@ def _(args: argparse.Namespace, extra: list[str]) -> tuple[argparse.Namespace, l
318351 raise ArgumentError ("Input file does not have .psll extension" )
319352
320353 args .ruby = check_ruby (args .ruby )
354+ args .pyra = check_pyra (args .pyra , args .verbose )
321355
322356 return args , extra
323357
@@ -563,19 +597,14 @@ def _(args: argparse.Namespace, extra: list[str]) -> None:
563597 if args .verbose > 1 :
564598 print ("Ruby version:" , ruby_version )
565599
566- pyra_rb = find_pyra_rb (args .verbose )
567-
568- if pyra_rb is None :
569- raise RuntimeError ("Could not find pyra.rb. Make sure pyramid scheme is installed." )
570-
571600 if args .verbose > 1 :
572- print ("pyra.rb:" , pyra_rb )
601+ print ("pyra.rb:" , args . pyra )
573602
574603 # run pyramid scheme
575604 if args .verbose :
576605 print ("Running pyramid scheme:" )
577606
578- subprocess .run ([args .ruby , pyra_rb , args .input , * extra ])
607+ subprocess .run ([args .ruby , args . pyra , args .input , * extra ])
579608
580609
581610@register_subcommand (Subcommand .COMPILE_AND_RUN )
0 commit comments