1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
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
17 class custom_sdist(sdist):
19 if os.path.exists('VERSION'):
21 version = get_version()
22 version_file = open('VERSION', 'w')
23 version_file.write(version)
26 if os.path.exists('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.
33 if os.path.exists('VERSION'):
34 with open('VERSION', 'r') as v:
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]
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)
49 return '0.0.post%s' % len(
50 subprocess.check_output(
51 ['git', 'rev-list', 'HEAD']).splitlines())
54 def data_tree(destdir, sourcedir):
55 extensions = ['.css', '.png', '.jpeg', '.jpg', '.gif', '.xml', '.html', '.js']
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))
62 class compile_translations(Command):
63 description = 'compile message catalogs to MO files via django compilemessages'
66 def initialize_options(self):
69 def finalize_options(self):
74 from django.core.management import call_command
75 for path, dirs, files in os.walk('chrono'):
76 if 'locale' not in dirs:
79 os.chdir(os.path.realpath(path))
80 call_command('compilemessages')
83 sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
86 class compile_scss(Command):
87 description = 'compile scss files into css files'
90 def initialize_options(self):
93 def finalize_options(self):
98 for program in ('sass', 'sassc'):
99 sass_bin = find_executable(program)
103 raise CompileError('A sass compiler is required but none was found. See sass-lang.com for choices.')
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'):
112 if filename.startswith('_'):
114 if (path, filename) in done:
116 subprocess.check_call([sass_bin, '%s/%s' % (path, filename),
117 '%s/%s' % (path, filename.replace('.scss', '.css'))])
118 done[(path, filename)] = True
122 sub_commands = [('compile_translations', None),
123 ('compile_scss', None) ] + _build.sub_commands
126 class install_lib(_install_lib):
128 self.run_command('compile_translations')
129 _install_lib.run(self)
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',),
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',
151 install_requires=['django>=1.11, <1.12',
152 'django-ckeditor<4.5.3',
156 'django-registration-redux>=2.4',
164 'compile_scss': compile_scss,
165 'compile_translations': compile_translations,
166 'install_lib': install_lib,
167 'sdist': custom_sdist,