Skip to content

Commit

Permalink
feat: language selection in cell context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
CrystallineCat committed Aug 20, 2022
1 parent d884eb7 commit 31b663e
Show file tree
Hide file tree
Showing 47 changed files with 13,238 additions and 463 deletions.
2 changes: 2 additions & 0 deletions applications/desktop/src/notebook/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { middlewares as coreMiddlewares, reducers } from "@nteract/core";
import { configuration } from "@nteract/mythic-configuration";
import { languageInfo } from "@nteract/mythic-notebook";
import { notifications } from "@nteract/mythic-notifications";
import { windowing } from "@nteract/mythic-windowing";
import { makeConfigureStore, MythicAction } from "@nteract/myths";
Expand All @@ -14,6 +15,7 @@ export const configureStore : (initialState?: DesktopNotebookAppState) => Store<
configuration,
notifications,
windowing,
languageInfo,
],
reducers: {
app: reducers.app,
Expand Down
1 change: 1 addition & 0 deletions applications/desktop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{ "path": "../../packages/types" },
{ "path": "../../packages/editor" },
{ "path": "../../packages/mythic-configuration" },
{ "path": "../../packages/mythic-notebook" },
{ "path": "../../packages/mythic-notifications" },
{ "path": "../../packages/mythic-windowing" },
{ "path": "../../packages/myths" },
Expand Down
3 changes: 2 additions & 1 deletion applications/web/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
makeTransformsRecord,
reducers,
} from "@nteract/core";
import { languageInfo } from "@nteract/mythic-notebook";
import { notifications } from "@nteract/mythic-notifications";
import { makeConfigureStore } from "@nteract/myths";
import { Media } from "@nteract/outputs";
Expand Down Expand Up @@ -71,7 +72,7 @@ export const initialState = Record<AppState>({
})();

