Skip to content

Commit bbe366b

Browse files
committed
more robust versioning
- make version-syncing-thingy (Git ←→ PEP-440) a bit more robust - use setuptools instead of distutils.core - make setup.py syntactically legal for Python 2 so I don't get weird errors when I accidentally type pip instead of pip3 - include version in program output so I don't have to ask for it in every… single… issue… report
1 parent 99229d7 commit bbe366b

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

setup.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

3+
from __future__ import print_function
34
import sys, os, re, subprocess as sp
4-
from distutils.core import setup
5+
from setuptools import setup
56

67
if not sys.version_info[0] == 3:
78
sys.exit("Python 2.x is not supported; Python 3.x is required.")
@@ -14,19 +15,21 @@
1415

1516
# Fetch version from git tags, and write to version.py.
1617
# Also, when git is not available (PyPi package), use stored version.py.
17-
version_py = os.path.join(os.path.dirname(__file__), 'version.py')
18+
version_py = os.path.join(os.path.dirname(__file__), 'tetherback', 'version.py')
1819

1920
try:
20-
version_git = sp.check_output(["git", "describe", "--tags"]).strip().decode('ascii')
21-
final, dev, blob = re.match(r'v?((?:\d+\.)*\d+)(?:-(\d+)-(g[a-z0-9]+))?', version_git).groups()
22-
version_pep = final+('.dev%s+%s'%(dev,blob) if dev else '')
23-
except sp.CalledProcessError:
21+
version_git = sp.check_output(["git", "describe", "--tags", "--dirty=_dirty"]).strip().decode('ascii')
22+
final, dev, blob, dirty = re.match(r'v?((?:\d+\.)*\d+)(?:-(\d+)-(g[a-z0-9]+))?(_dirty)?', version_git).groups()
23+
version_pep = final+('.dev%s+%s'%(dev,blob) if dev else '')+(dirty if dirty else '')
24+
except:
25+
d = {}
2426
with open(version_py, 'r') as fh:
25-
version_pep = open(version_py).read().strip().split('=')[-1][1:-1]
27+
exec(fh.read(), d)
28+
version_pep = d['__version__']
2629
else:
2730
with open(version_py, 'w') as fh:
2831
print("# Do not edit this file, tetherback versioning is governed by git tags", file=fh)
29-
print('__version__="%s"\n' % version_pep, file=fh)
32+
print('__version__="%s"' % version_pep, file=fh)
3033

3134
########################################
3235

tetherback/tetherback.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from hashlib import md5
1616
from collections import namedtuple, OrderedDict as odict
1717

18+
from .version import __version__
1819
from .adb_wrapper import AdbWrapper
1920
from .adb_stuff import *
2021

@@ -29,6 +30,8 @@
2930

3031
def parse_args(args=None):
3132
p = argparse.ArgumentParser(description='''Tool to create TWRP and nandroid-style backups of an Android device running TWRP recovery, using adb-over-USB, without touching the device's internal storage or SD card.''')
33+
p.version=__version__
34+
p.add_argument('--version', action='version')
3235
p.add_argument('-s', dest='specific', metavar='DEVICE_ID', default=None, help="Specific device ID (shown by adb devices). Default is sole USB-connected device.")
3336
p.add_argument('-o', '--output-path', default=".", help="Set optional output path for backup files.")
3437
p.add_argument('-N', '--nandroid', action='store_true', help="Make nandroid backup; raw images rather than tarballs for /system and /data partitions (default is TWRP backup)")
@@ -277,6 +280,8 @@ def main(args=None):
277280
p, args = parse_args(args)
278281
adb = AdbWrapper('adb', ('-s',args.specific) if args.specific else ('-d',))
279282

283+
print('%s v%s' % (p.prog, p.version), file=stderr)
284+
280285
# check adb version, and TWRP recovery
281286
adbversion = check_adb_version(p, adb)
282287
args.transport = sensible_transport(args.transport, adbversion)
File renamed without changes.

0 commit comments

Comments
 (0)