setup.py: simplify get_version, pep8ness and cleaning
This commit is contained in:
parent
ab75d8a89c
commit
8a84c89610
60
setup.py
60
setup.py
|
@ -1,17 +1,11 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import glob
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
from setuptools.command.install_lib import install_lib as _install_lib
|
from setuptools.command.sdist import sdist
|
||||||
from distutils.command.build import build as _build
|
|
||||||
from distutils.command.sdist import sdist
|
|
||||||
from distutils.cmd import Command
|
|
||||||
|
|
||||||
from eobuilder import VERSION
|
|
||||||
|
|
||||||
class eo_sdist(sdist):
|
class eo_sdist(sdist):
|
||||||
|
|
||||||
|
@ -28,37 +22,25 @@ class eo_sdist(sdist):
|
||||||
if os.path.exists('VERSION'):
|
if os.path.exists('VERSION'):
|
||||||
os.remove('VERSION')
|
os.remove('VERSION')
|
||||||
|
|
||||||
def get_version():
|
|
||||||
|
|
||||||
version = VERSION
|
def get_version():
|
||||||
|
'''Use the VERSION, if absent generates a version with git describe, if not
|
||||||
|
tag exists, take 0.0.0- and add the length of the commit log.
|
||||||
|
'''
|
||||||
if os.path.exists('VERSION'):
|
if os.path.exists('VERSION'):
|
||||||
version_file = open('VERSION', 'r')
|
with open('VERSION', 'r') as v:
|
||||||
version = version_file.read()
|
return v.read()
|
||||||
version_file.close()
|
|
||||||
return version
|
|
||||||
for d in glob.glob('*'):
|
|
||||||
if not os.path.isdir(d):
|
|
||||||
continue
|
|
||||||
module_file = os.path.join(d, '__init__.py')
|
|
||||||
if not os.path.exists(module_file):
|
|
||||||
continue
|
|
||||||
for v in re.findall("""__version__ *= *['"](.*)['"]""",
|
|
||||||
open(module_file).read()):
|
|
||||||
assert version is None
|
|
||||||
version = v
|
|
||||||
if version:
|
|
||||||
break
|
|
||||||
assert version is not None
|
|
||||||
if os.path.exists('.git'):
|
if os.path.exists('.git'):
|
||||||
import subprocess
|
p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE,
|
||||||
p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
|
stderr=subprocess.PIPE)
|
||||||
stdout=subprocess.PIPE)
|
|
||||||
result = p.communicate()[0]
|
result = p.communicate()[0]
|
||||||
assert p.returncode == 0, 'git returned non-zero'
|
if p.returncode == 0:
|
||||||
new_version = result.split()[0][1:]
|
result = result.split()[0][1:]
|
||||||
assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
|
else:
|
||||||
version = new_version.replace('-', '.')
|
result = '0.0.0-%s' % len(subprocess.check_output(
|
||||||
return version
|
['git', 'rev-list', 'HEAD']).splitlines())
|
||||||
|
return result.replace('-', '.').replace('.g', '+g')
|
||||||
|
return '0.0.0'
|
||||||
|
|
||||||
|
|
||||||
setup(name="eobuilder",
|
setup(name="eobuilder",
|
||||||
|
@ -69,13 +51,9 @@ setup(name="eobuilder",
|
||||||
author_email="info@entrouvert.org",
|
author_email="info@entrouvert.org",
|
||||||
maintainer="Jerome Schneider",
|
maintainer="Jerome Schneider",
|
||||||
maintainer_email="info@entrouvert.com",
|
maintainer_email="info@entrouvert.com",
|
||||||
install_requires=['pytz',
|
install_requires=['pytz', 'GitPython'],
|
||||||
'GitPython'
|
|
||||||
],
|
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
url='https://dev.entrouvert.org/projects/eobuilder',
|
url='https://dev.entrouvert.org/projects/eobuilder',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
scripts=('eobuilder-ctl', 'eobuildall'),
|
scripts=('eobuilder-ctl', 'eobuildall'),
|
||||||
cmdclass={'sdist': eo_sdist},
|
cmdclass={'sdist': eo_sdist})
|
||||||
)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue