@@ -236,6 +236,13 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat, build_dir
236236else :
237237 DEFAULT_PREFIX = "/usr"
238238
239+
240+ build_option = click .option (
241+ "--build/--no-build" ,
242+ default = True ,
243+ help = "Whether to build or not before executing commands" ,
244+ )
245+
239246build_dir_option = click .option (
240247 "-C" ,
241248 "--build-dir" ,
@@ -447,6 +454,7 @@ def _get_configured_command(command_name):
447454 default = "html" ,
448455 help = f"Format of the gcov report. Can be one of { ', ' .join (e .value for e in GcovReportFormat )} ." ,
449456)
457+ @build_option
450458@build_dir_option
451459@click .pass_context
452460def test (
@@ -459,6 +467,7 @@ def test(
459467 coverage = False ,
460468 gcov = None ,
461469 gcov_format = None ,
470+ build = None ,
462471 build_dir = None ,
463472):
464473 """🔧 Run tests
@@ -541,15 +550,16 @@ def test(
541550 )
542551 raise SystemExit (1 )
543552
544- build_cmd = _get_configured_command ("build" )
545- if build_cmd :
546- click .secho (
547- "Invoking `build` prior to running tests:" , bold = True , fg = "bright_green"
548- )
549- if gcov is not None :
550- ctx .invoke (build_cmd , build_dir = build_dir , gcov = bool (gcov ))
551- else :
552- ctx .invoke (build_cmd , build_dir = build_dir )
553+ if build :
554+ build_cmd = _get_configured_command ("build" )
555+ if build_cmd :
556+ click .secho (
557+ "Invoking `build` prior to running tests:" , bold = True , fg = "bright_green"
558+ )
559+ if gcov is not None :
560+ ctx .invoke (build_cmd , build_dir = build_dir , gcov = bool (gcov ))
561+ else :
562+ ctx .invoke (build_cmd , build_dir = build_dir )
553563
554564 site_path = _set_pythonpath (build_dir )
555565
@@ -647,9 +657,10 @@ def test(
647657 "--code" , "-c" , metavar = "CODE" , help = "Python program passed in as a string"
648658)
649659@click .argument ("gdb_args" , nargs = - 1 )
660+ @build_option
650661@build_dir_option
651662@click .pass_context
652- def gdb (ctx , * , code , gdb_args , build_dir ):
663+ def gdb (ctx , * , code , gdb_args , build = None , build_dir = None ):
653664 """👾 Execute code through GDB
654665
655666 spin gdb -c 'import numpy as np; print(np.__version__)'
@@ -670,12 +681,13 @@ def gdb(ctx, *, code, gdb_args, build_dir):
670681 spin gdb my_tests.py
671682 spin gdb -- my_tests.py --mytest-flag
672683 """
673- build_cmd = _get_configured_command ("build" )
674- if build_cmd :
675- click .secho (
676- "Invoking `build` prior to invoking gdb:" , bold = True , fg = "bright_green"
677- )
678- ctx .invoke (build_cmd , build_dir = build_dir )
684+ if build :
685+ build_cmd = _get_configured_command ("build" )
686+ if build_cmd :
687+ click .secho (
688+ "Invoking `build` prior to invoking gdb:" , bold = True , fg = "bright_green"
689+ )
690+ ctx .invoke (build_cmd , build_dir = build_dir )
679691
680692 _set_pythonpath (build_dir )
681693 gdb_args = list (gdb_args )
@@ -700,21 +712,25 @@ def gdb(ctx, *, code, gdb_args, build_dir):
700712
701713@click .command ()
702714@click .argument ("ipython_args" , nargs = - 1 )
715+ @build_option
703716@build_dir_option
704717@click .pass_context
705- def ipython (ctx , * , ipython_args , build_dir , pre_import = "" ):
718+ def ipython (ctx , * , ipython_args , build = None , build_dir = None , pre_import = "" ):
706719 """💻 Launch IPython shell with PYTHONPATH set
707720
708721 IPYTHON_ARGS are passed through directly to IPython, e.g.:
709722
710723 spin ipython -- -i myscript.py
711724 """
712- build_cmd = _get_configured_command ("build" )
713- if build_cmd :
714- click .secho (
715- "Invoking `build` prior to launching ipython:" , bold = True , fg = "bright_green"
716- )
717- ctx .invoke (build_cmd , build_dir = build_dir )
725+ if build :
726+ build_cmd = _get_configured_command ("build" )
727+ if build_cmd :
728+ click .secho (
729+ "Invoking `build` prior to launching ipython:" ,
730+ bold = True ,
731+ fg = "bright_green" ,
732+ )
733+ ctx .invoke (build_cmd , build_dir = build_dir )
718734
719735 p = _set_pythonpath (build_dir )
720736 if p :
@@ -726,9 +742,10 @@ def ipython(ctx, *, ipython_args, build_dir, pre_import=""):
726742
727743@click .command ()
728744@click .argument ("shell_args" , nargs = - 1 )
745+ @build_option
729746@build_dir_option
730747@click .pass_context
731- def shell (ctx , shell_args = [], build_dir = None ):
748+ def shell (ctx , shell_args = [], build = None , build_dir = None ):
732749 """💻 Launch shell with PYTHONPATH set
733750
734751 SHELL_ARGS are passed through directly to the shell, e.g.:
@@ -738,12 +755,15 @@ def shell(ctx, shell_args=[], build_dir=None):
738755 Ensure that your shell init file (e.g., ~/.zshrc) does not override
739756 the PYTHONPATH.
740757 """
741- build_cmd = _get_configured_command ("build" )
742- if build_cmd :
743- click .secho (
744- "Invoking `build` prior to invoking shell:" , bold = True , fg = "bright_green"
745- )
746- ctx .invoke (build_cmd , build_dir = build_dir )
758+ if build :
759+ build_cmd = _get_configured_command ("build" )
760+ if build_cmd :
761+ click .secho (
762+ "Invoking `build` prior to invoking shell:" ,
763+ bold = True ,
764+ fg = "bright_green" ,
765+ )
766+ ctx .invoke (build_cmd , build_dir = build_dir )
747767
748768 p = _set_pythonpath (build_dir )
749769 if p :
@@ -758,21 +778,25 @@ def shell(ctx, shell_args=[], build_dir=None):
758778
759779@click .command ()
760780@click .argument ("python_args" , nargs = - 1 )
781+ @build_option
761782@build_dir_option
762783@click .pass_context
763- def python (ctx , * , python_args , build_dir ):
784+ def python (ctx , * , python_args , build = None , build_dir = None ):
764785 """🐍 Launch Python shell with PYTHONPATH set
765786
766787 PYTHON_ARGS are passed through directly to Python, e.g.:
767788
768789 spin python -- -c 'import sys; print(sys.path)'
769790 """
770- build_cmd = _get_configured_command ("build" )
771- if build_cmd :
772- click .secho (
773- "Invoking `build` prior to invoking Python:" , bold = True , fg = "bright_green"
774- )
775- ctx .invoke (build_cmd , build_dir = build_dir )
791+ if build :
792+ build_cmd = _get_configured_command ("build" )
793+ if build_cmd :
794+ click .secho (
795+ "Invoking `build` prior to invoking Python:" ,
796+ bold = True ,
797+ fg = "bright_green" ,
798+ )
799+ ctx .invoke (build_cmd , build_dir = build_dir )
776800
777801 p = _set_pythonpath (build_dir )
778802 if p :
@@ -799,10 +823,11 @@ def python(ctx, *, python_args, build_dir):
799823
800824
801825@click .command (context_settings = {"ignore_unknown_options" : True })
826+ @build_option
802827@build_dir_option
803828@click .argument ("args" , nargs = - 1 )
804829@click .pass_context
805- def run (ctx , * , args , build_dir = None ):
830+ def run (ctx , * , args , build = None , build_dir = None ):
806831 """🏁 Run a shell command with PYTHONPATH set
807832
808833 \b
@@ -821,12 +846,13 @@ def run(ctx, *, args, build_dir=None):
821846 if not len (args ) > 0 :
822847 raise RuntimeError ("No command given" )
823848
824- build_cmd = _get_configured_command ("build" )
825- if build_cmd :
826- # Redirect spin generated output
827- with contextlib .redirect_stdout (sys .stderr ):
828- # Also ask build to be quiet
829- ctx .invoke (build_cmd , build_dir = build_dir , quiet = True )
849+ if build :
850+ build_cmd = _get_configured_command ("build" )
851+ if build_cmd :
852+ # Redirect spin generated output
853+ with contextlib .redirect_stdout (sys .stderr ):
854+ # Also ask build to be quiet
855+ ctx .invoke (build_cmd , build_dir = build_dir , quiet = True )
830856
831857 is_posix = sys .platform in ("linux" , "darwin" )
832858 shell = len (args ) == 1
@@ -882,12 +908,6 @@ def attach_sigint():
882908 default = False ,
883909 help = "Clean previously built docs before building" ,
884910)
885- @click .option (
886- "--build/--no-build" ,
887- "first_build" ,
888- default = True ,
889- help = "Build project before generating docs" ,
890- )
891911@click .option (
892912 "--plot/--no-plot" ,
893913 "sphinx_gallery_plot" ,
@@ -901,17 +921,18 @@ def attach_sigint():
901921 metavar = "N_JOBS" ,
902922 help = "Number of parallel build jobs" ,
903923)
924+ @build_option
904925@build_dir_option
905926@click .pass_context
906927def docs (
907928 ctx ,
908929 * ,
909930 sphinx_target ,
910931 clean ,
911- first_build ,
912932 jobs ,
913933 sphinx_gallery_plot ,
914934 clean_dirs = None ,
935+ build = None ,
915936 build_dir = None ,
916937):
917938 """📖 Build Sphinx documentation
@@ -941,7 +962,7 @@ def docs(
941962
942963 if sphinx_target in ("targets" , "help" ):
943964 clean = False
944- first_build = False
965+ build = False
945966 sphinx_target = "help"
946967
947968 if clean :
@@ -963,7 +984,7 @@ def docs(
963984
964985 build_cmd = _get_configured_command ("build" )
965986
966- if build_cmd and first_build :
987+ if build_cmd and build :
967988 click .secho (
968989 "Invoking `build` prior to building docs:" , bold = True , fg = "bright_green"
969990 )
@@ -1007,9 +1028,10 @@ def docs(
10071028 "--code" , "-c" , metavar = "CODE" , help = "Python program passed in as a string"
10081029)
10091030@click .argument ("lldb_args" , nargs = - 1 )
1031+ @build_option
10101032@build_dir_option
10111033@click .pass_context
1012- def lldb (ctx , * , code , lldb_args , build_dir = None ):
1034+ def lldb (ctx , * , code , lldb_args , build = None , build_dir = None ):
10131035 """👾 Execute code through LLDB
10141036
10151037 spin lldb -c 'import numpy as np; print(np.__version__)'
@@ -1032,12 +1054,13 @@ def lldb(ctx, *, code, lldb_args, build_dir=None):
10321054 spin lldb -- --arch x86_64 -- my_tests.py
10331055 spin lldb -c 'import numpy as np; print(np.__version__)' -- --arch x86_64
10341056 """
1035- build_cmd = _get_configured_command ("build" )
1036- if build_cmd :
1037- click .secho (
1038- "Invoking `build` prior to invoking lldb:" , bold = True , fg = "bright_green"
1039- )
1040- ctx .invoke (build_cmd , build_dir = build_dir )
1057+ if build :
1058+ build_cmd = _get_configured_command ("build" )
1059+ if build_cmd :
1060+ click .secho (
1061+ "Invoking `build` prior to invoking lldb:" , bold = True , fg = "bright_green"
1062+ )
1063+ ctx .invoke (build_cmd , build_dir = build_dir )
10411064
10421065 _set_pythonpath (build_dir )
10431066 lldb_args = list (lldb_args )
0 commit comments