Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tickets/DM-5018: Modernize python code #1

Merged
merged 3 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions scripts/check_matplotlib
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
# Minimum supported version is 1.2.0
#

from __future__ import print_function
import sys

# See if matplotlib is installed in the first place
try:
import matplotlib as mpl;
import matplotlib as mpl
except ImportError:
print >>sys.stderr, "error: matplotlib is not installed. please install matplotlib v1.5.1 or later and try again."
sys.exit(-1)
print("error: matplotlib is not installed. Please install matplotlib v1.5.1 or later and try again.",
file=sys.stderr)
sys.exit(-1)

# See if the version is compatible
(major, minor, pl) = [ int(s) for s in (mpl.__version__ + ".0.0.0").split('.')[:3] ]
(major, minor, pl) = [int(s) for s in (mpl.__version__ + ".0.0.0").split('.')[:3]]
if (major < 1) or (major == 1 and minor < 2) or (major == 1 and minor == 2 and pl < 0):
print >>sys.stderr, "error: matplotlib version too old (%s). please install matplotlib v1.2.0 or later and try again." % mpl.__version__
sys.exit(-1)
print("error: matplotlib version too old (%s)."
" Please install matplotlib v1.2.0 or later and try again." % mpl.__version__,
file=sys.stderr)
sys.exit(-1)

print "matplotlib version ok (%s)." % mpl.__version__
print("matplotlib version ok (%s)." % mpl.__version__)

# OK.
sys.exit(0)
50 changes: 28 additions & 22 deletions scripts/check_python_module
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,54 @@
# usage: check_python_module <module> <min_version>
#

import sys, os.path, importlib, argparse
from __future__ import print_function
import sys
import importlib
import argparse

parser = argparse.ArgumentParser(description="Check presence and version of a Python module")
parser.add_argument("module", help="python module to check")
parser.add_argument("min_version", help="minimum version")
parser.add_argument("-v", "--verbose", action="store_true")
args = parser.parse_args()

modname=args.module
version=args.min_version
modname = args.module
version = args.min_version

#
# See if numpy is installed in the first place
#
try:
module = importlib.import_module(modname)
module = importlib.import_module(modname)
except ImportError:
print >>sys.stderr, "error: %(module)s is not installed. please install %(module)s v%(needver)s or later and try again." % {
'module' : modname,
'needver' : version
}
exit(-1)
print("error: %(module)s is not installed."
" Please install %(module)s v%(needver)s or later and try again." % {
'module': modname,
'needver': version
},
file=sys.stderr)
exit(-1)

#
# Check version compatibility
#
needver = map(int, version.split('.'))
havever = map(int, module.__version__.split('.')) + [ 0 ] * len(needver)
needver = list(map(int, version.split('.')))
havever = list(map(int, module.__version__.split('.'))) + [0] * len(needver)
for a, b in zip(needver, havever):
if a > b:
print >>sys.stderr, "error: %(module)s version too old (v%(havever)s). please install %(module)s v%(needver)s or later and try again." % {
'module' : modname,
'havever' : module.__version__,
'needver' : version
}
exit(-1)
elif a < b:
break
if a > b:
print("error: %(module)s version too old (v%(havever)s)."
" Please install %(module)s v%(needver)s or later and try again." % {
'module': modname,
'havever': module.__version__,
'needver': version
},
file=sys.stderr)
exit(-1)
elif a < b:
break

if args.verbose:
print "Using externally provided %s v%s." % (modname, module.__version__)
# print "Located in '%s'." % os.path.dirname(module.__file__)
print("Using externally provided %s v%s." % (modname, module.__version__))

# OK.
exit(0)