Coverage for gws-app/gws/spec/spec.py: 0%

25 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Command line tool that runs the spec generator on the developer system.""" 

2 

3import os 

4import sys 

5 

6sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/../../../app')) 

7 

8import gws.lib.cli as cli 

9 

10import gws.spec.generator.main as generator_main 

11 

12USAGE = """ 

13GWS Spec Compiler 

14~~~~~~~~~~~~~~~~~ 

15  

16 python3 spec.py <output-directory> <options> 

17 

18Options: 

19 

20 -root <dir> 

21 application root directory ('app') 

22 

23 -manifest <path> 

24 path to MANIFEST.json 

25 

26 -v 

27 verbose logging 

28""" 

29 

30 

31def main(args): 

32 """Generate the specs and write them to the output directory. 

33 

34 Args: 

35 args: Parsed command line arguments: the output directory as the first 

36 positional argument, and the ``root``, ``manifest`` and ``v`` options. 

37 

38 Raises: 

39 ``generator_main.Error``: If the generator fails; other exceptions are passed through as well. 

40 """ 

41 

42 out_dir = args.get(1) 

43 if not out_dir: 

44 cli.fatal('output directory required') 

45 

46 os.makedirs(out_dir, exist_ok=True) 

47 

48 try: 

49 generator_main.generate_and_write( 

50 out_dir=out_dir, 

51 root_dir=args.get('root'), 

52 manifest_path=args.get('manifest'), 

53 debug=args.get('v')) 

54 

55 except generator_main.Error as e: 

56 cli.error('-' * 40) 

57 cli.error(f'SPEC GENERATOR ERROR: {e.args[0]}') 

58 cli.error('-' * 40) 

59 raise 

60 except Exception as e: 

61 cli.error('-' * 40) 

62 cli.error(f'UNHANDLED SPEC GENERATOR ERROR: {e!r}') 

63 cli.error('-' * 40) 

64 raise 

65 

66 

67if __name__ == '__main__': 

68 cli.main('spec', main, USAGE)