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

29 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-16 16:09 +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 has_reuse_port, get_default_clienttransports, \ 

13 get_default_servertransports, missing_module_functions 

14import argparse 

15import os 

16 

17if __name__ == "__main__": 

18 p = argparse.ArgumentParser(description=__doc__) 

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

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

21 p.add_argument("--expect-all", help="Exit with an error unless all subsystems are available", 

22 action='store_true', default=os.environ.get('AIOCOAP_DEFAULTS_EXPECT_ALL') == '1') 

23 p.add_argument('--version', action='version', version=version) 

24 args = p.parse_args() 

25 

26 error = 0 

27 

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

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

30 print("Modules missing for subsystems:") 

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

32 missing = f() 

33 if missing and args.expect_all: 

34 error = 1 

35 print(" %s: %s" % (name, "everything there" if not missing else "missing " + ", ".join(missing))) 

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

37 print("Default server transports: %s" % ":".join(get_default_servertransports(use_env=False))) 

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

39 print("Default client transports: %s" % ":".join(get_default_clienttransports(use_env=False))) 

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

41 print("SO_REUSEPORT available (default, selected): %s, %s" % (has_reuse_port(use_env=False), has_reuse_port())) 

42 

43 if error: 

44 print("Exiting unsuccessfully because --expect-all was set and not all extras are available.") 

45 sys.exit(error)