From 6fc09e500df1a3b9f15955b8710978ea7a478866 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 13 Oct 2014 23:24:18 +0200 Subject: [PATCH] debian packaging --- MANIFEST.in | 2 + debian/changelog | 5 +++ debian/compat | 1 + debian/control | 18 ++++++++ debian/rules | 7 ++++ debian/source/format | 1 + debian/source/options | 1 + setup.py | 96 +++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 debian/source/options diff --git a/MANIFEST.in b/MANIFEST.in index cbdf17f..edccf66 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,3 +4,5 @@ include README.rst recursive-include import_export/templates * recursive-include import_export/locale * recursive-include import_export/static * +include VERSION +include MANIFEST.in diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..263ead0 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +django-import-export (0.2.4-0) unstable; urgency=low + + * Initial packaging + + -- Benjamin Dauvergne Thu, 13 Oct 2014 23:22:57 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..d12ce86 --- /dev/null +++ b/debian/control @@ -0,0 +1,18 @@ +Source: django-import-export +Maintainer: Benjamin Dauvergne +Section: python +Priority: optional +Build-Depends: python-setuptools, python-all, python3-setuptools, python3-all, debhelper (>= 9), dh-python +Standards-Version: 3.9.1 + +Package: python-django-import-export +Architecture: all +Depends: ${misc:Depends}, ${python:Depends} +Description: Django application and library for importing and exporting data + with included admin integration. + +Package: python3-django-import-export +Architecture: all +Depends: ${misc:Depends}, ${python:Depends} +Description: Django application and library for importing and exporting data + with included admin integration. diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..a9461d2 --- /dev/null +++ b/debian/rules @@ -0,0 +1,7 @@ +#!/usr/bin/make -f + +export PYBUILD_DISABLE=test +export PYBUILD_NAME=django-import-export + +%: + dh $@ --with python2,python3 --buildsystem=pybuild diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/source/options b/debian/source/options new file mode 100644 index 0000000..e960d25 --- /dev/null +++ b/debian/source/options @@ -0,0 +1 @@ +extend-diff-ignore="\.egg-info" diff --git a/setup.py b/setup.py index abbb25e..3ba73da 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,91 @@ +import os +import subprocess +import sys + from setuptools import find_packages, setup +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 -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- 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=.dirty', '--match=*'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + result = p.communicate()[0] + if p.returncode == 0: + result = result.decode('ascii').strip() # strip spaces/newlines and initial v + if '-' in result: # not a tagged version + real_number, commit_count, commit_hash = result.split('-', 2) + version = '%s.post%s+%s' % (real_number, commit_count, commit_hash) + else: + version = result + return version + else: + return '0.0.post%s' % len( + subprocess.check_output( + ['git', 'rev-list', 'HEAD']).splitlines()) + return '0.0' + + +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): + orig_dir = os.getcwd() + try: + from django.core.management import call_command + for path, dirs, files in os.walk('combo'): + if 'locale' not in dirs: + continue + curdir = os.getcwd() + os.chdir(os.path.realpath(path)) + call_command('compilemessages') + os.chdir(curdir) + except ImportError: + sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n') + os.chdir(orig_dir) + + +class eo_sdist(sdist): + sub_commands = [('compile_translations', None)] + sdist.sub_commands + + 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') + + +class build(_build): + sub_commands = [('compile_translations', None)] + _build.sub_commands + + +class install_lib(_install_lib): + def run(self): + self.run_command('compile_translations') + _install_lib.run(self) + CLASSIFIERS = [ 'Framework :: Django', @@ -35,8 +119,8 @@ install_requires = [ setup( name="django-import-export", description="Django application and library for importing and exporting" - "data with included admin integration.", - version=VERSION, + "data with included admin integration.", + version=get_version(), author="Informatika Mihelac", author_email="bmihelac@mihelac.org", license='BSD License', @@ -48,4 +132,10 @@ setup( python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*", classifiers=CLASSIFIERS, zip_safe=False, + cmdclass={ + 'build': build, + 'install_lib': install_lib, + 'compile_translations': compile_translations, + 'sdist': eo_sdist + }, )