Coverage for aiocoap/cli/defaults.py: 93%

30 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-15 22:10 +0000

1# SPDX-FileCopyrightText: Christian Amsüss and the aiocoap contributors 

2# 

3# SPDX-License-Identifier: MIT 

4 

5"""This helper script can be used to easily inspect aiocoap's environment 

6autodetection (ie. whether all modules required for particular subsystems are 

7available, losely corresponding to the "features" made available through 

8setup.py); run it as `python3 -m aiocoap.cli.defaults`.""" 

9 

10import sys 

11from aiocoap.meta import version 

12from aiocoap.defaults import ( 

13 has_reuse_port, 

14 get_default_clienttransports, 

15 get_default_servertransports, 

16 missing_module_functions, 

17) 

18import argparse 

19import os 

20 

21 

22def main(argv=None): 

23 p = argparse.ArgumentParser(description=__doc__) 

24 # Allow passing this in as AIOCOAP_DEFAULTS_EXPECT_ALL=1 via the 

25 # environment, as that's easier to set in tox 

26 p.add_argument( 

27 "--expect-all", 

28 help="Exit with an error unless all subsystems are available", 

29 action="store_true", 

30 default=os.environ.get("AIOCOAP_DEFAULTS_EXPECT_ALL") == "1", 

31 ) 

32 p.add_argument("--version", action="version", version=version) 

33 args = p.parse_args(sys.argv[1:] if argv is None else argv) 

34 

35 error = 0 

36 

37 print("Python version: %s" % sys.version) 

38 print("aiocoap version: %s" % version) 

39 print("Modules missing for subsystems:") 

40 for name, f in missing_module_functions.items(): 

41 missing = f() 

42 if missing and args.expect_all: 

43 error = 1 

44 print( 

45 " %s: %s" 

46 % ( 

47 name, 

48 "everything there" if not missing else "missing " + ", ".join(missing), 

49 ) 

50 ) 

51 print("Python platform: %s" % sys.platform) 

52 print( 

53 "Default server transports: %s" 

54 % ":".join(get_default_servertransports(use_env=False)) 

55 ) 

56 print("Selected server transports: %s" % ":".join(get_default_servertransports())) 

57 print( 

58 "Default client transports: %s" 

59 % ":".join(get_default_clienttransports(use_env=False)) 

60 ) 

61 print("Selected client transports: %s" % ":".join(get_default_clienttransports())) 

62 print( 

63 "SO_REUSEPORT available (default, selected): %s, %s" 

64 % (has_reuse_port(use_env=False), has_reuse_port()) 

65 ) 

66 

67 if error: 

68 print( 

69 "Exiting unsuccessfully because --expect-all was set and not all extras are available." 

70 ) 

71 return error 

72 

73 

74if __name__ == "__main__": 

75 sys.exit(main())