-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
setupbase.py
107 lines (81 loc) · 2.93 KB
/
setupbase.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
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) Spyder Project Contributors
# Copyright (c) 2015-, Jupyter Development Team.
# Copyright (c) 2008-2015, IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# -----------------------------------------------------------------------------
"""
General setup rules to download external JS dependencies
via Bower
Some functions were taken from the Jupyter Notebook
setupbase definition
See: https://github.com/jupyter/notebook/blob/master/setupbase.py
"""
import os
import os.path as osp
import pipes
import shutil
import sys
from distutils import log
from distutils.core import Command
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist
from subprocess import check_call
if sys.platform == 'win32':
from subprocess import list2cmdline
else:
def list2cmdline(cmd_list):
return ' '.join(map(pipes.quote, cmd_list))
HERE = os.path.abspath(os.path.dirname(__file__))
COMPONENTS = osp.join(HERE, 'spyder_terminal', 'server', 'static',
'components')
repo_root = os.path.dirname(os.path.abspath(__file__))
def run(cmd, *args, **kwargs):
"""Echo a command before running it"""
log.info('> ' + list2cmdline(cmd))
kwargs['shell'] = (sys.platform == 'win32')
return check_call(cmd, *args, **kwargs)
class BuildStatic(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if not osp.isdir(COMPONENTS):
log.info("running [yarn install]")
run(['yarn', 'install'], cwd=repo_root)
log.info("installing webpack")
run(['npm', 'i', '-D', 'webpack'], cwd=repo_root)
run(['npm', 'i', 'webpack-cli', 'html-webpack-plugin', 'xterm',
'xterm-addon-attach', 'xterm-addon-search',
'xterm-addon-web-links', 'xterm-addon-fit'],
cwd=repo_root)
log.info('running webpack')
run(['npm', 'run', 'webpack'], cwd=repo_root)
class DevelopWithBuildStatic(develop):
def install_for_development(self):
self.run_command('build_static')
return develop.install_for_development(self)
class SdistWithBuildStatic(sdist):
def run(self):
self.run_command('build_static')
sdist.run(self)
def make_distribution(self):
if not osp.isdir(COMPONENTS):
print("\nWARNING: Server components are missing!! We can't "
"proceed further!\n")
sys.exit(1)
return sdist.make_distribution(self)
class CleanComponents(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
log.info("Removing server components")
shutil.rmtree(COMPONENTS, ignore_errors=True)