]> git.0d.be Git - earwig.git/blob - setup.py
sources: fix check for missing image property
[earwig.git] / setup.py
1 #! /usr/bin/env python3
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 distutils.cmd import Command
14 from distutils.spawn import find_executable
15 from setuptools import setup, find_packages
16
17 class custom_sdist(sdist):
18     def run(self):
19         if os.path.exists('VERSION'):
20             os.remove('VERSION')
21         version = get_version()
22         version_file = open('VERSION', 'w')
23         version_file.write(version)
24         version_file.close()
25         sdist.run(self)
26         if os.path.exists('VERSION'):
27             os.remove('VERSION')
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(['git','describe','--dirty=.dirty','--match=v*'],
38                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39         result = p.communicate()[0]
40         if p.returncode == 0:
41             result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
42             if '-' in result: # not a tagged version
43                 real_number, commit_count, commit_hash = result.split('-', 2)
44                 version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
45             else:
46                 version = result
47             return version
48         else:
49             return '0.0.post%s' % len(
50                     subprocess.check_output(
51                             ['git', 'rev-list', 'HEAD']).splitlines())
52     return '0.0'
53
54 def data_tree(destdir, sourcedir):
55     extensions = ['.css', '.png', '.jpeg', '.jpg', '.gif', '.xml', '.html', '.js']
56     r = []
57     for root, dirs, files in os.walk(sourcedir):
58         l = [os.path.join(root, x) for x in files if os.path.splitext(x)[1] in extensions]
59         r.append((root.replace(sourcedir, destdir, 1), l))
60     return r
61
62 class compile_translations(Command):
63     description = 'compile message catalogs to MO files via django compilemessages'
64     user_options = []
65
66     def initialize_options(self):
67         pass
68
69     def finalize_options(self):
70         pass
71
72     def run(self):
73         try:
74             from django.core.management import call_command
75             for path, dirs, files in os.walk('chrono'):
76                 if 'locale' not in dirs:
77                     continue
78                 curdir = os.getcwd()
79                 os.chdir(os.path.realpath(path))
80                 call_command('compilemessages')
81                 os.chdir(curdir)
82         except ImportError:
83             sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
84
85
86 class compile_scss(Command):
87     description = 'compile scss files into css files'
88     user_options = []
89
90     def initialize_options(self):
91         pass
92
93     def finalize_options(self):
94         pass
95
96     def run(self):
97         sass_bin = None
98         for program in ('sass', 'sassc'):
99             sass_bin = find_executable(program)
100             if sass_bin:
101                 break
102         if not sass_bin:
103             raise CompileError('A sass compiler is required but none was found.  See sass-lang.com for choices.')
104
105         done = {}
106         for package in self.distribution.packages:
107             for package_path in __import__(package).__path__:
108                 for path, dirnames, filenames in os.walk(package_path):
109                     for filename in filenames:
110                         if not filename.endswith('.scss'):
111                             continue
112                         if filename.startswith('_'):
113                             continue
114                         if (path, filename) in done:
115                             continue
116                         subprocess.check_call([sass_bin, '%s/%s' % (path, filename),
117                             '%s/%s' % (path, filename.replace('.scss', '.css'))])
118                         done[(path, filename)] = True
119
120
121 class build(_build):
122     sub_commands = [('compile_translations', None),
123                     ('compile_scss', None) ] + _build.sub_commands
124
125
126 class install_lib(_install_lib):
127     def run(self):
128         self.run_command('compile_translations')
129         _install_lib.run(self)
130
131
132 setup(
133     name='earwig',
134     version=get_version(),
135     description='Sound Aggregator',
136     author='Frederic Peters',
137     author_email='fpeters@e0d.be',
138     packages=find_packages(),
139     include_package_data=True,
140     scripts=('manage.py',),
141     classifiers=[
142         'Development Status :: 3 - Alpha',
143         'Environment :: Web Environment',
144         'Framework :: Django',
145         'Intended Audience :: Developers',
146         'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
147         'Operating System :: OS Independent',
148         'Programming Language :: Python',
149         'Programming Language :: Python :: 3',
150     ],
151     install_requires=['django>=1.11, <1.12',
152         'django-ckeditor<4.5.3',
153         'gadjo>=0.53',
154         'XStatic_OpenSans',
155         'feedparser',
156         'django-registration-redux>=2.4',
157         'feedparser',
158         'sorl-thumbnail',
159         'Pillow',
160         ],
161     zip_safe=False,
162     cmdclass={
163         'build': build,
164         'compile_scss': compile_scss,
165         'compile_translations': compile_translations,
166         'install_lib': install_lib,
167         'sdist': custom_sdist,
168     },
169 )