diff --git a/.travis.yml b/.travis.yml index c3a5fdb..bb7e571 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ jobs: - stage: pypi release script: - echo "Deploying to PyPI ..." + - python freeze_git_tag.py --silent deploy: # deploy (on tag) to PyPI provider: pypi username: __token__ diff --git a/freeze_git_tag.py b/freeze_git_tag.py new file mode 100644 index 0000000..b9ba34a --- /dev/null +++ b/freeze_git_tag.py @@ -0,0 +1,33 @@ +import re +import sys +import signal +import subprocess + + +def signal_handler(_, __): + print('\n----------------------------------------------') + print('Exiting. No tag will be written to setup.py') + sys.exit(0) + + +if __name__ == '__main__': + signal.signal(signal.SIGINT, signal_handler) + + git_tag = subprocess.check_output(['git', 'describe', '--tags']).strip().decode('utf-8') + pattern = re.compile(r"CURRENT_GIT_TAG = '(v[1-9.]+)'") + + if '--silent' not in sys.argv: + print('----------------------------------------------') + print(f'Tag {git_tag} will be written to setup.py') + input('Press ENTER to continue or Ctrl+C to stop...') + print('----------------------------------------------') + + with open('setup.py', 'r+') as f: + old_contents = f.read() + try: + f.seek(0) + new_contents = re.sub(pattern, f"CURRENT_GIT_TAG = '{git_tag}'", old_contents) + f.write(new_contents) + f.truncate() + except (OSError, ValueError): + f.write(old_contents) diff --git a/setup.py b/setup.py index 92497c1..c993ac3 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ import os import datetime -import subprocess from setuptools import find_packages, setup with open("README.md", "r") as readme_file: @@ -9,12 +8,12 @@ # allow setup.py to be run from any path os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) -git_tag = subprocess.check_output(['git', 'describe', '--tags']).strip().decode('utf-8') +CURRENT_GIT_TAG = 'v2.2.0' year = datetime.datetime.now().year setup( name='django-minio-backend', - version=git_tag, + version=CURRENT_GIT_TAG, packages=find_packages(), include_package_data=True, license=f'MIT License | Copyright (c) {year} Kristof Daja',