forked from Unmanic/unmanic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
201 lines (162 loc) · 6.51 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
unmanic.setup.py
Written by: Josh.5 <jsunnex@gmail.com>
Date: 04 May 2020, (10:47 AM)
Copyright:
Copyright (C) Josh Sunnex - All Rights Reserved
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
"""
import json
import os
import shutil
import subprocess
import sys
import glob
from setuptools import setup, find_packages, Command
import setuptools.command.build_py
import versioninfo
if sys.version_info[0] < 3:
print("This module version requires Python 3.")
sys.exit(1)
project_root_dir = os.path.dirname(os.path.realpath(__file__))
src_dir = 'unmanic'
module_name = versioninfo.name()
module_version = versioninfo.version()
module_description = versioninfo.description()
module_author = versioninfo.author()
module_email = versioninfo.email()
module_url = versioninfo.url()
module_classifiers = [
versioninfo.dev_status(),
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Operating System :: POSIX :: Linux',
'Operating System :: Unix',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Topic :: Multimedia :: Video :: Conversion',
'Topic :: Internet :: WWW/HTTP',
]
class BuildPyCommand(setuptools.command.build_py.build_py):
"""Custom build command."""
def run(self):
setuptools.command.build_py.build_py.run(self)
self.run_command('write-build-version')
self.run_command('build-web')
class WriteVersionCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
@staticmethod
def run():
version_file = os.path.join('.', 'build', 'lib', src_dir, 'version')
data = {
'short': versioninfo.version(),
'long': versioninfo.full_version(),
}
with open(version_file, 'w') as f:
json.dump(data, f)
class BuildWebUICommand(setuptools.command.build_py.build_py):
"""WebUI build command."""
def run(self):
setuptools.command.build_py.build_py.run(self)
# Start by clearing out anything if this was pulled from a dirty tree
shutil.rmtree(os.path.abspath(os.path.join('.', 'build', 'lib', src_dir, 'webserver', 'node_modules')),
ignore_errors=True)
# Clean our build env
subprocess.run(
["npm", "--prefix", os.path.join('.', 'build', 'lib', src_dir, 'webserver'), "run", "distclean"],
check=True
)
# Install all modules
subprocess.run(
["npm", "--prefix", os.path.join('.', 'build', 'lib', src_dir, 'webserver'), "install"],
check=True
)
# Build the WebUI
subprocess.run(
["npm", "--prefix", os.path.join('.', 'build', 'lib', src_dir, 'webserver'), "run", "build"],
check=True
)
# Remove the node_modules from the package (we will not distribute these)
shutil.rmtree(os.path.abspath(os.path.join('.', 'build', 'lib', src_dir, 'webserver', 'node_modules')),
ignore_errors=True)
class CleanCommand(Command):
"""Custom clean command to tidy up the project root."""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
@staticmethod
def run():
shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), 'build')), ignore_errors=True)
shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), 'dist')), ignore_errors=True)
shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), '*.pyc')), ignore_errors=True)
shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), 'unmanic.egg-info')), ignore_errors=True)
[shutil.rmtree(f) for f in glob.glob(src_dir + "/**/__pycache__", recursive=True)]
class FullVersionCommand(Command):
"""Custom clean command to tidy up the project root."""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
@staticmethod
def run():
print(versioninfo.full_version())
cmd_class = {
'build_py': BuildPyCommand,
'write-build-version': WriteVersionCommand,
'build-web': BuildWebUICommand,
'clean': CleanCommand,
'fullversion': FullVersionCommand,
}
def requirements():
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements.txt'))) as f:
return f.read().splitlines()
def requirements_dev():
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements-dev.txt'))) as f:
return f.read().splitlines()
setup(
name=module_name,
version=module_version,
author=module_author,
author_email=module_email,
maintainer=module_author,
maintainer_email=module_email,
description=module_description,
url=module_url,
classifiers=module_classifiers,
install_requires=requirements(),
extras_require={
'dev': requirements_dev()
},
packages=[src_dir],
entry_points={
'console_scripts': [
'%s=%s.service:main' % (module_name, module_name)
]
},
cmdclass=cmd_class,
)