forked from Irrational-Encoding-Wizardry/yuuno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
233 lines (186 loc) · 7.25 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Yuuno - IPython + VapourSynth
# Copyright (C) 2018 cid-chan (Sarah <[email protected]>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import json
from distutils.log import INFO
from distutils.command.build import build
from setuptools import setup, find_packages
from setuptools.command.sdist import sdist
from setuptools.command.install import install
from setuptools.command.build_py import build_py
try:
from Cython.Build import cythonize
extensions = cythonize("yuuno/vs/_audioop.pyx")
except ImportError:
extensions = []
DIRNAME = os.path.dirname(__file__) if __file__ else os.getcwd()
class NPMBuild(build_py):
ENV_NAME = ""
JS_PROJECT_PATH = ""
SUCCESS_FILE = ""
TARGET_PATH = ""
@classmethod
def for_build(cls, **args):
return type("NPMBuild", (cls,), args)
def ensure_package_managers(self):
import shutil
yarn = shutil.which("yarn")
if yarn is None:
raise RuntimeError("Couldn't find Yarn.")
lerna = shutil.which("lerna")
if lerna is None:
raise RuntimeError("Couldn't find Lerna.")
return yarn, lerna
def popen(self, cmd, *args, **kwargs):
self.announce(f"running command: {cmd}", level=INFO)
import shlex
import subprocess
return subprocess.check_call(shlex.split(cmd), *args, **kwargs)
def run(self):
cwd = DIRNAME
target_dir = os.path.join(cwd, self.TARGET_PATH)# "yuuno_ipython", "build")
target_file = os.path.join(target_dir, self.SUCCESS_FILE)# "extension.js")
if os.path.exists(self.JS_PROJECT_PATH):
if os.path.exists(target_file):
self.announce(f"cleaning build target.", level=INFO)
import shutil
shutil.rmtree(target_dir)
if os.environ.get(self.ENV_NAME, ""):
compiled_path = os.environ[self.ENV_NAME]
if not os.path.exists(os.path.join(compiled_path, self.SUCCESS_FILE)):
raise EnvironmentError("Could not find built extension.")
import shutil
shutil.copytree(compiled_path, target_dir)
self.announce("Used build from environment.")
return
if os.path.exists(self.JS_PROJECT_PATH):
yarn, lerna = self.ensure_package_managers()
self.popen(f'"{lerna}" bootstrap')
self.popen(f'"{yarn}" run build', cwd=f"{DIRNAME}/packages/widgets")
self.popen(f'"{yarn}" run build', cwd=f"{DIRNAME}/packages/jupyterlab")
self.popen(f'"{yarn}" run build', cwd=f"{DIRNAME}/packages/notebook")
elif os.path.exists(target_file):
self.announce("source distribution with prebuilt binaries detected. Skipping build.")
else:
raise EnvironmentError("sdist without prebuild javascript.")
class SDistNPM(sdist):
def run(self):
if not os.path.exists(os.path.join(DIRNAME, "yuuno_ipython", "build", "jupyter.js")):
self.run_command('build')
super().run()
class Install(install):
def run(self):
cwd = DIRNAME
if not os.path.exists(os.path.join(cwd, "yuuno_ipython", "build", "jupyter.js")):
self.run_command('build')
super().run()
class Build(build):
def run(self):
self.run_command('build_npm_lab')
super().run()
with open('README', encoding="utf8") as readme_file:
readme = readme_file.read()
with open('HISTORY.rst', encoding="utf8") as history_file:
history = history_file.read()
requirements = [
"jupyter",
"jupyterlab",
"traitlets",
"jinja2",
"ipywidgets",
"pillow",
"psutil"
]
test_requirements = []
extras_requires = {
'vapoursynth': ['vapoursynth', 'vsutil']
}
def recursive(path, prefix, extras=None):
if extras is None:
extras = {}
for dirpath, _, files in os.walk(path):
kdpath = dirpath[len(path):]
if not files and not extras.get(kdpath, ()): continue
npath = f"{path}{kdpath}" if kdpath else path
npfx = f"{prefix}{kdpath}" if kdpath else prefix
yield (npfx, [f"{npath}/{file}" for file in files] + extras.get(npfx, []))
setup(
name='yuuno',
version='1.5dev1',
description="Yuuno = Jupyter + VapourSynth",
long_description=readme + '\n\n' + history,
long_description_content_type = "text/plain",
author="cid-chan",
author_email='[email protected]',
url='https://github.com/Irrational-Encoding-Wizardry/yuuno',
packages=find_packages(exclude=("tests", )),
data_files=[
("share/jupyter/nbextensions", [
"yuuno_ipython/static/extension/yuuno-platform.js"
]),
("share/jupyter/nbextensions/yuuno-platform", [
"yuuno_ipython/static/extension/yuuno-platform/index.js"
]),
("etc/jupyter/nbconfig/notebook.d", [
"yuuno_ipython/static/config/yuuno-jupyter.json"
]),
*recursive("yuuno_jupyterlab/static", "share/jupyter/labextensions/@yuuno/jupyterlab", {
"share/jupyter/labextensions/@yuuno/jupyterlab": [
"yuuno_jupyterlab/config/labextensions/install.json"
]
}),
],
package_dir={'yuuno_ipython': 'yuuno_ipython'},
package_data={'yuuno_ipython': ['static/*', 'build/*']},
# ext_modules=extensions,
include_package_data=True,
install_requires=requirements,
license="GNU Affero General Public License v3 (AGPLv3)",
zip_safe=False,
keywords='yuuno',
cmdclass={
'sdist': SDistNPM,
'build': Build,
'build_npm_lab': NPMBuild.for_build(
ENV_NAME = "COMPILED_YUUNO_LAB_JS",
JS_PROJECT_PATH = "packages",
SUCCESS_FILE = "package.json",
TARGET_PATH = "yuuno_jupyterlab/static"
),
'install': Install
},
classifiers=[
'Natural Language :: English',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Other Audience',
'License :: OSI Approved :: GNU Affero General Public License v3',
'Programming Language :: Python :: 3.9',
'Framework :: Jupyter',
'Framework :: Jupyter :: JupyterLab',
'Framework :: Jupyter :: JupyterLab :: 3',
'Framework :: Jupyter :: JupyterLab :: Extensions',
'Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt',
'Topic :: Multimedia :: Video',
'Topic :: Multimedia :: Video :: Display',
'Topic :: Multimedia :: Video :: Non-Linear Editor',
],
entry_points={
'console_scripts': ['yuuno=yuuno.console_scripts:main']
}
)