forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jlpmapp.py
70 lines (57 loc) · 2.05 KB
/
jlpmapp.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
# coding: utf-8
"""A Jupyter-aware wrapper for the yarn package manager"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import sys
import os
from ipython_genutils.py3compat import which as _which
try:
import subprocess32 as subprocess
except ImportError:
import subprocess
HERE = os.path.dirname(os.path.abspath(__file__))
YARN_PATH = os.path.join(HERE, 'staging', 'yarn.js')
def execvp(cmd, argv):
"""Execvp, except on Windows where it uses Popen.
The first argument, by convention, should point to the filename
associated with the file being executed.
Python provides execvp on Windows, but its behavior is problematic
(Python bug#9148).
"""
cmd = which(cmd)
if os.name == 'nt':
import signal
import sys
p = subprocess.Popen([cmd] + argv[1:])
# Don't raise KeyboardInterrupt in the parent process.
# Set this after spawning, to avoid subprocess inheriting handler.
signal.signal(signal.SIGINT, signal.SIG_IGN)
p.wait()
sys.exit(p.returncode)
else:
os.execvp(cmd, argv)
def which(command, env=None):
"""Get the full path to a command.
Parameters
----------
command: str
The command name or path.
env: dict, optional
The environment variables, defaults to `os.environ`.
"""
env = env or os.environ
path = env.get('PATH') or os.defpath
command_with_path = _which(command, path=path)
if command_with_path is None:
if command in ['node', 'npm']:
msg = 'Please install nodejs and npm before continuing installation. nodejs may be installed using conda or directly from the website.'
raise ValueError(msg)
raise ValueError('The command was not found or was not ' +
'executable: %s.' % command)
return command_with_path
def main(argv=None):
"""Run node and return the result.
"""
# Make sure node is available.
argv = argv or sys.argv[1:]
execvp('node', ['node', YARN_PATH] + argv)