check if module has __version__ attribute before the check
This commit is contained in:
@@ -21,6 +21,11 @@ def notinstalled(modulename):
|
||||
return modulename + """ is not installed for \"""" + sys.executable + """\"
|
||||
Run \"""" + sys.executable + """ setup.py install --user\" to install it"""
|
||||
|
||||
def absent_version(module, modulename):
|
||||
return """You are using a """ + modulename + """ module that doesn't have a __version__ attribute : """ + inspect.getfile(module) + """\"
|
||||
Run \"""" + sys.executable + """ setup.py install --user\" to upgrade.
|
||||
If the problem persists, remove the site-package that contains \"""" + inspect.getfile(module) + """\". You can do so either manually or by using pip."""
|
||||
|
||||
def wrong_version(module, modulename, required_version, installed_version):
|
||||
return """You are using """ + modulename + """-""" + installed_version + """ : """ + inspect.getfile(module) + """, while the required version is : """ + required_version + """
|
||||
Run \"""" + sys.executable + """ setup.py install --user\" to upgrade.
|
||||
@@ -30,6 +35,10 @@ def log_error_and_exit(error_message):
|
||||
logging.error(error_message)
|
||||
raise SystemExit
|
||||
|
||||
def check_absent_version(module, modulename):
|
||||
if not hasattr(module, '__version__'):
|
||||
log_error_and_exit(absent_version(module, modulename))
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = OptionParser('Log level')
|
||||
parser.add_option('-l','--log',type='string',help='Available levels are CRITICAL (3), ERROR (2), WARNING (1), INFO (0), DEBUG (-1)',default='INFO')
|
||||
@@ -72,6 +81,7 @@ if __name__ == '__main__':
|
||||
|
||||
#check ortools version
|
||||
try:
|
||||
check_absent_version(ortools, "ortools")
|
||||
if required_ortools_version != ortools.__version__:
|
||||
raise Exception
|
||||
logging.info("or-tools version : " + ortools.__version__ + "\n" + inspect.getfile(ortools))
|
||||
@@ -80,6 +90,7 @@ if __name__ == '__main__':
|
||||
|
||||
#check protobuf version
|
||||
try:
|
||||
check_absent_version(google.protobuf, "protobuf")
|
||||
if required_protobuf_version != google.protobuf.__version__:
|
||||
raise Exception
|
||||
logging.info("protobuf version : " + google.protobuf.__version__+ "\n" + inspect.getfile(google.protobuf) )
|
||||
|
||||
Reference in New Issue
Block a user