From a320540d1be441250e83d92889a2c5712c4bb9fd Mon Sep 17 00:00:00 2001 From: = Date: Wed, 25 Dec 2019 17:55:27 +0800 Subject: [PATCH] add airtest.__version__, and command line support airtest version to show version number --- airtest/__init__.py | 1 + airtest/cli/__main__.py | 8 ++++++++ airtest/cli/parser.py | 4 +++- airtest/utils/snippet.py | 14 ++++++++++++++ setup.py | 20 +++++++++++++++++++- 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/airtest/__init__.py b/airtest/__init__.py index e69de29b..72f26f59 100644 --- a/airtest/__init__.py +++ b/airtest/__init__.py @@ -0,0 +1 @@ +__version__ = "1.1.2" diff --git a/airtest/cli/__main__.py b/airtest/cli/__main__.py index 11a6ca1c..d38144bf 100644 --- a/airtest/cli/__main__.py +++ b/airtest/cli/__main__.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +import os +import sys + from airtest.cli.parser import get_parser +from airtest.utils.snippet import get_airtest_version def main(argv=None): @@ -14,6 +18,10 @@ def main(argv=None): elif args.action == "run": from airtest.cli.runner import run_script run_script(args) + elif args.action == "version": + sys.stdout.write(get_airtest_version()) + sys.stdout.write(os.linesep) + sys.exit() else: ap.print_help() diff --git a/airtest/cli/parser.py b/airtest/cli/parser.py index 0d9fad7c..825283e7 100644 --- a/airtest/cli/parser.py +++ b/airtest/cli/parser.py @@ -7,7 +7,9 @@ def get_parser(): ap = argparse.ArgumentParser() - subparsers = ap.add_subparsers(dest="action", help="run/info/report") + subparsers = ap.add_subparsers(dest="action", help="version/run/info/report") + # subparser version + subparsers.add_parser("version", help="show version and exit") # subparser run ap_run = subparsers.add_parser("run", help="run script") runner_parser(ap_run) diff --git a/airtest/utils/snippet.py b/airtest/utils/snippet.py index ee7bed44..717b5a42 100644 --- a/airtest/utils/snippet.py +++ b/airtest/utils/snippet.py @@ -1,9 +1,11 @@ # _*_ coding:UTF-8 _*_ +import os import sys import threading from functools import wraps from six import string_types from six.moves import queue +from airtest import __version__ def split_cmd(cmds): @@ -114,3 +116,15 @@ def wrapper(inst, *args, **kwargs): ret = func(inst, *args, **kwargs) return ret return wrapper + + +def get_airtest_version(): + # type: () -> str + pip_pkg_dir = os.path.join(os.path.dirname(__file__), "..", "..") + pip_pkg_dir = os.path.abspath(pip_pkg_dir) + + return ( + 'airtest {} from {} (python {})'.format( + __version__, pip_pkg_dir, sys.version[:3], + ) + ) diff --git a/setup.py b/setup.py index f3a5ec5d..8fbb9750 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,25 @@ +import os import sys +import codecs from setuptools import setup, find_packages +def read(rel_path): + here = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(here, rel_path), 'r') as fp: + return fp.read() + + +def get_version(rel_path): + for line in read(rel_path).splitlines(): + if line.startswith('__version__'): + # __version__ = "1.x.x" + delim = '"' if '"' in line else "'" + return line.split(delim)[1] + else: + raise RuntimeError("Unable to find version string.") + + def parse_requirements(filename): """ load requirements from a pip requirements file. (replacing from pip.req import parse_requirements)""" lineiter = (line.strip() for line in open(filename)) @@ -15,7 +33,7 @@ def parse_requirements(filename): setup( name='airtest', - version='1.1.1', + version=get_version("airtest/__init__.py"), author='Netease Games', author_email='gzliuxin@corp.netease.com', description='UI Test Automation Framework for Games and Apps on Android/iOS/Windows/Linux',