1 |
5c14c814
|
Benjamin Dauvergne
|
#! /usr/bin/env python
|
2 |
|
|
|
3 |
|
|
''' Setup script for python-entrouvert
|
4 |
|
|
'''
|
5 |
|
|
|
6 |
4f18903b
|
Jérôme Schneider
|
import glob
|
7 |
|
|
import re
|
8 |
5ba9c64e
|
Jérôme Schneider
|
import sys
|
9 |
4f18903b
|
Jérôme Schneider
|
import os
|
10 |
5ba9c64e
|
Jérôme Schneider
|
|
11 |
5c14c814
|
Benjamin Dauvergne
|
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 |
4f18903b
|
Jérôme Schneider
|
from distutils.command.sdist import sdist
|
15 |
5c14c814
|
Benjamin Dauvergne
|
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 |
5ba9c64e
|
Jérôme Schneider
|
try:
|
29 |
|
|
from django.core.management.commands.compilemessages import \
|
30 |
|
|
compile_messages
|
31 |
58f83775
|
Benjamin Dauvergne
|
for path in ['entrouvert/djommon/', 'entrouvert/djommon/humantime/']:
|
32 |
5ba9c64e
|
Jérôme Schneider
|
if path.endswith('.py'):
|
33 |
|
|
continue
|
34 |
|
|
curdir = os.getcwd()
|
35 |
|
|
os.chdir(os.path.realpath(path))
|
36 |
b1b0f6f7
|
Benjamin Dauvergne
|
compile_messages(sys.stderr)
|
37 |
5ba9c64e
|
Jérôme Schneider
|
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 |
5c14c814
|
Benjamin Dauvergne
|
|
44 |
|
|
class build(_build):
|
45 |
|
|
sub_commands = [('compile_translations', None)] + _build.sub_commands
|
46 |
|
|
|
47 |
4f18903b
|
Jérôme Schneider
|
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 |
5c14c814
|
Benjamin Dauvergne
|
class install_lib(_install_lib):
|
63 |
|
|
def run(self):
|
64 |
|
|
self.run_command('compile_translations')
|
65 |
|
|
_install_lib.run(self)
|
66 |
|
|
|
67 |
fa4c24c2
|
Benjamin Dauvergne
|
def get_version():
|
68 |
|
|
|
69 |
|
|
version = None
|
70 |
4f18903b
|
Jérôme Schneider
|
if os.path.exists('VERSION'):
|
71 |
|
|
version_file = open('VERSION', 'r')
|
72 |
|
|
version = version_file.read()
|
73 |
4564b8d3
|
Jérôme Schneider
|
version_file.close()
|
74 |
4f18903b
|
Jérôme Schneider
|
return version
|
75 |
fa4c24c2
|
Benjamin Dauvergne
|
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 |
fe3a77c4
|
Benjamin Dauvergne
|
p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
|
91 |
fa4c24c2
|
Benjamin Dauvergne
|
stdout=subprocess.PIPE)
|
92 |
|
|
result = p.communicate()[0]
|
93 |
07c1be37
|
Benjamin Dauvergne
|
assert p.returncode == 0, 'git returned non-zero'
|
94 |
fe3a77c4
|
Benjamin Dauvergne
|
new_version = result.split()[0][1:]
|
95 |
07c1be37
|
Benjamin Dauvergne
|
assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
|
96 |
|
|
version = new_version.replace('-', '.')
|
97 |
fa4c24c2
|
Benjamin Dauvergne
|
return version
|
98 |
|
|
|
99 |
|
|
|
100 |
50ca9a81
|
Jérôme Schneider
|
setup(name="python-entrouvert",
|
101 |
fa4c24c2
|
Benjamin Dauvergne
|
version=get_version(),
|
102 |
5c14c814
|
Benjamin Dauvergne
|
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 |
bbd77257
|
Benjamin Dauvergne
|
scripts=('tools/check-git2python-packaging.sh',),
|
112 |
5c14c814
|
Benjamin Dauvergne
|
install_requires=[],
|
113 |
ad7cffb2
|
Benjamin Dauvergne
|
tests_require=[
|
114 |
|
|
'nose>=0.11.4',
|
115 |
|
|
],
|
116 |
5c14c814
|
Benjamin Dauvergne
|
cmdclass={'build': build, 'install_lib': install_lib,
|
117 |
4f18903b
|
Jérôme Schneider
|
'compile_translations': compile_translations,
|
118 |
|
|
'sdist': eo_sdist},
|
119 |
5c14c814
|
Benjamin Dauvergne
|
)
|