How to use @jupyterlab/services - 10 common examples

To help you get started, we’ve selected a few @jupyterlab/services examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab-data-explorer / tests / test-services / src / kernel / ikernel.spec.ts View on Github external
}
      });

      // Send a shell message with the wrong client (parent) session.
      const msg1 = KernelMessage.createMessage({
        msgType: 'kernel_info_request',
        channel: 'shell',
        session: tester.serverSessionId,
        msgId: 'message from wrong session',
        content: {}
      });
      msg1.parent_header = { session: 'wrong session' };
      tester.send(msg1);

      // Send a shell message with the right client (parent) session.
      const msg2 = KernelMessage.createMessage({
        msgType: 'kernel_info_request',
        channel: 'shell',
        session: tester.serverSessionId,
        msgId: msgId,
        content: {}
      });
      msg2.parent_header = { session: kernel.clientId };
      tester.send(msg2);

      await emission;
    });
  });
github yuvipanda / simplest-notebook / tests / utils.ts View on Github external
} catch (error) {
    return; // Ignore calls to dismiss the dialog if there is no dialog.
  }

  const node = host.getElementsByClassName('jp-Dialog')[0];

  if (node) {
    simulate(node as HTMLElement, 'keydown', { keyCode: 27 });
  }
}

/**
 * A namespace for private data.
 */
namespace Private {
  export const manager = new ServiceManager();

  export const textFactory = new TextModelFactory();

  export const notebookFactory = new NotebookModelFactory({});

  class JSONRenderer extends RenderedHTML {
    mimeType = 'text/html';

    renderModel(model: IRenderMime.IMimeModel): Promise {
      let source = model.data['application/json'];
      model.setData({ data: { 'text/html': json2html(source) } });
      return super.renderModel(model);
    }
  }

