From 48e84ff653613a337419dbdda368468ca5839043 Mon Sep 17 00:00:00 2001 From: Michele Alberti <michele.alberti@cea.fr> Date: Thu, 8 Jun 2023 17:17:00 +0200 Subject: [PATCH] [bin] Better python script for faking --version option. Not only it searches for the python module given as first parameter, but it also tries to import it for approximate whether its execution will fail or not (for example, due to a missing dependency). --- bin/abcrown.sh | 4 ++-- bin/{findmodule.py => dummyversion.py} | 20 +++++++++++++++----- bin/dune | 2 +- bin/nnenum.sh | 2 +- config/caisar-detection-data.conf | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) rename bin/{findmodule.py => dummyversion.py} (79%) diff --git a/bin/abcrown.sh b/bin/abcrown.sh index 2d02c29..0eb92f1 100755 --- a/bin/abcrown.sh +++ b/bin/abcrown.sh @@ -23,7 +23,7 @@ if [ "$1" = "--version" ]; then SCRIPT_DIR=$( dirname -- "$0"; ) - $SCRIPT_DIR/findmodule.py "complete_verifier.abcrown" "dummy-version" + $SCRIPT_DIR/dummyversion.py "complete_verifier.abcrown" "dummy-version" else - python3 -m complete_verifier.abcrown "$@" + OMP_NUM_THREADS=1 python3 -m complete_verifier.abcrown "$@" fi diff --git a/bin/findmodule.py b/bin/dummyversion.py similarity index 79% rename from bin/findmodule.py rename to bin/dummyversion.py index 4332bb5..cc9ccf2 100755 --- a/bin/findmodule.py +++ b/bin/dummyversion.py @@ -23,14 +23,24 @@ import sys import importlib +from importlib import import_module module_name = str(sys.argv[1]) -output = str(sys.argv[2]) +dummy_version = str(sys.argv[2]) spec = importlib.util.find_spec(module_name) -if spec is not None: - print(output) - exit(0) -else: +if spec is None: + # [module_name] cannot be found: most likely, the PYTHONPATH has not been + # correctly set up. exit(1) + +# [module_name] has been found. However, this is not sufficient to conclude that +# its interpretation/execution will not fail, e.g., due to unmet dependencies. +try: + import_module(module_name) +except ModuleNotFoundError as error: + exit(1) + +print(dummy_version) +exit(0) \ No newline at end of file diff --git a/bin/dune b/bin/dune index b05c9ab..1200cd3 100644 --- a/bin/dune +++ b/bin/dune @@ -2,6 +2,6 @@ (package caisar) (section bin) (files - (findmodule.py as findmodule.py) + (dummyversion.py as dummyversion.py) (nnenum.sh as nnenum.sh) (abcrown.sh as abcrown.sh))) diff --git a/bin/nnenum.sh b/bin/nnenum.sh index d58856b..bb447de 100755 --- a/bin/nnenum.sh +++ b/bin/nnenum.sh @@ -23,7 +23,7 @@ if [ "$1" = "--version" ]; then SCRIPT_DIR=$( dirname -- "$0"; ) - $SCRIPT_DIR/findmodule.py "nnenum" "dummy-version" + $SCRIPT_DIR/dummyversion.py "nnenum.nnenum" "dummy-version" else OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 -m nnenum.nnenum "$@" fi diff --git a/config/caisar-detection-data.conf b/config/caisar-detection-data.conf index c560676..2aeaa83 100644 --- a/config/caisar-detection-data.conf +++ b/config/caisar-detection-data.conf @@ -108,7 +108,7 @@ command = "%e --device cpu --onnx_path %{nnet-onnx} --vnnlib_path %f --timeout % driver = "%{config}/drivers/abcrown.drv" use_at_auto_level = 1 -[ATP abcrown] +[ATP abcrown-acas] name = "alpha-beta-CROWN" alternative = "ACAS" exec = "abcrown.sh" -- GitLab