Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
----------
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 = _ensure_logger(logger)
ts_dir = osp.realpath(osp.join(HERE, '..', 'packages', 'metapackage'))
# Run typescript watch and wait for the string indicating it is done.
ts_regex = r'.* Found 0 errors\. Watching for file changes\.'
ts_proc = WatchHelper(['node', YARN_PATH, 'run', 'watch'],
cwd=ts_dir, logger=logger, startup_regex=ts_regex)
return [ts_proc]
def watch_packages(logger=None):
"""Run watch mode for the source packages.
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 = _ensure_logger(logger)
ts_dir = osp.realpath(osp.join(HERE, '..', 'packages', 'metapackage'))
# Run typescript watch and wait for the string indicating it is done.
ts_regex = r'.* Found 0 errors\. Watching for file changes\.'
ts_proc = WatchHelper(['node', YARN_PATH, 'run', 'watch'],
cwd=ts_dir, logger=logger, startup_regex=ts_regex)
return [ts_proc]
from urllib.request import Request, urlopen, urljoin, quote
from urllib.error import URLError
from jupyter_core.paths import jupyter_config_path
from jupyterlab_server.process import which, Process, WatchHelper
from notebook.nbextensions import GREEN_ENABLED, GREEN_OK, RED_DISABLED, RED_X
from .semver import Range, gte, lt, lte, gt, make_semver
from .jlpmapp import YARN_PATH, HERE
# The regex for expecting the webpack output.
WEBPACK_EXPECT = re.compile(r'.*/index.out.js')
# The dev mode directory.
DEV_DIR = osp.realpath(os.path.join(HERE, '..', 'dev_mode'))
def pjoin(*args):
"""Join paths to create a real path.
"""
return osp.realpath(osp.join(*args))
def get_user_settings_dir():
"""Get the configured JupyterLab user settings directory.
"""
settings_dir = os.environ.get('JUPYTERLAB_SETTINGS_DIR')
settings_dir = settings_dir or pjoin(
jupyter_config_path()[0], 'lab', 'user-settings'
)
return osp.realpath(settings_dir)
def _node_check(logger):
"""Check for the existence of nodejs with the correct version.
"""
node = which('node')
try:
output = subprocess.check_output([node, 'node-version-check.js'], cwd=HERE)
logger.info(output.decode('utf-8'))
except Exception:
data = _get_core_data()
ver = data['engines']['node']
msg = 'Please install nodejs %s before continuing. nodejs may be installed using conda or directly from the nodejs website.' % ver
raise ValueError(msg)
try:
logger.debug('Fetching URL: %s' % (req.full_url))
except AttributeError:
logger.debug('Fetching URL: %s' % (req.get_full_url()))
try:
with contextlib.closing(urlopen(req)) as response:
return json.loads(response.read().decode('utf-8'))
except URLError as exc:
logger.warning(
'Failed to fetch package metadata for %r: %r',
name, exc)
raise
if __name__ == '__main__':
watch_dev(HERE)
def clean(app_dir=None, logger=None):
"""Clean the JupyterLab application directory."""
logger = _ensure_logger(logger)
app_dir = app_dir or get_app_dir()
logger.info('Cleaning %s...', app_dir)
if app_dir == pjoin(HERE, 'dev'):
raise ValueError('Cannot clean the dev app')
if app_dir == pjoin(HERE, 'core'):
raise ValueError('Cannot clean the core app')
for name in ['staging']:
target = pjoin(app_dir, name)
if osp.exists(target):
_rmtree(target, logger)
logger.info('Success!')
def _get_core_data():
"""Get the data for the app template.
"""
with open(pjoin(HERE, 'staging', 'package.json')) as fid:
return json.load(fid)
# Look for mismatched version.
pkg_path = pjoin(staging, 'package.json')
if osp.exists(pkg_path):
with open(pkg_path) as fid:
data = json.load(fid)
if data['jupyterlab'].get('version', '') != version:
_rmtree(staging, self.logger)
os.makedirs(staging)
for fname in ['index.js', 'webpack.config.js',
'webpack.prod.config.js',
'.yarnrc', 'yarn.js']:
target = pjoin(staging, fname)
shutil.copy(pjoin(HERE, 'staging', fname), target)
# Remove an existing yarn.lock file
# Because otherwise we can end up with unwanted duplicates
# cf https://github.com/yarnpkg/yarn/issues/3967
if osp.exists(pjoin(staging, 'yarn.lock')):
os.remove(pjoin(staging, 'yarn.lock'))
# Ensure a clean templates directory
templates = pjoin(staging, 'templates')
if osp.exists(templates):
_rmtree(templates, self.logger)
try:
shutil.copytree(pjoin(HERE, 'staging', 'templates'), templates)
except shutil.Error as error:
# `copytree` throws an error if copying to + from NFS even though