Projet

Général

Profil

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

root / setup.py @ master

1
#! /usr/bin/env python
2

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

    
6
import glob
7
import re
8
import sys
9
import os
10

    
11
from setuptools import setup, find_packages
12
from setuptools.command.install_lib import install_lib as _install_lib
13
from distutils.command.build import build as _build
14
from distutils.command.sdist import sdist
15
from distutils.cmd import Command
16

    
17
class compile_translations(Command):
18
    description = 'compile message catalogs to MO files via django compilemessages'
19
    user_options = []
20

    
21
    def initialize_options(self):
22
        pass
23

    
24
    def finalize_options(self):
25
        pass
26

    
27
    def run(self):
28
        try:
29
            from django.core.management.commands.compilemessages import \
30
                    compile_messages
31
            for path in ['entrouvert/djommon/', 'entrouvert/djommon/humantime/']:
32
                if path.endswith('.py'):
33
                    continue
34
                curdir = os.getcwd()
35
                os.chdir(os.path.realpath(path))
36
                compile_messages(sys.stderr)
37
                os.chdir(curdir)
38
        except ImportError:
39
            print
40
            sys.stderr.write('!!! Please install Django >= 1.4 to build translations')
41
            print
42
            print
43

    
44
class build(_build):
45
    sub_commands = [('compile_translations', None)] + _build.sub_commands
46

    
47
class eo_sdist(sdist):
48

    
49
    def run(self):
50
        print "creating VERSION file"
51
        if os.path.exists('VERSION'):
52
            os.remove('VERSION')
53
        version = get_version()
54
        version_file = open('VERSION', 'w')
55
        version_file.write(version)
56
        version_file.close()
57
        sdist.run(self)
58
        print "removing VERSION file"
59
        if os.path.exists('VERSION'):
60
            os.remove('VERSION')
61

    
62
class install_lib(_install_lib):
63
    def run(self):
64
        self.run_command('compile_translations')
65
        _install_lib.run(self)
66

    
67
def get_version():
68

    
69
    version = None
70
    if os.path.exists('VERSION'):
71
        version_file = open('VERSION', 'r')
72
        version = version_file.read()
73
        version_file.close()
74
        return version
75
    for d in glob.glob('*'):
76
        if not os.path.isdir(d):
77
            continue
78
        module_file = os.path.join(d, '__init__.py')
79
        if not os.path.exists(module_file):
80
            continue
81
        for v in re.findall("""__version__ *= *['"](.*)['"]""",
82
                open(module_file).read()):
83
            assert version is None
84
            version = v
85
        if version:
86
            break
87
    assert version is not None
88
    if os.path.exists('.git'):
89
        import subprocess
90
        p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
91
                stdout=subprocess.PIPE)
92
        result = p.communicate()[0]
93
        assert p.returncode == 0, 'git returned non-zero'
94
        new_version = result.split()[0][1:]
95
        assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
96
        version = new_version.replace('-', '.')
97
    return version
98

    
99

    
100
setup(name="python-entrouvert",
101
      version=get_version(),
102
      license="AGPLv3 or later",
103
      description="Entr'ouvert tools",
104
      url="http://dev.entrouvert.org/projects/python-entrouvert/",
105
      author="Entr'ouvert",
106
      author_email="info@entrouvert.org",
107
      maintainer="Benjamin Dauvergne",
108
      maintainer_email="info@entrouvert.com",
109
      include_package_data=True,
110
      packages=find_packages(),
111
      scripts=('tools/check-git2python-packaging.sh',),
112
      install_requires=[],
113
      tests_require=[
114
          'nose>=0.11.4',
115
      ],
116
      cmdclass={'build': build, 'install_lib': install_lib,
117
          'compile_translations': compile_translations,
118
          'sdist': eo_sdist},
119
)
(4-4/4)