Skip to content

Commit

Permalink
travis.ci
Browse files Browse the repository at this point in the history
Added freeze_git_tag.py to automatically freeze version in setup.py
  • Loading branch information
theriverman committed Aug 16, 2020
1 parent e6e30e1 commit 10a7a74
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
33 changes: 33 additions & 0 deletions freeze_git_tag.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import datetime
import subprocess
from setuptools import find_packages, setup

with open("README.md", "r") as readme_file:
Expand All @@ -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',
Expand Down

0 comments on commit 10a7a74

Please sign in to comment.