@@ -236,6 +236,16 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat, build_dir
236
236
else :
237
237
DEFAULT_PREFIX = "/usr"
238
238
239
+
240
+ build_option = click .option (
241
+ "--no-build" ,
242
+ "build" ,
243
+ is_flag = True ,
244
+ callback = lambda ctx , param , value : not value , # store opposite value in `build` var
245
+ default = False ,
246
+ help = "Disable building before executing command" ,
247
+ )
248
+
239
249
build_dir_option = click .option (
240
250
"-C" ,
241
251
"--build-dir" ,
@@ -447,6 +457,7 @@ def _get_configured_command(command_name):
447
457
default = "html" ,
448
458
help = f"Format of the gcov report. Can be one of { ', ' .join (e .value for e in GcovReportFormat )} ." ,
449
459
)
460
+ @build_option
450
461
@build_dir_option
451
462
@click .pass_context
452
463
def test (
@@ -459,6 +470,7 @@ def test(
459
470
coverage = False ,
460
471
gcov = None ,
461
472
gcov_format = None ,
473
+ build = None ,
462
474
build_dir = None ,
463
475
):
464
476
"""🔧 Run tests
@@ -541,15 +553,16 @@ def test(
541
553
)
542
554
raise SystemExit (1 )
543
555
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 )
556
+ if build :
557
+ build_cmd = _get_configured_command ("build" )
558
+ if build_cmd :
559
+ click .secho (
560
+ "Invoking `build` prior to running tests:" , bold = True , fg = "bright_green"
561
+ )
562
+ if gcov is not None :
563
+ ctx .invoke (build_cmd , build_dir = build_dir , gcov = bool (gcov ))
564
+ else :
565
+ ctx .invoke (build_cmd , build_dir = build_dir )
553
566
554
567
site_path = _set_pythonpath (build_dir )
555
568
@@ -647,9 +660,10 @@ def test(
647
660
"--code" , "-c" , metavar = "CODE" , help = "Python program passed in as a string"
648
661
)
649
662
@click .argument ("gdb_args" , nargs = - 1 )
663
+ @build_option
650
664
@build_dir_option
651
665
@click .pass_context
652
- def gdb (ctx , * , code , gdb_args , build_dir ):
666
+ def gdb (ctx , * , code , gdb_args , build = None , build_dir = None ):
653
667
"""👾 Execute code through GDB
654
668
655
669
spin gdb -c 'import numpy as np; print(np.__version__)'
@@ -670,12 +684,13 @@ def gdb(ctx, *, code, gdb_args, build_dir):
670
684
spin gdb my_tests.py
671
685
spin gdb -- my_tests.py --mytest-flag
672
686
"""
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 )
687
+ if build :
688
+ build_cmd = _get_configured_command ("build" )
689
+ if build_cmd :
690
+ click .secho (
691
+ "Invoking `build` prior to invoking gdb:" , bold = True , fg = "bright_green"
692
+ )
693
+ ctx .invoke (build_cmd , build_dir = build_dir )
679
694
680
695
_set_pythonpath (build_dir )
681
696
gdb_args = list (gdb_args )
@@ -700,21 +715,25 @@ def gdb(ctx, *, code, gdb_args, build_dir):
700
715
701
716
@click .command ()
702
717
@click .argument ("ipython_args" , nargs = - 1 )
718
+ @build_option
703
719
@build_dir_option
704
720
@click .pass_context
705
- def ipython (ctx , * , ipython_args , build_dir , pre_import = "" ):
721
+ def ipython (ctx , * , ipython_args , build = None , build_dir = None , pre_import = "" ):
706
722
"""💻 Launch IPython shell with PYTHONPATH set
707
723
708
724
IPYTHON_ARGS are passed through directly to IPython, e.g.:
709
725
710
726
spin ipython -- -i myscript.py
711
727
"""
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 )
728
+ if build :
729
+ build_cmd = _get_configured_command ("build" )
730
+ if build_cmd :
731
+ click .secho (
732
+ "Invoking `build` prior to launching ipython:" ,
733
+ bold = True ,
734
+ fg = "bright_green" ,
735
+ )
736
+ ctx .invoke (build_cmd , build_dir = build_dir )
718
737
719
738
p = _set_pythonpath (build_dir )
720
739
if p :
@@ -726,9 +745,10 @@ def ipython(ctx, *, ipython_args, build_dir, pre_import=""):
726
745
727
746
@click .command ()
728
747
@click .argument ("shell_args" , nargs = - 1 )
748
+ @build_option
729
749
@build_dir_option
730
750
@click .pass_context
731
- def shell (ctx , shell_args = [], build_dir = None ):
751
+ def shell (ctx , shell_args = [], build = None , build_dir = None ):
732
752
"""💻 Launch shell with PYTHONPATH set
733
753
734
754
SHELL_ARGS are passed through directly to the shell, e.g.:
@@ -738,12 +758,15 @@ def shell(ctx, shell_args=[], build_dir=None):
738
758
Ensure that your shell init file (e.g., ~/.zshrc) does not override
739
759
the PYTHONPATH.
740
760
"""
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 )
761
+ if build :
762
+ build_cmd = _get_configured_command ("build" )
763
+ if build_cmd :
764
+ click .secho (
765
+ "Invoking `build` prior to invoking shell:" ,
766
+ bold = True ,
767
+ fg = "bright_green" ,
768
+ )
769
+ ctx .invoke (build_cmd , build_dir = build_dir )
747
770
748
771
p = _set_pythonpath (build_dir )
749
772
if p :
@@ -758,21 +781,25 @@ def shell(ctx, shell_args=[], build_dir=None):
758
781
759
782
@click .command ()
760
783
@click .argument ("python_args" , nargs = - 1 )
784
+ @build_option
761
785
@build_dir_option
762
786
@click .pass_context
763
- def python (ctx , * , python_args , build_dir ):
787
+ def python (ctx , * , python_args , build = None , build_dir = None ):
764
788
"""🐍 Launch Python shell with PYTHONPATH set
765
789
766
790
PYTHON_ARGS are passed through directly to Python, e.g.:
767
791
768
792
spin python -- -c 'import sys; print(sys.path)'
769
793
"""
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 )
794
+ if build :
795
+ build_cmd = _get_configured_command ("build" )
796
+ if build_cmd :
797
+ click .secho (
798
+ "Invoking `build` prior to invoking Python:" ,
799
+ bold = True ,
800
+ fg = "bright_green" ,
801
+ )
802
+ ctx .invoke (build_cmd , build_dir = build_dir )
776
803
777
804
p = _set_pythonpath (build_dir )
778
805
if p :
@@ -799,10 +826,11 @@ def python(ctx, *, python_args, build_dir):
799
826
800
827
801
828
@click .command (context_settings = {"ignore_unknown_options" : True })
829
+ @build_option
802
830
@build_dir_option
803
831
@click .argument ("args" , nargs = - 1 )
804
832
@click .pass_context
805
- def run (ctx , * , args , build_dir = None ):
833
+ def run (ctx , * , args , build = None , build_dir = None ):
806
834
"""🏁 Run a shell command with PYTHONPATH set
807
835
808
836
\b
@@ -821,12 +849,13 @@ def run(ctx, *, args, build_dir=None):
821
849
if not len (args ) > 0 :
822
850
raise RuntimeError ("No command given" )
823
851
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 )
852
+ if build :
853
+ build_cmd = _get_configured_command ("build" )
854
+ if build_cmd :
855
+ # Redirect spin generated output
856
+ with contextlib .redirect_stdout (sys .stderr ):
857
+ # Also ask build to be quiet
858
+ ctx .invoke (build_cmd , build_dir = build_dir , quiet = True )
830
859
831
860
is_posix = sys .platform in ("linux" , "darwin" )
832
861
shell = len (args ) == 1
@@ -882,12 +911,6 @@ def attach_sigint():
882
911
default = False ,
883
912
help = "Clean previously built docs before building" ,
884
913
)
885
- @click .option (
886
- "--build/--no-build" ,
887
- "first_build" ,
888
- default = True ,
889
- help = "Build project before generating docs" ,
890
- )
891
914
@click .option (
892
915
"--plot/--no-plot" ,
893
916
"sphinx_gallery_plot" ,
@@ -901,17 +924,18 @@ def attach_sigint():
901
924
metavar = "N_JOBS" ,
902
925
help = "Number of parallel build jobs" ,
903
926
)
927
+ @build_option
904
928
@build_dir_option
905
929
@click .pass_context
906
930
def docs (
907
931
ctx ,
908
932
* ,
909
933
sphinx_target ,
910
934
clean ,
911
- first_build ,
912
935
jobs ,
913
936
sphinx_gallery_plot ,
914
937
clean_dirs = None ,
938
+ build = None ,
915
939
build_dir = None ,
916
940
):
917
941
"""📖 Build Sphinx documentation
@@ -941,7 +965,7 @@ def docs(
941
965
942
966
if sphinx_target in ("targets" , "help" ):
943
967
clean = False
944
- first_build = False
968
+ build = False
945
969
sphinx_target = "help"
946
970
947
971
if clean :
@@ -963,7 +987,7 @@ def docs(
963
987
964
988
build_cmd = _get_configured_command ("build" )
965
989
966
- if build_cmd and first_build :
990
+ if build_cmd and build :
967
991
click .secho (
968
992
"Invoking `build` prior to building docs:" , bold = True , fg = "bright_green"
969
993
)
@@ -1007,9 +1031,10 @@ def docs(
1007
1031
"--code" , "-c" , metavar = "CODE" , help = "Python program passed in as a string"
1008
1032
)
1009
1033
@click .argument ("lldb_args" , nargs = - 1 )
1034
+ @build_option
1010
1035
@build_dir_option
1011
1036
@click .pass_context
1012
- def lldb (ctx , * , code , lldb_args , build_dir = None ):
1037
+ def lldb (ctx , * , code , lldb_args , build = None , build_dir = None ):
1013
1038
"""👾 Execute code through LLDB
1014
1039
1015
1040
spin lldb -c 'import numpy as np; print(np.__version__)'
@@ -1032,12 +1057,13 @@ def lldb(ctx, *, code, lldb_args, build_dir=None):
1032
1057
spin lldb -- --arch x86_64 -- my_tests.py
1033
1058
spin lldb -c 'import numpy as np; print(np.__version__)' -- --arch x86_64
1034
1059
"""
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 )
1060
+ if build :
1061
+ build_cmd = _get_configured_command ("build" )
1062
+ if build_cmd :
1063
+ click .secho (
1064
+ "Invoking `build` prior to invoking lldb:" , bold = True , fg = "bright_green"
1065
+ )
1066
+ ctx .invoke (build_cmd , build_dir = build_dir )
1041
1067
1042
1068
_set_pythonpath (build_dir )
1043
1069
lldb_args = list (lldb_args )
0 commit comments