Coverage for aiocoap/cli/defaults.py: 93%
30 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-16 19:02 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-16 19:02 +0000
1# SPDX-FileCopyrightText: Christian Amsüss and the aiocoap contributors
2#
3# SPDX-License-Identifier: MIT
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 its extras (as described in pyproject.toml
8or the installation documentation).
10Run it as `python3 -m aiocoap.cli.defaults`."""
12import sys
13from aiocoap.meta import version
14from aiocoap.defaults import (
15 has_reuse_port,
16 get_default_clienttransports,
17 get_default_servertransports,
18 missing_module_functions,
19)
20import argparse
21import os
24def main(argv=None):
25 p = argparse.ArgumentParser(description=__doc__)
26 # Allow passing this in as AIOCOAP_DEFAULTS_EXPECT_ALL=1 via the
27 # environment, as that's easier to set in tox
28 p.add_argument(
29 "--expect-all",
30 help="Exit with an error unless all subsystems are available",
31 action="store_true",
32 default=os.environ.get("AIOCOAP_DEFAULTS_EXPECT_ALL") == "1",
33 )
34 p.add_argument("--version", action="version", version=version)
35 args = p.parse_args(sys.argv[1:] if argv is None else argv)
37 error = 0
39 print("Python version: %s" % sys.version)
40 print("aiocoap version: %s" % version)
41 print("Modules missing for subsystems:")
42 for name, f in missing_module_functions.items():
43 missing = f()
44 if missing and args.expect_all:
45 error = 1
46 print(
47 " %s: %s"
48 % (
49 name,
50 "everything there" if not missing else "missing " + ", ".join(missing),
51 )
52 )
53 print("Python platform: %s" % sys.platform)
54 print(
55 "Default server transports: %s"
56 % ":".join(get_default_servertransports(use_env=False))
57 )
58 print("Selected server transports: %s" % ":".join(get_default_servertransports()))
59 print(
60 "Default client transports: %s"
61 % ":".join(get_default_clienttransports(use_env=False))
62 )
63 print("Selected client transports: %s" % ":".join(get_default_clienttransports()))
64 print(
65 "SO_REUSEPORT available (default, selected): %s, %s"
66 % (has_reuse_port(use_env=False), has_reuse_port())
67 )
69 if error:
70 print(
71 "Exiting unsuccessfully because --expect-all was set and not all extras are available."
72 )
73 return error
76if __name__ == "__main__":
77 sys.exit(main())