-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
87 lines (72 loc) · 2.67 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env/ python
from setuptools import setup
import os
import sys
import subprocess
# edit setup details here
name='binpacking'
license='GNU GPLv3'
description='A package for solving 2D binpacking problems'
url=''
author='Brecht Baeten'
author_email='[email protected]'
packages=['binpacking']
install_requires=['numpy','matplotlib','pyomo']
classifiers = ['Programming Language :: Python :: 2.7']
version = '0.0.1'
changelog = ''
################################################################################
# do not edit
################################################################################
if sys.argv[-1] == 'version':
branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD' ])[:-1]
if not branch=='master':
raise ValueError('the current branch ({}) is not master.'.format(branch))
# get the old version number from version.py
try:
versionfilename = '{}//__version__.py'.format(packages[0])
f = open( versionfilename, 'r')
content = f.readline()
splitcontent = content.split('\'')
oldversion = splitcontent[1]
splitoldversion = oldversion.split('.')
f.close()
# check if the new version is higher than the old version
splitversion = version.split('.')
if sum([int(v)*1000**i for i,v in enumerate(splitversion[::-1])]) <= sum([int(v)*1000**i for i,v in enumerate(splitoldversion[::-1])]):
raise ValueError('the new version ({}) is not higher than the old version ({})'.format(version,oldversion))
except:
raise Exception('Error while checking the version number. Check __version__.py')
# write the version to version.py
f = open( versionfilename, 'w')
f.write( 'version = \'{}\''.format(version) )
f.close()
print('Creating a new distribution version for {}'.format(name) )
print('GIT branch: {}'.format(branch) )
print('Version: {}'.format(version) )
print('Changelog:\n{}'.format(changelog) )
# create a commit message
message = 'Created new version\nVersion: {}'.format(version)
if not changelog == '':
# add the changelog to the commit message
message = message + '\n\nChangelog:\n{}'.format(changelog)
message = message + '\n\nThis is an automated commit.'
# create the commit
output = subprocess.check_output(['git', 'commit', '-a', '-m', message])[:-1]
# add a git tag
output = subprocess.check_output(['git', 'tag' ,'{}'.format(version)])[:-1]
else:
# run the setup command
setup(
name=name,
version=version,
license=license,
description=description,
long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
url=url,
author=author,
author_email=author_email,
packages=packages,
install_requires=install_requires,
classifiers=classifiers,
)