4040)
4141from .package import (
4242 AVAILABLE ,
43+ INSTALLED ,
4344 ConcretePackage ,
4445 Follows ,
4546 GithubPackage ,
5253console = Console (theme = Theme ({'markdown.code' : 'green' }))
5354
5455KUP_DIR = os .path .split (os .path .abspath (__file__ ))[0 ] # i.e. /path/to/dir/
56+ VERBOSE = False
5557
5658available_packages : list [GithubPackage ] = [
5759 GithubPackage ('runtimeverification' , 'kup' , PackageName ('kup' )),
@@ -157,7 +159,9 @@ def parse_package_metadata(
157159def get_package_metadata (package : GithubPackage ) -> PackageMetadata :
158160 try :
159161 path , git_token_options = package .repo_path_with_access ()
160- result = nix (['flake' , 'metadata' , path , '--json' ] + git_token_options , is_install = False )
162+ result = nix (
163+ ['flake' , 'metadata' , path , '--json' ] + git_token_options , is_install = False , refresh = True , verbose = VERBOSE
164+ )
161165 except Exception :
162166 rich .print ('❗ [red]Could not get package metadata!' )
163167 sys .exit (1 )
@@ -371,7 +375,7 @@ def list_package(package_name: str, show_inputs: bool, show_status: bool) -> Non
371375 else '\033 [3mlocal checkout\033 [0m'
372376 if type (p ) == LocalPackage
373377 else '' ,
374- p .status if type (p ) == ConcretePackage else AVAILABLE ,
378+ p .status if type (p ) == ConcretePackage else INSTALLED if type ( p ) == LocalPackage else AVAILABLE ,
375379 ]
376380 for alias , p in packages .items ()
377381 ]
@@ -453,8 +457,6 @@ def install_package(
453457 package_name : PackageName ,
454458 package_version : Optional [str ],
455459 package_overrides : List [List [str ]],
456- verbose : bool ,
457- refresh : bool ,
458460) -> None :
459461 reload_packages ()
460462 if package_name .base not in packages :
@@ -472,13 +474,13 @@ def install_package(
472474 rich .print (f" ⌛ Fetching cached version of '[green]{ package_name .pretty_name } [/]' ..." )
473475 nix (
474476 ['copy' , '--from' , K_FRAMEWORK_BINARY_CACHE , pinned_package_cache [package .uri ]],
475- verbose = verbose ,
477+ verbose = VERBOSE ,
476478 )
477479 if package_name .base in installed_packages :
478480 nix (['profile' , 'remove' , str (package .index )], is_install = False )
479481 nix (
480482 ['profile' , 'install' , pinned_package_cache [package .uri ]],
481- verbose = verbose ,
483+ verbose = VERBOSE ,
482484 )
483485 else :
484486 rich .print (f" ⌛ Building '[green]{ package_name .pretty_name } [/]' ..." )
@@ -489,16 +491,15 @@ def install_package(
489491 ['build' , package .uri , '--no-link' ] + overrides + git_token_options ,
490492 extra_substituters = package .substituters ,
491493 extra_public_keys = package .public_keys ,
492- verbose = verbose ,
493- refresh = refresh ,
494+ verbose = VERBOSE ,
494495 )
495496 if package_name .base in installed_packages :
496497 nix (['profile' , 'remove' , str (package .index )], is_install = False )
497498 nix (
498499 ['profile' , 'install' , package .uri ] + overrides + git_token_options ,
499500 extra_substituters = package .substituters ,
500501 extra_public_keys = package .public_keys ,
501- verbose = verbose ,
502+ verbose = VERBOSE ,
502503 )
503504
504505 verb = 'updated' if package_name .base in installed_packages else 'installed'
@@ -610,7 +611,9 @@ def add_new_package(
610611 nix (
611612 ['flake' , 'metadata' , path , '--json' ] + git_token_options ,
612613 is_install = False ,
614+ refresh = True ,
613615 exit_on_error = False ,
616+ verbose = VERBOSE ,
614617 )
615618 else :
616619 rich .print ('Detected a private repository without a GitHub access token, using git+ssh...' )
@@ -619,7 +622,9 @@ def add_new_package(
619622 nix (
620623 ['flake' , 'metadata' , path , '--json' ] + git_token_options ,
621624 is_install = False ,
625+ refresh = True ,
622626 exit_on_error = False ,
627+ verbose = VERBOSE ,
623628 )
624629 except Exception :
625630 rich .print (
@@ -739,7 +744,7 @@ def publish_package(cache: str, uri_or_path_with_package_name: str, keep_days: O
739744 git_url = giturlparse .parse (output .decode ('utf8' ).strip ())
740745 owner = git_url .owner
741746 repo = git_url .name
742- result = nix (['flake' , 'metadata' , uri_or_path , '--json' ], is_install = False )
747+ result = nix (['flake' , 'metadata' , uri_or_path , '--json' ], is_install = False , refresh = True , verbose = VERBOSE )
743748 except Exception :
744749 rich .print ('❗ [red]Could not get package metadata!' )
745750 sys .exit (1 )
@@ -751,7 +756,7 @@ def publish_package(cache: str, uri_or_path_with_package_name: str, keep_days: O
751756 sys .exit (1 )
752757 elif uri_or_path .startswith ('github:' ):
753758 try :
754- result = nix (['flake' , 'metadata' , uri_or_path , '--json' ], is_install = False )
759+ result = nix (['flake' , 'metadata' , uri_or_path , '--json' ], is_install = False , refresh = True , verbose = VERBOSE )
755760 except Exception :
756761 rich .print ('❗ [red]Could not get package metadata!' )
757762 sys .exit (1 )
@@ -770,7 +775,7 @@ def publish_package(cache: str, uri_or_path_with_package_name: str, keep_days: O
770775 sys .exit (1 )
771776 cache_key = f'github:{ owner } /{ repo } /{ rev } #{ PackageName (package_name )} '
772777 try :
773- result = nix (['build' , f'{ uri } #{ PackageName (package_name )} ' , '--no-link' , '--json' ])
778+ result = nix (['build' , f'{ uri } #{ PackageName (package_name )} ' , '--no-link' , '--json' ], verbose = VERBOSE )
774779 build_meta = json .loads (result )
775780 except Exception :
776781 rich .print ('❗ [red]Could not build package!' )
@@ -833,6 +838,7 @@ def __call__(
833838
834839
835840def main () -> None :
841+ global VERBOSE
836842 parser = ArgumentParser (
837843 description = 'The K Framework installer' ,
838844 prog = 'kup' ,
@@ -845,18 +851,18 @@ def main() -> None:
845851 """
846852 ),
847853 )
854+ verbose_arg = ArgumentParser (add_help = False )
855+ verbose_arg .add_argument ('-v' , '--verbose' , action = 'store_true' , help = 'verbose output from nix' )
848856 shared_args = ArgumentParser (add_help = False )
849857 shared_args .add_argument ('package' , type = str )
850858 shared_args .add_argument ('--version' , type = str , help = 'install the given version of the package' )
851859 shared_args .add_argument (
852860 '--override' , type = str , nargs = 2 , action = 'append' , help = 'override an input dependency of a package'
853861 )
854- shared_args .add_argument ('--verbose' , '-v' , default = False , action = 'store_true' , help = 'verbose output from nix.' )
855- shared_args .add_argument (
856- '--refresh' , default = False , action = 'store_true' , help = 'force a re-fetch when pulling from a GitHub branch'
857- )
858862 subparser = parser .add_subparsers (dest = 'command' )
859- list = subparser .add_parser ('list' , help = 'show the active and installed K semantics' , add_help = False )
863+ list = subparser .add_parser (
864+ 'list' , help = 'show the active and installed K semantics' , add_help = False , parents = [verbose_arg ]
865+ )
860866 list .add_argument ('package' , nargs = '?' , default = 'all' , type = str )
861867 list .add_argument ('--inputs' , action = 'store_true' , help = 'show the input dependencies of the selected package' )
862868 list .add_argument (
@@ -867,22 +873,26 @@ def main() -> None:
867873 list .add_argument ('-h' , '--help' , action = _HelpListAction )
868874
869875 install = subparser .add_parser (
870- 'install' , help = 'download and install the stated package' , add_help = False , parents = [shared_args ]
876+ 'install' , help = 'download and install the stated package' , add_help = False , parents = [verbose_arg , shared_args ]
871877 )
872878 install .add_argument ('-h' , '--help' , action = _HelpInstallAction )
873879
874- uninstall = subparser .add_parser ('uninstall' , help = "remove the given package from the user's PATH" )
880+ uninstall = subparser .add_parser (
881+ 'uninstall' , help = "remove the given package from the user's PATH" , parents = [verbose_arg ]
882+ )
875883 uninstall .add_argument ('package' , type = str )
876- uninstall .add_argument ('--verbose' , action = 'store_true' , help = 'verbose output from nix' )
877884
878885 shell = subparser .add_parser (
879- 'shell' , help = 'add the selected package to the current shell (temporary)' , add_help = False , parents = [shared_args ]
886+ 'shell' ,
887+ help = 'add the selected package to the current shell (temporary)' ,
888+ add_help = False ,
889+ parents = [verbose_arg , shared_args ],
880890 )
881891 shell .add_argument ('-h' , '--help' , action = _HelpShellAction )
882892
883- subparser .add_parser ('doctor' , help = 'check if kup is installed correctly' )
893+ subparser .add_parser ('doctor' , help = 'check if kup is installed correctly' , parents = [ verbose_arg ] )
884894
885- add = subparser .add_parser ('add' , help = 'add a private package to kup' , add_help = False )
895+ add = subparser .add_parser ('add' , help = 'add a private package to kup' , add_help = False , parents = [ verbose_arg ] )
886896 add .add_argument ('uri' , type = str )
887897 add .add_argument ('package' , type = str )
888898 add .add_argument (
@@ -898,16 +908,21 @@ def main() -> None:
898908 add .add_argument ('--strict' , action = 'store_true' , help = 'check if the package being added exists' )
899909 add .add_argument ('-h' , '--help' , action = _HelpAddAction )
900910
901- publish = subparser .add_parser ('publish' , help = 'push a package to a cachix cache' )
911+ publish = subparser .add_parser ('publish' , help = 'push a package to a cachix cache' , parents = [ verbose_arg ] )
902912 publish .add_argument ('cache' , type = str )
903913 publish .add_argument ('uri' , type = str )
904914 publish .add_argument ('--keep-days' , type = int , help = 'keep package cached for N days' )
905915
906916 subparser .add_parser (
907- 'gc' , help = 'Call Nix garbage collector to remove previously uninstalled packages' , add_help = False
917+ 'gc' ,
918+ help = 'Call Nix garbage collector to remove previously uninstalled packages' ,
919+ add_help = False ,
920+ parents = [verbose_arg ],
908921 )
909922
910923 args = parser .parse_args ()
924+ if args .verbose :
925+ VERBOSE = True
911926
912927 if args .command is None :
913928 parser .print_help ()
@@ -941,7 +956,7 @@ def main() -> None:
941956 list_package (package_name .base , args .inputs , args .status )
942957
943958 elif args .command == 'install' :
944- install_package (package_name , args .version , args .override , args . verbose , args . refresh )
959+ install_package (package_name , args .version , args .override )
945960 elif args .command == 'uninstall' :
946961 uninstall_package (package_name .base )
947962 elif args .command == 'add' :
@@ -974,11 +989,11 @@ def main() -> None:
974989 rich .print (f" ⌛ Fetching cached version of '[green]{ package_name .pretty_name } [/]' ..." )
975990 nix (
976991 ['copy' , '--from' , K_FRAMEWORK_BINARY_CACHE , pinned_package_cache [package .uri ]],
977- verbose = args . verbose ,
992+ verbose = VERBOSE ,
978993 )
979994 nix_detach (
980995 ['shell' , pinned_package_cache [package .uri ]],
981- verbose = args . verbose ,
996+ verbose = VERBOSE ,
982997 )
983998 else :
984999 rich .print (f" ⌛ Building '[green]{ package_name .pretty_name } [/]' ..." )
@@ -987,8 +1002,7 @@ def main() -> None:
9871002 ['shell' , package .uri ] + overrides + git_token_options ,
9881003 extra_substituters = package .substituters ,
9891004 extra_public_keys = package .public_keys ,
990- verbose = args .verbose ,
991- refresh = args .refresh ,
1005+ verbose = VERBOSE ,
9921006 )
9931007
9941008
0 commit comments