summaryrefslogtreecommitdiffstats
path: root/tests/packaging/dependencies.py
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2024-09-30 15:34:11 +0200
committerVladimír Čunát <vladimir.cunat@nic.cz>2024-09-30 15:34:11 +0200
commit3b815e8f6989d64ce1facaa24dd0f94c585b819d (patch)
tree48943e52d37bdb89b313dc6ba5320eb7c19ef140 /tests/packaging/dependencies.py
parentfixup! defer: add request and idle timeouts, limit on waiting queries (diff)
parentMerge branch 'python-constants-module' into 'master' (diff)
downloadknot-resolver-3b815e8f6989d64ce1facaa24dd0f94c585b819d.tar.xz
knot-resolver-3b815e8f6989d64ce1facaa24dd0f94c585b819d.zip
Merge branch 'master' into rrl-wip
Diffstat (limited to 'tests/packaging/dependencies.py')
-rwxr-xr-xtests/packaging/dependencies.py33
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)