const configureStore = makeConfigureStore<AppState>()({
packages: [notifications],
packages: [notifications, languageInfo],
reducers: {
app: reducers.app,
core: reducers.core as any,
Expand Down
3 changes: 3 additions & 0 deletions applications/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
{
"path": "../../packages/mythic-notifications"
},
{
"path": "../../packages/mythic-notebook"
},
{
"path": "../../packages/styles"
},
Expand Down
24 changes: 0 additions & 24 deletions packages/actions/__tests__/actions-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@ import * as actionTypes from "../src";

const actions = actionTypes;

describe("setLanguageInfo", () => {
test("creates a SET_LANGUAGE_INFO action", () => {
const langInfo = {
codemirror_mode: { name: "ipython", version: 3 },
file_extension: ".py",
mimetype: "text/x-python",
name: "python",
nbconvert_exporter: "python",
pygments_lexer: "ipython3",
version: "3.5.1"
};

const kernelRef = createKernelRef();
const contentRef = createContentRef();

expect(
actions.setLanguageInfo({ langInfo, kernelRef, contentRef })
).toEqual({
type: actionTypes.SET_LANGUAGE_INFO,
payload: { langInfo, kernelRef, contentRef }
});
});
});

describe("unhideAll", () => {
test("allows being called with sets defaults for outputHidden and inputHidden", () => {
const contentRef = createContentRef();
Expand Down
6 changes: 2 additions & 4 deletions packages/actions/src/actionTypes/kernel_misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:max-line-length
import { KernelInfo, KernelspecRecord, LanguageInfoMetadata } from "@nteract/types";
import { KernelInfo, KernelspecRecord } from "@nteract/types";
import { Action, ErrorAction, HasContent, HasKernel, makeActionFunction, makeErrorActionFunction } from "../utils";

export const SET_KERNEL_INFO = "CORE/SET_KERNEL_INFO";
Expand All @@ -10,17 +10,15 @@ export const KERNEL_RAW_STDERR = "KERNEL_RAW_STDERR";
export const DELETE_CONNECTION_FILE_FAILED = "DELETE_CONNECTION_FILE_FAILED";
export const DELETE_CONNECTION_FILE_SUCCESSFUL = "DELETE_CONNECTION_FILE_SUCCESSFUL";

export type SetKernelInfo = Action <typeof SET_KERNEL_INFO, HasKernel & { info: KernelInfo }>;
export type SetKernelInfo = Action <typeof SET_KERNEL_INFO, HasContent & HasKernel & { info: KernelInfo }>;
export type SetKernelMetadata = Action <typeof SET_KERNEL_METADATA, HasContent & { kernelInfo: KernelspecRecord }>;
export type SetLanguageInfo = Action <typeof SET_LANGUAGE_INFO, HasContent & HasKernel & { langInfo: LanguageInfoMetadata }>;
export type KernelRawStdout = Action <typeof KERNEL_RAW_STDOUT, HasKernel & { text: string }>;
export type KernelRawStderr = Action <typeof KERNEL_RAW_STDERR, HasKernel & { text: string }>;
export type DeleteConnectionFileFailedAction = ErrorAction<typeof DELETE_CONNECTION_FILE_FAILED, HasKernel>;
export type DeleteConnectionFileSuccessfulAction = Action <typeof DELETE_CONNECTION_FILE_SUCCESSFUL, HasKernel>;

export const setKernelInfo = makeActionFunction <SetKernelInfo> (SET_KERNEL_INFO);
export const setKernelMetadata = makeActionFunction <SetKernelMetadata> (SET_KERNEL_METADATA);
export const setLanguageInfo = makeActionFunction <SetLanguageInfo> (SET_LANGUAGE_INFO);
export const kernelRawStdout = makeActionFunction <KernelRawStdout> (KERNEL_RAW_STDOUT);
export const kernelRawStderr = makeActionFunction <KernelRawStderr> (KERNEL_RAW_STDERR);
export const deleteConnectionFileFailed = makeErrorActionFunction <DeleteConnectionFileFailedAction> (DELETE_CONNECTION_FILE_FAILED);
Expand Down
34 changes: 7 additions & 27 deletions packages/commutable/__tests__/v4.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
import Immutable, { Record } from "immutable";

import {
makeDisplayData,
makeErrorOutput,
makeExecuteResult,
makeStreamOutput,
OnDiskStreamOutput
} from "../src/outputs";
import {
createCodeCell,
createMarkdownCell,
NotebookRecordParams,
ImmutableNotebook,
makeNotebookRecord
} from "../src/structures";

import * as Immutable from "immutable";
import { makeDisplayData, makeErrorOutput, makeExecuteResult, makeStreamOutput, OnDiskStreamOutput } from "../src/outputs";
import * as primitives from "../src/primitives";

import {
cellToJS,
outputToJS,
fromJS,
toJS,
NotebookV4,
Cell
} from "../src/v4";
import { CodeCellParams, ImmutableCell } from "../src/cells";
import { createCodeCell, createMarkdownCell, makeNotebookRecord } from "../src/structures";
import { cellToJS, fromJS, NotebookV4, outputToJS, toJS } from "../src/v4";

describe("cellToJS", () => {
it("throws an error for unkown cell types", () => {
const cell = Immutable.Map({
cell_type: "not_real"
});

// @ts-ignore supposed to fail
const invocation = () => cellToJS(cell);

expect(invocation).toThrowError("Cell type unknown at runtime");
});
it("process known cell types", () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/commutable/src/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface MarkdownCellParams {
id?: string;
source: string;
metadata: ImmutableMap<string, any>;
attachments: ImmutableMap<string, ImmutableMap<string, string>>;
}

export const makeMarkdownCell = Record<MarkdownCellParams>({
Expand All @@ -60,6 +61,7 @@ export const makeMarkdownCell = Record<MarkdownCellParams>({
}),
}),
source: "",
attachments: ImmutableMap(),
});

export type ImmutableMarkdownCell = RecordOf<MarkdownCellParams>;
Expand All @@ -71,6 +73,7 @@ export interface RawCellParams {
cell_type: "raw";
source: string;
metadata: ImmutableMap<string, any>;
attachments: ImmutableMap<string, ImmutableMap<string, string>>;
}

export const makeRawCell = Record<RawCellParams>({
Expand All @@ -83,6 +86,7 @@ export const makeRawCell = Record<RawCellParams>({
}),
}),
source: "",
attachments: ImmutableMap(),
});

export type ImmutableRawCell = RecordOf<RawCellParams>;
Expand Down
2 changes: 1 addition & 1 deletion packages/commutable/src/structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type ImmutableNotebook = ImmutableRecord<NotebookRecordParams> &
export const makeNotebookRecord = ImmutableRecord<NotebookRecordParams>({
cellOrder: ImmutableList(),
cellMap: ImmutableMap(),
nbformat_minor: 0,
nbformat_minor: 5,
nbformat: 4,
metadata: ImmutableMap()
});
Expand Down
34 changes: 2 additions & 32 deletions packages/epics/__tests__/kernel-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,10 @@ describe("acquireKernelInfo", () => {
const actions = await obs.pipe(toArray()).toPromise();

expect(actions).toEqual([
{
payload: {
contentRef: "fakeContentRef",
kernelRef: "fakeKernelRef",
langInfo: {
name: "python",
version: "3.6.5",
mimetype: "text/x-python",
codemirror_mode: { name: "ipython", version: 3 },
pygments_lexer: "ipython3",
nbconvert_exporter: "python",
file_extension: ".py"
}
},
type: "SET_LANGUAGE_INFO"
},
{
type: "CORE/SET_KERNEL_INFO",
payload: {
contentRef: "fakeContentRef",
info: {
protocolVersion: "5.1",
implementation: "ipython",
Expand Down Expand Up @@ -316,25 +301,10 @@ describe("acquireKernelInfo", () => {
const actions = await obs.pipe(toArray()).toPromise();

expect(actions).toEqual([
{
payload: {
contentRef: "fakeContentRef",
kernelRef: "fakeKernelRef",
langInfo: {
name: "python",
version: "3.6.5",
mimetype: "text/x-python",
codemirror_mode: { name: "ipython", version: 3 },
pygments_lexer: "ipython3",
nbconvert_exporter: "python",
file_extension: ".py"
}
},
type: "SET_LANGUAGE_INFO"
},
{
type: "CORE/SET_KERNEL_INFO",
payload: {
contentRef: "fakeContentRef",
info: {
protocolVersion: "5.1",
implementation: "ipython",
Expand Down
7 changes: 1 addition & 6 deletions packages/epics/src/kernel-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,9 @@ export function acquireKernelInfo(
];
} else {
result = [
// The original action we were using
actions.setLanguageInfo({
langInfo: msg.content.language_info,
kernelRef,
contentRef
}),
actions.setKernelInfo({
kernelRef,
contentRef,
info
}),
actions.setExecutionState({ kernelStatus: KernelStatus.Launched, kernelRef })
Expand Down
47 changes: 0 additions & 47 deletions packages/monaco-editor/src/converter.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/monaco-editor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { default, IMonacoProps, IMonacoShortCutProps } from "./MonacoEditor";

export { completionProvider } from "./completions/completionItemProvider";
export {Mode, mapCodeMirrorModeToMonaco } from "./converter";

export { DocumentUri } from "./documentUri";
export {LightThemeName, DarkThemeName } from "./theme";
Expand Down
31 changes: 31 additions & 0 deletions packages/mythic-notebook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# @nteract/mythic-notebook

This package implements a model of an `.ipynb`-notebook based on the `myths` package system.

Each subdirectory of `src/` is a mythic package dealing with one aspect of `.pynb`-notebooks.

## Installation

```
$ yarn add @nteract/mythic-notebook
```

```
$ npm install --save @nteract/mythic-notebook
```

## Usage

TBD

## API

TBD

## Support

If you experience an issue while using this package or have a feature request, please file an issue on the [issue board](https://github.com/nteract/nteract/issues/new/choose) and add the `pkg:mythic-notebook` label.

## License

[BSD-3-Clause](https://choosealicense.com/licenses/bsd-3-clause/)

0 comments on commit 31b663e

Please sign in to comment.