  const jsonRendererFactory = {
github jupyterlab / jupyterlab / tests / test-filebrowser / src / crumbs.spec.ts View on Github external
before(async () => {
    const opener: DocumentManager.IWidgetOpener = {
      open: widget => {
        /* no op */
      }
    };

    registry = new DocumentRegistry({
      textModelFactory: new TextModelFactory()
    });
    serviceManager = new ServiceManager({ standby: 'never' });
    iconRegistry = defaultIconRegistry;
    manager = new DocumentManager({
      registry,
      opener,
      manager: serviceManager
    });

    const contents = serviceManager.contents;
    let cModel = await contents.newUntitled({ type: 'directory' });
    first = cModel.name;
    cModel = await contents.newUntitled({
      path: cModel.path,
      type: 'directory'
    });
    second = cModel.name;
    cModel = await contents.newUntitled({
github jupyterlab / jupyterlab / tests / test-console / src / foreign.spec.ts View on Github external
before(async function() {
      // tslint:disable-next-line:no-invalid-this
      this.timeout(60000);

      const path = UUID.uuid4();
      [local, foreign, session] = await Promise.all([
        Session.startNew({ path }),
        Session.startNew({ path }),
        createClientSession({ path })
      ]);

      // check path prop
      expect(local.path).to.equal(path);

      await (session as ClientSession).initialize();
      await session.kernel.ready;
    });
github jupyterlab / jupyterlab / packages / services / examples / node / index.js View on Github external
var services = require('@jupyterlab/services');

// Start a new session.
var options = {
  path: 'foo.ipynb',
  type: 'notebook',
  name: 'foo.ipynb',
  kernel: {
    name: 'python'
  }
};

/* eslint-disable no-console */
console.log('Starting session...');
var kernelManager = new services.KernelManager();
var sessionManager = new services.SessionManager({ kernelManager });
var session;
sessionManager
  .startNew(options)
  .then(function(s) {
    // Rename the session.
    session = s;
    return session.setPath('bar.ipynb');
  })
  .then(function() {
    console.log('Session renamed to', session.path);
    // Execute and handle replies on the kernel.
    var future = session.kernel.requestExecute({ code: 'a = 1' });
    future.onReply = function(reply) {
      console.log('Got execute reply', reply);
    };
github jupyterlab / jupyterlab / packages / services / examples / node / index.js View on Github external
var services = require('@jupyterlab/services');

// Start a new session.
var options = {
  path: 'foo.ipynb',
  type: 'notebook',
  name: 'foo.ipynb',
  kernel: {
    name: 'python'
  }
};

/* eslint-disable no-console */
console.log('Starting session...');
var kernelManager = new services.KernelManager();
var sessionManager = new services.SessionManager({ kernelManager });
var session;
sessionManager
  .startNew(options)
  .then(function(s) {
    // Rename the session.
    session = s;
    return session.setPath('bar.ipynb');
  })
  .then(function() {
    console.log('Session renamed to', session.path);
    // Execute and handle replies on the kernel.
    var future = session.kernel.requestExecute({ code: 'a = 1' });
    future.onReply = function(reply) {
      console.log('Got execute reply', reply);
    };
    return future.done;
github hadim / jupyter-archive / src / index.ts View on Github external
function downloadArchiveRequest(
  path: string,
  archiveFormat: ArchiveFormat
): Promise {
  const settings = ServerConnection.makeSettings();

  let baseUrl = settings.baseUrl;
  let url = URLExt.join(baseUrl, DIRECTORIES_URL, URLExt.encodeParts(path));

  const fullurl = new URL(url);

  // Generate a random token.
  const rand = () =>
    Math.random()
      .toString(36)
      .substr(2);
  const token = (length: number) =>
    (rand() + rand() + rand() + rand()).substr(0, length);

  fullurl.searchParams.append("archiveToken", token(20));
  fullurl.searchParams.append("archiveFormat", archiveFormat);
github minrk / thebelab / src / thebelab.js View on Github external
export function requestKernel(kernelOptions) {
  // request a new Kernel
  kernelOptions = mergeOptions({ kernelOptions }).kernelOptions;
  if (kernelOptions.serverSettings) {
    let ss = kernelOptions.serverSettings;
    // workaround bug in jupyterlab where wsUrl and baseUrl must both be set
    // https://github.com/jupyterlab/jupyterlab/pull/4427
    if (ss.baseUrl && !ss.wsUrl) {
      ss.wsUrl = "ws" + ss.baseUrl.slice(4);
    }
    kernelOptions.serverSettings = ServerConnection.makeSettings(
      kernelOptions.serverSettings
    );
  }
  events.trigger("status", {
    status: "starting",
    message: "Starting Kernel",
  });
  let p = Session.startNew(kernelOptions);
  p.then(session => {
    events.trigger("status", {
      status: "ready",
      message: "Kernel is ready",
    });
    let k = session.kernel;
    return k;
  });
github dask / dask-labextension / src / dashboard.tsx View on Github external
export function testDaskDashboard(
    url: string,
    settings: ServerConnection.ISettings
  ): Promise {
    url = normalizeDashboardUrl(url);

    // If this is a url that we are proxying under the notebook server,
    // it is easier to check for a valid dashboard.
    if (URLExt.isLocal(url)) {
      return ServerConnection.makeRequest(
        URLExt.join(settings.baseUrl, url, 'individual-plots.json'),
        {},
        settings
      ).then(response => {
        if (response.status === 200) {
          return true;
        } else {
          return false;
        }
      });
    }

    return new Promise(resolve => {
      // Hack Alert! We would like to test whether a given URL is actually
      // a dask dashboard, since we will be iframe-ing it sight-unseen.
      // However, CORS policies prevent us from doing a normal fetch
github pymedphys / pymedphys / packages / pymedphys / src / pymedphys / gui / src / jupyter.tsx View on Github external
// let opener = {
//   open: (widget: Widget) => {
//     if (widgets.indexOf(widget) === -1) {
//       dock.addWidget(widget, { mode: 'tab-after' });
//       widgets.push(widget);
//     }
//     dock.activateWidget(widget);
//     activeWidget = widget;
//     widget.disposed.connect((w: Widget) => {
//       let index = widgets.indexOf(w);
//       widgets.splice(index, 1);
//     });
//   }
// };

let serviceManager = new ServiceManager();
// let docRegistry = new DocumentRegistry();
// let docManager = new DocumentManager({
//   registry: docRegistry,
//   manager: serviceManager,
//   opener
// });

// let context = new Context({
//   manager: serviceManager
// })

// let widget = new Widget()

// docManager

// docRegistry.addWidgetExtension('Notebook', new NBWidgetExtension())