Skip to content

Commit

Permalink
add airtest.__version__, and command line support airtest version to …
Browse files Browse the repository at this point in the history
…show version number
  • Loading branch information
yimelia committed Dec 25, 2019
1 parent c090c40 commit a320540
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions airtest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.1.2"
8 changes: 8 additions & 0 deletions airtest/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion airtest/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions airtest/utils/snippet.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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],
)
)
20 changes: 19 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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',
Expand Down

0 comments on commit a320540

Please sign in to comment.