Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/apps/pyrocko.py: 0%

49 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6''' 

7Pyrocko - package introspection. 

8''' 

9 

10import sys 

11import logging 

12 

13logger = logging.getLogger('main') 

14 

15 

16def main(args=None): 

17 ''' 

18 CLI entry point for Pyrocko's ``pyrocko`` app. 

19 ''' 

20 logging.basicConfig( 

21 level=logging.INFO, 

22 format='pyrocko:%(name)-25s - %(levelname)-8s - %(message)s') 

23 

24 try: 

25 from pyrocko import squirrel 

26 

27 class PrintVersion(squirrel.SquirrelCommand): 

28 def make_subparser(self, subparsers): 

29 return subparsers.add_parser( 

30 'version', 

31 help='Print version.', 

32 description='Print version.') 

33 

34 def setup(self, parser): 

35 parser.add_argument( 

36 '--long', 

37 dest='long', 

38 action='store_true', 

39 help='Print long version string.') 

40 

41 def run(self, parser, args): 

42 import pyrocko 

43 if args.long: 

44 print(pyrocko.long_version) 

45 else: 

46 print(pyrocko.__version__) 

47 

48 class PrintDependencies(squirrel.SquirrelCommand): 

49 def make_subparser(self, subparsers): 

50 return subparsers.add_parser( 

51 'dependencies', 

52 help='Print versions of available dependencies.', 

53 description='Print versions of available dependencies.') 

54 

55 def setup(self, parser): 

56 pass 

57 

58 def run(self, parser, args): 

59 from pyrocko import deps 

60 deps.print_dependencies() 

61 

62 class PrintInfo(squirrel.SquirrelCommand): 

63 def make_subparser(self, subparsers): 

64 return subparsers.add_parser( 

65 'info', 

66 help='Print information about Pyrocko installation(s).', 

67 description='Print information about Pyrocko ' 

68 'installation(s).') 

69 

70 def setup(self, parser): 

71 pass 

72 

73 def run(self, parser, args): 

74 from pyrocko import deps 

75 print() 

76 print('Python executable:\n %s' % sys.executable) 

77 print() 

78 deps.print_installations() 

79 

80 squirrel.run( 

81 args=args, 

82 prog='pyrocko', 

83 subcommands=[ 

84 PrintVersion(), 

85 PrintDependencies(), 

86 PrintInfo()], 

87 description='Tools for seismology.') 

88 

89 except ImportError as e: 

90 from pyrocko import deps 

91 logger.info('\n' + deps.str_dependencies()) 

92 logger.info('\n' + deps.str_installations()) 

93 

94 try: 

95 deps.require_all('required') 

96 

97 except deps.MissingPyrockoDependency as e2: 

98 logger.fatal(str(e2)) 

99 sys.exit(1) 

100 

101 logger.fatal(str(e)) 

102 sys.exit(1) 

103 

104 

105if __name__ == '__main__': 

106 main()