-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsetup.py
executable file
·92 lines (71 loc) · 2.27 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
"""
Install django-formset-js using setuptools
"""
import os
import subprocess
import warnings
from distutils.core import Command
from setuptools.command.sdist import sdist
from setuptools import setup, find_packages
from djangoformsetjs import __version__
with open('README.rst') as f:
readme = f.read()
class MinifyCommand(Command):
source_js = 'djangoformsetjs/static/js/jquery.formset.js'
dest_js = 'djangoformsetjs/static/js/jquery.formset.min.js'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def minify_js(self):
map_js = self.dest_js + '.map'
uglifyjs = './node_modules/.bin/uglifyjs'
if os.path.exists(uglifyjs):
try:
subprocess.check_call([
uglifyjs, self.source_js,
'-o', self.dest_js,
'--source-map', map_js,
'--source-map-url', os.path.basename(map_js),
'-p', 'relative'])
except subprocess.CalledProcessError:
raise SystemExit(1)
else:
warnings.warn("uglify-js not found, can not minify JavaScript")
self.copy_js()
def copy_js(self):
import shutil
shutil.copy(self.source_js, self.dest_js)
def run(self):
self.minify_js()
class MinifyAndSdist(sdist):
sub_commands = sdist.sub_commands + [('minify', None)]
setup(
name='django-formset-js-improved',
version=__version__,
description='Extend Django formsets with JavaScript',
long_description=readme,
author='Raphael Michel',
author_email='[email protected]',
url='https://github.com/pretix/django-formset-js',
install_requires=['Django', 'django-jquery-js'],
zip_safe=False,
packages=find_packages(),
include_package_data=True,
package_data={},
classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Framework :: Django',
'License :: OSI Approved :: BSD License',
],
license='BSD',
cmdclass={
'sdist': MinifyAndSdist,
'minify': MinifyCommand,
},
)