ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
importTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Standard Python modules
3 import argparse
4 import os
5 import sys
6 
7 parser = argparse.ArgumentParser()
8 parser.add_argument(
9  "name",
10  type=str,
11  help="Library name (example: libpackage.so). Note: This script must be run in the same dir as the library.",
12 )
13 args = parser.parse_args()
14 
15 # Make sure the executing directory is always in the PATH before importing
16 sys.path.insert(0, os.getcwd())
17 
18 # Only get the filename without the extension
19 name = os.path.splitext(args.name)[0]
20 print(f"Testing if module {name} can be imported...")
21 
22 try:
23  import_cmd = f"import {name}"
24  exec(import_cmd)
25 except ImportError as e:
26  print(f"Error: {e}")
27  print(f"Error: library {args.name} was not imported correctly")
28  sys.exit(1)
29 
30 print(f"Module {name} was successfully imported")