summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2015-05-27 14:37:03 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2015-05-27 14:38:03 (GMT)
commit7225dffb503c8cf35c9cbc6952fc46772f60e612 (patch)
tree731c83140ad21f202f558302221101e32193f230
parentf2c55bd74761feacccee9c420a14cceafdd9ae39 (diff)
downloaddjango-import-export-7225dffb503c8cf35c9cbc6952fc46772f60e612.zip
django-import-export-7225dffb503c8cf35c9cbc6952fc46772f60e612.tar.gz
django-import-export-7225dffb503c8cf35c9cbc6952fc46772f60e612.tar.bz2
setup.py: compute version from git tags
-rw-r--r--MANIFEST.in2
-rw-r--r--setup.py94
2 files changed, 92 insertions, 4 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
index 59723d2..3416d44 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -3,3 +3,5 @@ include AUTHORS
include README.rst
recursive-include import_export/templates *
recursive-include import_export/locale *
+include VERSION
+include MANIFEST.in
diff --git a/setup.py b/setup.py
index 886c4b0..c31ccb4 100644
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,91 @@
+import subprocess
+import sys
+import os
+
from distutils.core import setup
from setuptools import find_packages
+from setuptools.command.install_lib import install_lib as _install_lib
+from distutils.command.build import build as _build
+from distutils.command.sdist import sdist
+from distutils.cmd import Command
+
+
+class compile_translations(Command):
+ description = 'compile message catalogs to MO files via django \
+compilemessages'
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ try:
+ from django.core.management import call_command
+ for dir in ('src/authentic2', 'src/authentic2_idp_openid',
+ 'src/authentic2_idp_cas', 'src/django_rbac'):
+ for path, dirs, files in os.walk(dir):
+ if 'locale' not in dirs:
+ continue
+ curdir = os.getcwd()
+ os.chdir(os.path.realpath(path))
+ call_command('compilemessages')
+ os.chdir(curdir)
+ except ImportError:
+ print
+ sys.stderr.write('!!! Please install Django >= 1.4 to build '
+ 'translations')
+ print
+ print
+
+
+class build(_build):
+ sub_commands = [('compile_translations', None)] + _build.sub_commands
+
+
+class eo_sdist(sdist):
+
+ def run(self):
+ print "creating VERSION file"
+ 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)
+ print "removing VERSION file"
+ if os.path.exists('VERSION'):
+ os.remove('VERSION')
+
+
+class install_lib(_install_lib):
+ def run(self):
+ self.run_command('compile_translations')
+ _install_lib.run(self)
-VERSION = __import__("import_export").__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'):
+ with open('VERSION', 'r') as v:
+ return v.read()
+ if os.path.exists('.git'):
+ p = subprocess.Popen(['git', 'describe', '--dirty'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ result = p.communicate()[0]
+ if p.returncode == 0:
+ return result.split()[0].replace('-', '.')
+ else:
+ return '0.0.0-%s' % len(
+ subprocess.check_output(['git', 'rev-list',
+ 'HEAD']).splitlines())
+ return '0.0.0'
CLASSIFIERS = [
'Framework :: Django',
@@ -22,9 +105,9 @@ install_requires = [
setup(
name="django-import-export",
- description="Django application and library for importing and exporting"
- "data with included admin integration.",
- version=VERSION,
+ description="Django application and library for importing and "
+ "exporting" "data with included admin integration.",
+ version=get_version(),
author="Informatika Mihelac",
author_email="bmihelac@mihelac.org",
license='BSD License',
@@ -34,4 +117,7 @@ setup(
include_package_data=True,
install_requires=install_requires,
classifiers=CLASSIFIERS,
+ cmdclass={'build': build, 'install_lib': install_lib,
+ 'compile_translations': compile_translations, 'sdist':
+ eo_sdist},
)