Projet

Général

Profil

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

root / setup.py @ main

1
#! /usr/bin/env python
2
# -*- coding: utf-8 -*-
3

    
4
import glob
5
import os
6
import re
7
import subprocess
8
import sys
9

    
10
from setuptools.command.install_lib import install_lib as _install_lib
11
from distutils.command.build import build as _build
12
from distutils.command.sdist import sdist
13
from setuptools import setup, find_packages
14

    
15
from distutils.cmd import Command
16

    
17

    
18
class eo_sdist(sdist):
19
    def run(self):
20
        if os.path.exists('VERSION'):
21
            os.remove('VERSION')
22
        version = get_version()
23
        with open('VERSION', 'w') as fd:
24
            fd.write(version)
25
        sdist.run(self)
26
        if os.path.exists('VERSION'):
27
            os.remove('VERSION')
28

    
29

    
30
def get_version():
31
    '''Use the VERSION, if absent generates a version with git describe, if not
32
       tag exists, take 0.0- and add the length of the commit log.
33
    '''
34
    if os.path.exists('VERSION'):
35
        with open('VERSION', 'r') as v:
36
            return v.read()
37
    if os.path.exists('.git'):
38
        p = subprocess.Popen(
39
            ['git', 'describe', '--dirty=.dirty', '--match=v*'],
40
            stdout=subprocess.PIPE,
41
            stderr=subprocess.PIPE,
42
        )
43
        result = p.communicate()[0]
44
        if p.returncode == 0:
45
            result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
46
            if '-' in result:  # not a tagged version
47
                real_number, commit_count, commit_hash = result.split('-', 2)
48
                version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
49
            else:
50
                version = result
51
            return version
52
        else:
53
            return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
54
    return '0.0'
55

    
56

    
57
class compile_translations(Command):
58
    description = 'compile message catalogs to MO files via django compilemessages'
59
    user_options = []
60

    
61
    def initialize_options(self):
62
        pass
63

    
64
    def finalize_options(self):
65
        pass
66

    
67
    def run(self):
68
        curdir = os.getcwd()
69
        try:
70
            from django.core.management import call_command
71

    
72
            for path, dirs, files in os.walk('corbo'):
73
                if 'locale' not in dirs:
74
                    continue
75
                os.chdir(os.path.realpath(path))
76
                call_command('compilemessages')
77
        except ImportError:
78
            sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
79
        finally:
80
            os.chdir(curdir)
81

    
82

    
83
class build(_build):
84
    sub_commands = [('compile_translations', None)] + _build.sub_commands
85

    
86

    
87
class install_lib(_install_lib):
88
    def run(self):
89
        self.run_command('compile_translations')
90
        _install_lib.run(self)
91

    
92

    
93
setup(
94
    name='corbo',
95
    version=get_version(),
96
    description='Announces Manager',
97
    author='Serghei Mihai',
98
    author_email='smihai@entrouvert.com',
99
    packages=find_packages(),
100
    include_package_data=True,
101
    scripts=('manage.py',),
102
    url='http://repos.entrouvert.org/corbo.git',
103
    classifiers=[
104
        'Environment :: Web Environment',
105
        'Framework :: Django',
106
        'Intended Audience :: Developers',
107
        'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
108
        'Operating System :: OS Independent',
109
        'Programming Language :: Python',
110
        'Programming Language :: Python :: 2',
111
    ],
112
    install_requires=['django>1.7, <2.3',
113
        'django-ckeditor<4.5.4',
114
        'djangorestframework>=3.3,<3.8',
115
        'html2text',
116
        'gadjo',
117
        'emails',
118
        'lxml',
119
        'feedparser<6',
120
        'requests'
121
        ],
122
    zip_safe=False,
123
    cmdclass={
124
        'build': build,
125
        'compile_translations': compile_translations,
126
        'install_lib': install_lib,
127
        'sdist': eo_sdist,
128
    },
129
)
(8-8/9)