Skip to content

Commit 6c0b7a7

Browse files
committed
more robust check for Python modules during 'scons configure'; warn, do not fail if 'pbs' not installed
1 parent 36bb503 commit 6c0b7a7

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

SConstruct

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# http://www.scons.org/doc/production/HTML/scons-user.html
22
# This is: Sconstruct
33

4-
import os, glob, copy, shutil, subprocess, imp, re
4+
import sys, os, glob, copy, shutil, subprocess, imp, re
55

66
from os.path import join
77

@@ -575,13 +575,24 @@ if 'configure' in COMMAND_LINE_TARGETS:
575575
def check_module(module_name):
576576
print "Checking for Python module '" + module_name + "'... ",
577577
try:
578-
imp.find_module(module_name)
579-
res = 1
580-
print "yes"
581-
except:
582-
res = 0
583-
print "no"
584-
return res
578+
res = imp.find_module(module_name)
579+
if res:
580+
print "yes"
581+
return 1
582+
except ImportError:
583+
pass
584+
for item in sys.path:
585+
importer = sys.path_importer_cache.get(item)
586+
if importer:
587+
try:
588+
result = importer.find_module(module_name, [item])
589+
if result:
590+
print "yes"
591+
return 1
592+
except ImportError:
593+
pass
594+
print "no"
595+
return 0
585596

586597
conf = Configure(
587598
env.Clone(LIBPATH=install_lib_paths,
@@ -619,12 +630,12 @@ if 'configure' in COMMAND_LINE_TARGETS:
619630
if not check_module(module_name):
620631
if_failed("Python module '" + module_name + "' is not installed")
621632
if not check_module('pbs'):
622-
if_failed("""
623-
Python module '%s' is not installed
633+
print """
634+
Python module 'pbs' is not installed
624635
This module is only necessary for setting up and submitting DFT jobs
625636
**It is not the module available from pip**"
626637
It is available from: https://github.com/prisms-center/pbs
627-
""" % module_name)
638+
"""
628639

629640

630641
print "Configuration checks passed."

0 commit comments

Comments
 (0)