Projet

Général

Profil

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

root / setup.py @ master

1
#! /usr/bin/env python
2

    
3
''' Setup script for Facturier app
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 import call_command
30
            for path in ['src']:
31
                if not os.path.exists(os.path.join(path, 'locale')):
32
                    continue
33
                curdir = os.getcwd()
34
                os.chdir(os.path.realpath(path))
35
                call_command('compilemessages')
36
                os.chdir(curdir)
37
        except ImportError:
38
            print
39
            sys.stderr.write('!!! Please install Django >= 1.4 to build translations')
40
            print
41
            print
42

    
43

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

    
47

    
48
class eo_sdist(sdist):
49

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

    
63

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

    
69

    
70
def get_version():
71

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

    
103

    
104
setup(name="facturier",
105
      version=get_version(),
106
      license="AGPLv3 or later",
107
      description="Payment lib pluggable into portail-citoyen",
108
      author="Entr'ouvert",
109
      author_email="info@entrouvert.org",
110
      maintainer="Serghei Mihai",
111
      maintainer_email="smihai@entrouvert.com",
112
      include_package_data=True,
113
      packages=find_packages(),
114
      install_requires=[
115
            'portail-citoyen2',
116
            'eopayment',
117
            'django-jsonfield',
118
            'django-cmsplugin-blurp'
119
      ],
120
      dependency_links = [
121
          'git+git://repos.entrouvert.org/portail-citoyen2',
122
          'git+git://repos.entrouvert.org/eopayment'
123
      ],
124
      cmdclass={'build': build, 'install_lib': install_lib,
125
          'compile_translations': compile_translations,
126
          'sdist': eo_sdist},
127
      entry_points={
128
          'portail_citoyen2.plugin': ['facturier = facturier:Plugin']
129
      }
130
)
(3-3/3)