misc: update setup.py to our newest standards

This commit is contained in:
Frédéric Péters 2015-11-18 15:15:13 +01:00
parent 35867e5dc9
commit a952caabfc
1 changed files with 26 additions and 5 deletions

View File

@ -1,18 +1,36 @@
#! /usr/bin/env python
from setuptools import setup, find_packages
from distutils.command.sdist import sdist
import os
import subprocess
VERSION = '0.1'
class eo_sdist(sdist):
def run(self):
if os.path.exists('VERSION'):
os.remove('VERSION')
version = get_version()
version_file = open('VERSION', 'w')
version_file.write(version)
version_file.close()
sdist.run(self)
if os.path.exists('VERSION'):
os.remove('VERSION')
def get_version():
if os.path.exists('VERSION'):
version_file = open('VERSION', 'r')
version = version_file.read()
version_file.close()
return version
if os.path.exists('.git'):
p = subprocess.Popen(['git','describe','--dirty'], stdout=subprocess.PIPE)
p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE)
result = p.communicate()[0]
if result:
return result.split()[0].replace('-','.')
return VERSION
if p.returncode == 0:
version = result.split()[0][1:]
version = version.replace('-', '.')
return version
return '0'
setup(name='scrutiny',
version=get_version(),
@ -27,4 +45,7 @@ setup(name='scrutiny',
'django >= 1.7, < 1.8',
'gadjo',
],
cmdclass={
'sdist': eo_sdist,
},
)