diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2024-09-30 15:34:11 +0200 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2024-09-30 15:34:11 +0200 |
commit | 3b815e8f6989d64ce1facaa24dd0f94c585b819d (patch) | |
tree | 48943e52d37bdb89b313dc6ba5320eb7c19ef140 /tests/packaging/dependencies.py | |
parent | fixup! defer: add request and idle timeouts, limit on waiting queries (diff) | |
parent | Merge branch 'python-constants-module' into 'master' (diff) | |
download | knot-resolver-3b815e8f6989d64ce1facaa24dd0f94c585b819d.tar.xz knot-resolver-3b815e8f6989d64ce1facaa24dd0f94c585b819d.zip |
Merge branch 'master' into rrl-wip
Diffstat (limited to 'tests/packaging/dependencies.py')
-rwxr-xr-x | tests/packaging/dependencies.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/packaging/dependencies.py b/tests/packaging/dependencies.py new file mode 100755 index 00000000..1262d2e1 --- /dev/null +++ b/tests/packaging/dependencies.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import importlib +import importlib.util +import sys +from types import ModuleType + +import pkg_resources + +# replace imports with mocks +dummy = ModuleType("dummy") +dummy.__dict__["setup"] = lambda *args, **kwargs: None +dummy.__dict__["build"] = lambda *args, **kwargs: None +sys.modules["setuptools"] = dummy +sys.modules["build_c_extensions"] = dummy + +# load install_requires array from setup.py +spec = importlib.util.spec_from_file_location("setup", sys.argv[1] if len(sys.argv) == 2 else "setup.py") +mod = importlib.util.module_from_spec(spec) +spec.loader.exec_module(mod) +install_requires = mod.install_requires + +# strip version codes +deps = set((x[: x.index(">")].lower() if ">" in x else x.lower() for x in install_requires)) + +# find out which packages are missing +installed = {pkg.key for pkg in pkg_resources.working_set} +missing = deps - installed + +# fail if there are some missing +if len(missing) > 0: + print(f"Some required packages are missing: {missing}", file=sys.stderr) + exit(1) |