diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index b9a910e0..efda3b53 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- """mythril.py: Bug hunting on the Ethereum blockchain http://www.github.com/ConsenSys/mythril @@ -14,6 +14,7 @@ import argparse from mythril.exceptions import CriticalError from mythril.mythril import Mythril +from mythril.version import VERSION def exit_with_error(format, message): @@ -31,6 +32,8 @@ def main(): commands = parser.add_argument_group('commands') commands.add_argument('-g', '--graph', help='generate a control flow graph') + commands.add_argument('-V', '--version', action='store_true', + help='print the Mythril version number and exit') commands.add_argument('-x', '--fire-lasers', action='store_true', help='detect vulnerabilities, use with -c, -a or solidity file(s)') commands.add_argument('-t', '--truffle', action='store_true', @@ -84,6 +87,10 @@ def main(): args = parser.parse_args() + if args.version: + print("Mythril version {}".format(VERSION)) + sys.exit() + # -- args sanity checks -- # Detect unsupported combinations of command line args diff --git a/mythril/version.py b/mythril/version.py new file mode 100644 index 00000000..e606aa4c --- /dev/null +++ b/mythril/version.py @@ -0,0 +1,3 @@ +# This file is suitable for sourcing inside POSIX shell, e.g. bash as +# well as for importing into Python +VERSION="v0.18.9" # NOQA diff --git a/setup.py b/setup.py index ec606d3e..dd8d79ec 100755 --- a/setup.py +++ b/setup.py @@ -1,13 +1,18 @@ from setuptools import setup, find_packages from setuptools.command.install import install +from pathlib import Path import sys import os +# To make lint checkers happy we set VERSION here, but +# it is redefined by the exec below +VERSION = None + # Package version (vX.Y.Z). It must match git tag being used for CircleCI # deployment; otherwise the build will failed. -VERSION = "v0.18.9" - +version_path = (Path(__file__).parent / 'mythril' / 'version.py').absolute() +exec(open(version_path, 'r').read()) class VerifyVersionCommand(install): """Custom command to verify that the git tag matches our version"""