]> git.0d.be Git - chloro.git/blob - setup.py
include direct links to latest posts on homepage
[chloro.git] / setup.py
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 import os
5 import re
6 import subprocess
7 import sys
8
9 from setuptools.command.install_lib import install_lib as _install_lib
10 from distutils.command.build import build as _build
11 from distutils.command.sdist import sdist
12 from distutils.cmd import Command
13 from distutils.spawn import find_executable
14 from setuptools import setup, find_packages
15
16
17 class eo_sdist(sdist):
18     def run(self):
19         if os.path.exists('VERSION'):
20             os.remove('VERSION')
21         version = get_version()
22         with open('VERSION', 'w') as fd:
23             fd.write(version)
24         sdist.run(self)
25         if os.path.exists('VERSION'):
26             os.remove('VERSION')
27
28
29 def get_version():
30     '''Use the VERSION, if absent generates a version with git describe, if not
31        tag exists, take 0.0- and add the length of the commit log.
32     '''
33     if os.path.exists('VERSION'):
34         with open('VERSION', 'r') as v:
35             return v.read()
36     if os.path.exists('.git'):
37         p = subprocess.Popen(
38             ['git', 'describe', '--dirty=.dirty', '--match=v*'],
39             stdout=subprocess.PIPE,
40             stderr=subprocess.PIPE,
41         )
42         result = p.communicate()[0]
43         if p.returncode == 0:
44             result = result.decode('ascii').strip()[1:]  # strip spaces/newlines and initial v
45             if '-' in result:  # not a tagged version
46                 real_number, commit_count, commit_hash = result.split('-', 2)
47                 version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
48             else:
49                 version = result
50             return version
51         else:
52             return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
53     return '0.0'
54
55
56 class compile_translations(Command):
57     description = 'compile message catalogs to MO files via django compilemessages'
58     user_options = []
59
60     def initialize_options(self):
61         pass
62
63     def finalize_options(self):
64         pass
65
66     def run(self):
67         orig_dir = os.getcwd()
68         try:
69             from django.core.management import call_command
70
71             for path, dirs, files in os.walk('chloro'):
72                 if 'locale' not in dirs:
73                     continue
74                 curdir = os.getcwd()
75                 os.chdir(os.path.realpath(path))
76                 call_command('compilemessages')
77                 os.chdir(curdir)
78         except ImportError:
79             sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
80         os.chdir(orig_dir)
81
82
83 class compile_scss(Command):
84     description = 'compile scss files into css files'
85     user_options = []
86
87     def initialize_options(self):
88         pass
89
90     def finalize_options(self):
91         pass
92
93     def run(self):
94         sass_bin = None
95         for program in ('sassc', 'sass'):
96             sass_bin = find_executable(program)
97             if sass_bin:
98                 break
99         if not sass_bin:
100             raise CompileError(
101                 'A sass compiler is required but none was found.  See sass-lang.com for choices.'
102             )
103
104         for path, dirnames, filenames in os.walk('chloro'):
105             for filename in filenames:
106                 if not filename.endswith('.scss'):
107                     continue
108                 if filename.startswith('_'):
109                     continue
110                 subprocess.check_call(
111                     [
112                         sass_bin,
113                         '%s/%s' % (path, filename),
114                         '%s/%s' % (path, filename.replace('.scss', '.css')),
115                     ]
116                 )
117
118
119 class build(_build):
120     sub_commands = [('compile_translations', None), ('compile_scss', None)] + _build.sub_commands
121
122
123 class install_lib(_install_lib):
124     def run(self):
125         self.run_command('compile_translations')
126         _install_lib.run(self)
127
128
129 setup(
130     name='chloro',
131     version=get_version(),
132     description='Content Manager',
133     author='Frederic Peters',
134     author_email='fpeters@0d.be',
135     packages=find_packages(exclude=['tests']),
136     include_package_data=True,
137     scripts=('manage.py',),
138     classifiers=[
139         'Development Status :: 4 - Beta',
140         'Environment :: Web Environment',
141         'Framework :: Django',
142         'Intended Audience :: Developers',
143         'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
144         'Operating System :: OS Independent',
145         'Programming Language :: Python',
146         'Programming Language :: Python :: 3',
147     ],
148     install_requires=['django>=1.11, <1.12', 'django-ckeditor<=4.5.3', 'django-taggit', 'gadjo'],
149     zip_safe=False,
150     cmdclass={
151         'build': build,
152         'compile_scss': compile_scss,
153         'compile_translations': compile_translations,
154         'install_lib': install_lib,
155         'sdist': eo_sdist,
156     },
157 )