kapsikkum-unmanic – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3  
4 """
5 unmanic.setup.py
6  
7 Written by: Josh.5 <jsunnex@gmail.com>
8 Date: 04 May 2020, (10:47 AM)
9  
10 Copyright:
11 Copyright (C) Josh Sunnex - All Rights Reserved
12  
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19  
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22  
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
29 OR OTHER DEALINGS IN THE SOFTWARE.
30  
31 """
32 import json
33 import os
34 import shutil
35 import subprocess
36 import sys
37 import glob
38 from setuptools import setup, find_packages, Command, find_namespace_packages
39 import setuptools.command.build_py
40  
41 if sys.version_info[0] < 3:
42 print("This module version requires Python 3.")
43 sys.exit(1)
44  
45 sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
46 import versioninfo
47  
48 project_root_dir = os.path.dirname(os.path.realpath(__file__))
49 src_dir = 'unmanic'
50  
51 module_name = versioninfo.name()
52 module_version = versioninfo.version()
53 module_description = versioninfo.description()
54 module_author = versioninfo.author()
55 module_email = versioninfo.email()
56 module_url = versioninfo.url()
57 module_classifiers = [
58 versioninfo.dev_status(),
59 'Intended Audience :: End Users/Desktop',
60 'Intended Audience :: Developers',
61 'Programming Language :: Python :: 3.7',
62 'Programming Language :: Python :: 3.8',
63 'Programming Language :: Python :: 3.9',
64 'Programming Language :: Python :: 3.10',
65 'Programming Language :: Python :: 3.11',
66 'Programming Language :: Python :: 3.12',
67 'Operating System :: POSIX :: Linux',
68 'Operating System :: Unix',
69 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
70 'Topic :: Multimedia :: Video :: Conversion',
71 'Topic :: Internet :: WWW/HTTP',
72 ]
73  
74  
75 class BuildPyCommand(setuptools.command.build_py.build_py):
76 """Custom build command."""
77  
78 def run(self):
79 setuptools.command.build_py.build_py.run(self)
80 self.run_command('write-build-version')
81 self.run_command('build-frontend')
82  
83  
84 class WriteVersionCommand(Command):
85 user_options = []
86  
87 def initialize_options(self):
88 pass
89  
90 def finalize_options(self):
91 pass
92  
93 @staticmethod
94 def run():
95 version_file = os.path.join('.', 'build', 'lib', src_dir, 'version')
96 data = {
97 'short': versioninfo.version(),
98 'long': versioninfo.full_version(),
99 }
100 with open(version_file, 'w') as f:
101 json.dump(data, f)
102  
103  
104 class BuildFrontendCommand(setuptools.command.build_py.build_py):
105 """Frontend build command."""
106  
107 def run(self):
108 setuptools.command.build_py.build_py.run(self)
109  
110 public_asset_path = os.path.abspath(os.path.join('.', 'build', 'lib', src_dir, 'webserver', 'public'))
111 frontend_path = os.path.abspath(os.path.join('.', 'build', 'lib', src_dir, 'webserver', 'frontend'))
112  
113 # Start by clearing out anything if this was pulled from a dirty tree
114 shutil.rmtree(public_asset_path, ignore_errors=True)
115 shutil.rmtree(os.path.join(frontend_path, 'node_modules'), ignore_errors=True)
116  
117 # Install all modules
118 subprocess.run(
119 "npm ci",
120 check=True,
121 shell=True,
122 cwd=frontend_path,
123 )
124 # Build the frontend
125 subprocess.run(
126 "npm run build:publish",
127 check=True,
128 shell=True,
129 cwd=frontend_path,
130 )
131  
132 # Move built dist to templates directory
133 shutil.move(os.path.join(frontend_path, 'dist', 'spa'), public_asset_path)
134 # Remove the frontend source from the package (we will not distribute these)
135 shutil.rmtree(frontend_path, ignore_errors=True)
136  
137  
138 class CleanCommand(Command):
139 """Custom clean command to tidy up the project root."""
140 user_options = []
141  
142 def initialize_options(self):
143 pass
144  
145 def finalize_options(self):
146 pass
147  
148 @staticmethod
149 def run():
150 shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), 'build')), ignore_errors=True)
151 shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), 'dist')), ignore_errors=True)
152 shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), '*.pyc')), ignore_errors=True)
153 shutil.rmtree(os.path.abspath(os.path.join(os.path.dirname(__file__), 'unmanic.egg-info')), ignore_errors=True)
154 [shutil.rmtree(f) for f in glob.glob(src_dir + "/**/__pycache__", recursive=True)]
155  
156  
157 class FullVersionCommand(Command):
158 """Custom clean command to tidy up the project root."""
159 user_options = []
160  
161 def initialize_options(self):
162 pass
163  
164 def finalize_options(self):
165 pass
166  
167 @staticmethod
168 def run():
169 print(versioninfo.full_version())
170  
171  
172 cmd_class = {
173 'build_py': BuildPyCommand,
174 'write-build-version': WriteVersionCommand,
175 'build-frontend': BuildFrontendCommand,
176 'clean': CleanCommand,
177 'fullversion': FullVersionCommand,
178 }
179  
180  
181 def requirements():
182 with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements.txt'))) as f:
183 return f.read().splitlines()
184  
185  
186 def requirements_dev():
187 with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements-dev.txt'))) as f:
188 return f.read().splitlines()
189  
190  
191 setup(
192 name=module_name,
193 version=module_version,
194 author=module_author,
195 author_email=module_email,
196 maintainer=module_author,
197 maintainer_email=module_email,
198 description=module_description,
199 url=module_url,
200 classifiers=module_classifiers,
201 install_requires=requirements(),
202 extras_require={
203 'dev': requirements_dev()
204 },
205 packages=find_namespace_packages(include=[f"{src_dir}*"]),
206 include_package_data=True,
207 entry_points={
208 'console_scripts': [
209 '%s=%s.service:main' % (module_name, module_name)
210 ]
211 },
212 cmdclass=cmd_class,
213 )