From 0f3f45eb7605f6b816df4ec98b6f230b48b4be7d Mon Sep 17 00:00:00 2001 From: Vaidik Kapoor Date: Mon, 5 Oct 2020 20:29:23 +0530 Subject: [PATCH] move to dephell for generating requirements.txt and simplify version bumping --- Makefile | 5 +++++ requirements.txt | 1 + setup.py | 2 +- tools/bump-version.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 requirements.txt create mode 100644 tools/bump-version.py diff --git a/Makefile b/Makefile index 8bf6dd2..39c6457 100644 --- a/Makefile +++ b/Makefile @@ -3,5 +3,10 @@ # # Shortcuts for various tasks. +bump-version: + dephell deps convert --from=setup.py --to=requirements.txt + python tools/bump-version.py --get-current + python tools/bump-version.py --set-version + sdist: python setup.py sdist diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b02dc29 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +lark-parser<0.8.0,>=0.7.1 diff --git a/setup.py b/setup.py index 4b80ddb..04a1370 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup, find_packages -__version__ = '.'.join(map(str, (0, 9, 0))) +__version__ = '0.9.0' install_requires = [ 'lark-parser>=0.7.1,<0.8.0' diff --git a/tools/bump-version.py b/tools/bump-version.py new file mode 100644 index 0000000..70dd8ef --- /dev/null +++ b/tools/bump-version.py @@ -0,0 +1,36 @@ +import re +import sys + + +VERSION_RE = r'\'(([0-9]+\.){2}[0-9])\'' + + +if __name__ == '__main__': + cmd = sys.argv[1] + + if cmd == '--get-current': + with open('setup.py') as fp: + for line in fp.readlines(): + if '__version__' in line: + match = re.search(VERSION_RE, line) + if match: + print(match.groups()[0]) + elif cmd == '--set-version': + stdin_input = input() + if not len(stdin_input): + print('No input provided on stdin.') + sys.exit(1) + + lines = [] + with open('setup.py') as fp: + for line in fp.readlines(): + if '__version__' in line: + line = re.sub(VERSION_RE, '\'%s\'' % stdin_input, line) + lines.append(line) + + with open('setup.py', 'w') as fp: + fp.write(''.join(lines)) + + else: + print('Invalid command') + sys.exit(1)