Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _run(self, cmd, **kwargs):
"""Run the command using our logger and abort callback.
Returns the exit code.
"""
if self.kill_event.is_set():
raise ValueError('Command was killed')
kwargs['logger'] = self.logger
kwargs['kill_event'] = self.kill_event
proc = Process(cmd, **kwargs)
return proc.wait()
def ensure_dev(logger=None):
"""Ensure that the dev assets are available.
"""
parent = pjoin(HERE, '..')
if not osp.exists(pjoin(parent, 'node_modules')):
yarn_proc = Process(['node', YARN_PATH], cwd=parent, logger=logger)
yarn_proc.wait()
if not osp.exists(pjoin(parent, 'dev_mode', 'build')):
yarn_proc = Process(['node', YARN_PATH, 'build'], cwd=parent,
logger=logger)
yarn_proc.wait()
def watch_dev(logger=None):
"""Run watch mode in a given directory.
Parameters
----------
logger: :class:`~logger.Logger`, optional
The logger instance.
Returns
-------
A list of `WatchHelper` objects.
"""
parent = pjoin(HERE, '..')
if not osp.exists(pjoin(parent, 'node_modules')):
yarn_proc = Process(['node', YARN_PATH], cwd=parent, logger=logger)
yarn_proc.wait()
logger = logger or logging.getLogger('jupyterlab')
ts_dir = osp.realpath(osp.join(HERE, '..', 'packages', 'metapackage'))
# Run typescript watch and wait for compilation.
ts_regex = r'.* Compilation complete\. Watching for file changes\.'
ts_proc = WatchHelper(['node', YARN_PATH, 'run', 'watch'],
cwd=ts_dir, logger=logger, startup_regex=ts_regex)
# Run the metapackage file watcher.
tsf_regex = 'Watching the metapackage files...'
tsf_proc = WatchHelper(['node', YARN_PATH, 'run', 'watch:files'],
cwd=ts_dir, logger=logger, startup_regex=tsf_regex)
# Run webpack watch and wait for compilation.
def _run_command(self):
command, kwargs = self.get_command()
kwargs.setdefault('logger', self.log)
future = Process(command, **kwargs).wait_async()
IOLoop.current().add_future(future, self._process_finished)
self._stdout = os.fdopen(master, 'rb')
else:
kwargs['stdout'] = subprocess.PIPE
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
kwargs['startupinfo'] = startupinfo
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
kwargs['shell'] = True
return super(WatchHelper, self)._create_process(**kwargs)
# Register the cleanup handler.
atexit.register(Process._cleanup)
if os.name == 'nt':
kwargs['shell'] = True
proc = subprocess.Popen(cmd, **kwargs)
return proc
@classmethod
def _cleanup(cls):
"""Clean up the started subprocesses at exit.
"""
for proc in list(cls._procs):
proc.terminate()
class WatchHelper(Process):
"""A process helper for a watch process.
"""
def __init__(self, cmd, startup_regex, logger=None, cwd=None,
kill_event=None, env=None):
"""Initialize the process helper.
Parameters
----------
cmd: list
The command to run.
startup_regex: string
The regex to wait for at startup.
logger: :class:`~logger.Logger`, optional
The logger instance.
cwd: string, optional