]> git.0d.be Git - panikweb.git/blob - setup.py
limit embed view to podcastable sounds
[panikweb.git] / setup.py
1 #! /usr/bin/env python3
2
3 import os
4 import subprocess
5 import sys
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
10
11 from setuptools import find_packages, setup
12 from setuptools.command.install_lib import install_lib as _install_lib
13
14
15 class sdist(_sdist):
16     def run(self):
17         if os.path.exists('VERSION'):
18             os.remove('VERSION')
19         version = get_version()
20         with open('VERSION', 'w') as fd:
21             fd.write(version)
22         _sdist.run(self)
23         if os.path.exists('VERSION'):
24             os.remove('VERSION')
25
26
27 def get_version():
28     if os.path.exists('VERSION'):
29         with open('VERSION') as v:
30             return v.read()
31     if os.path.exists('.git'):
32         p = subprocess.Popen(
33             ['git', 'describe', '--dirty=.dirty', '--match=v*'],
34             stdout=subprocess.PIPE,
35             stderr=subprocess.PIPE,
36         )
37         result = p.communicate()[0]
38         if p.returncode == 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)
43             else:
44                 version = result
45             return version
46         else:
47             return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
48     return '0.0'
49
50
51 class compile_translations(Command):
52     description = 'compile message catalogs to MO files via django compilemessages'
53     user_options = []
54
55     def initialize_options(self):
56         pass
57
58     def finalize_options(self):
59         pass
60
61     def run(self):
62         try:
63             from django.core.management import call_command
64
65             for path, dirs, files in os.walk('panikweb'):
66                 if 'locale' not in dirs:
67                     continue
68                 curdir = os.getcwd()
69                 os.chdir(os.path.realpath(path))
70                 call_command('compilemessages')
71                 os.chdir(curdir)
72         except ImportError:
73             sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
74
75
76 class compile_scss(Command):
77     description = 'compile scss files into css files'
78     user_options = []
79
80     def initialize_options(self):
81         pass
82
83     def finalize_options(self):
84         pass
85
86     def run(self):
87         sass_bin = None
88         for program in ('sassc', 'sass'):
89             sass_bin = find_executable(program)
90             if sass_bin:
91                 break
92         if not sass_bin:
93             raise CompileError(
94                 'A sass compiler is required but none was found.  See sass-lang.com for choices.'
95             )
96
97         for path, dirnames, filenames in os.walk('panikweb'):
98             for filename in filenames:
99                 if not filename.endswith('.scss'):
100                     continue
101                 if filename.startswith('_'):
102                     continue
103                 subprocess.check_call(
104                     [
105                         sass_bin,
106                         '%s/%s' % (path, filename),
107                         '%s/%s' % (path, filename.replace('.scss', '.css')),
108                     ]
109                 )
110
111
112 class build(_build):
113     sub_commands = [('compile_translations', None), ('compile_scss', None)] + _build.sub_commands
114
115
116 class install_lib(_install_lib):
117     def run(self):
118         self.run_command('compile_translations')
119         _install_lib.run(self)
120
121
122 setup(
123     name='panikweb',
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',),
132     classifiers=[
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',
143     ],
144     zip_safe=False,
145     cmdclass={
146         'build': build,
147         'compile_scss': compile_scss,
148         'compile_translations': compile_translations,
149         'install_lib': install_lib,
150         'sdist': sdist,
151     },
152 )