1 #! /usr/bin/env python3
6 from distutils.cmd import Command
7 from distutils.command.build import build as _build
8 from distutils.command.sdist import sdist as _sdist
9 from distutils.spawn import find_executable
11 from setuptools import find_packages, setup
12 from setuptools.command.install_lib import install_lib as _install_lib
17 if os.path.exists('VERSION'):
19 version = get_version()
20 with open('VERSION', 'w') as fd:
23 if os.path.exists('VERSION'):
28 if os.path.exists('VERSION'):
29 with open('VERSION') as v:
31 if os.path.exists('.git'):
33 ['git', 'describe', '--dirty=.dirty', '--match=v*'],
34 stdout=subprocess.PIPE,
35 stderr=subprocess.PIPE,
37 result = p.communicate()[0]
39 result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
40 if '-' in result: # not a tagged version
41 real_number, commit_count, commit_hash = result.split('-', 2)
42 version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
47 return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
51 class compile_translations(Command):
52 description = 'compile message catalogs to MO files via django compilemessages'
55 def initialize_options(self):
58 def finalize_options(self):
63 from django.core.management import call_command
65 for path, dirs, files in os.walk('panikweb'):
66 if 'locale' not in dirs:
69 os.chdir(os.path.realpath(path))
70 call_command('compilemessages')
73 sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
76 class compile_scss(Command):
77 description = 'compile scss files into css files'
80 def initialize_options(self):
83 def finalize_options(self):
88 for program in ('sassc', 'sass'):
89 sass_bin = find_executable(program)
94 'A sass compiler is required but none was found. See sass-lang.com for choices.'
97 for path, dirnames, filenames in os.walk('panikweb'):
98 for filename in filenames:
99 if not filename.endswith('.scss'):
101 if filename.startswith('_'):
103 subprocess.check_call(
106 '%s/%s' % (path, filename),
107 '%s/%s' % (path, filename.replace('.scss', '.css')),
113 sub_commands = [('compile_translations', None), ('compile_scss', None)] + _build.sub_commands
116 class install_lib(_install_lib):
118 self.run_command('compile_translations')
119 _install_lib.run(self)
124 version=get_version(),
125 description='Radio Panik Website',
126 author='Frederic Peters',
127 author_email='fred@radiopanik.org',
128 packages=find_packages(),
129 url='https://www.radiopanik.org',
130 include_package_data=True,
131 scripts=('manage.py',),
133 'Development Status :: 4 - Beta',
134 'Environment :: Web Environment',
135 'Framework :: Django',
136 'Intended Audience :: Developers',
137 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
138 'Operating System :: OS Independent',
139 'Programming Language :: Python',
140 'Programming Language :: Python :: 3',
141 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
142 'Topic :: Multimedia :: Sound/Audio',
147 'compile_scss': compile_scss,
148 'compile_translations': compile_translations,
149 'install_lib': install_lib,