Projet

Général

Profil

Télécharger (3,02 ko) Statistiques
| Branche: | Tag: | Révision:

root / setup.py @ 50ca9a81

1
#! /usr/bin/env python
2

    
3
''' Setup script for python-entrouvert
4
'''
5

    
6
from setuptools import setup, find_packages
7
from setuptools.command.install_lib import install_lib as _install_lib
8
from distutils.command.build import build as _build
9
from distutils.command.sdist import sdist  as _sdist
10
from distutils.cmd import Command
11

    
12
class compile_translations(Command):
13
    description = 'compile message catalogs to MO files via django compilemessages'
14
    user_options = []
15

    
16
    def initialize_options(self):
17
        pass
18

    
19
    def finalize_options(self):
20
        pass
21

    
22
    def run(self):
23
        import os
24
        import sys
25
        from django.core.management.commands.compilemessages import \
26
            compile_messages
27
        for path in ['entrouvert/djommon/']:
28
            if path.endswith('.py'):
29
                continue
30
            curdir = os.getcwd()
31
            os.chdir(os.path.realpath(path))
32
            compile_messages(stderr=sys.stderr)
33
            os.chdir(curdir)
34

    
35
class build(_build):
36
    sub_commands = [('compile_translations', None)] + _build.sub_commands
37

    
38
class sdist(_sdist):
39
    sub_commands = [('compile_translations', None)] + _sdist.sub_commands
40

    
41
class install_lib(_install_lib):
42
    def run(self):
43
        self.run_command('compile_translations')
44
        _install_lib.run(self)
45

    
46
def get_version():
47
    import glob
48
    import re
49
    import os
50

    
51
    version = None
52
    for d in glob.glob('*'):
53
        if not os.path.isdir(d):
54
            continue
55
        module_file = os.path.join(d, '__init__.py')
56
        if not os.path.exists(module_file):
57
            continue
58
        for v in re.findall("""__version__ *= *['"](.*)['"]""",
59
                open(module_file).read()):
60
            assert version is None
61
            version = v
62
        if version:
63
            break
64
    assert version is not None
65
    if os.path.exists('.git'):
66
        import subprocess
67
        p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
68
                stdout=subprocess.PIPE)
69
        result = p.communicate()[0]
70
        assert p.returncode == 0, 'git returned non-zero'
71
        new_version = result.split()[0][1:]
72
        assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
73
        version = new_version.replace('-', '.')
74
    return version
75

    
76

    
77
setup(name="python-entrouvert",
78
      version=get_version(),
79
      license="AGPLv3 or later",
80
      description="Entr'ouvert tools",
81
      url="http://dev.entrouvert.org/projects/python-entrouvert/",
82
      author="Entr'ouvert",
83
      author_email="info@entrouvert.org",
84
      maintainer="Benjamin Dauvergne",
85
      maintainer_email="info@entrouvert.com",
86
      include_package_data=True,
87
      packages=find_packages(),
88
      scripts=('tools/check-git2python-packaging.sh',),
89
      install_requires=[],
90
      setup_requires=[
91
          'django>=1.4',
92
      ],
93
      tests_require=[
94
          'nose>=0.11.4',
95
      ],
96
      dependency_links=[],
97
      cmdclass={'build': build, 'install_lib': install_lib,
98
          'compile_translations': compile_translations,
99
          'sdist': sdist},
100
)
(4-4/4)