Skip to content

Commit

Permalink
Merge branch 'release/2021.1.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Chan committed Jan 14, 2021
2 parents d1c8983 + 3090301 commit 914fa34
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: clean build check check_lint dev-run-jupyterlab-2.x dev-run-jupyterlab-3.x

clean:
rm -rf venv* lib node_modules *.egg-info jupyterlab_executor/labextension
rm -rf venv* lib node_modules *.egg-info jupyterlab_executor/labextension dist build

venv-jupyterlab-2.x:
virtualenv venv-jupyterlab-2.x
Expand Down Expand Up @@ -32,7 +32,7 @@ dev-run-jupyterlab-3.x: build
jupyter lab

dist: # For JupyterLab >= 3.0
rm -rf dist
rm -rf dist build
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
Expand Down
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# jupyterlab_executor
# jupyterlab-executor

[![PyPI Release](https://img.shields.io/pypi/v/jupyterlab-executor.svg)](https://pypi.org/project/jupyterlab-executor/)

![Github Actions Status](https://github.com/gavincyi/jupyterlab-executor/workflows/Build/badge.svg)

![PyPI Downloads](https://img.shields.io/pypi/dm/jupyterlab-executor.svg)

JupyterLab extension of executing the scripts

[![demo](doc/README/demo.gif)]
![demo](doc/README/demo.gif)

The extension helps the user execute the script in the terminal and provides
multiple common executors, e.g. bash and python. Users can customise the
Expand Down Expand Up @@ -37,7 +41,7 @@ jupyter labextension install @gavincyi/jupyterlab-executor

The executors can be customised from the JupyterLab settings.

[![Customisation settings](doc/README/customisation-settings.png)]
![Customisation settings](doc/README/customisation-settings.png)

Alternatively, the customisation JSON file can be appended into the
[users setting directory](https://jupyterlab.readthedocs.io/en/stable/user/directories.html?highlight=%22jupyterlab-settings%22#jupyterlab-user-settings-directory).
Expand All @@ -50,11 +54,11 @@ and the format is like the following
"executors": [
{
"name": "bash",
"command": "bash "
"command": "bash {path} {args}"
},
{
"name": "python",
"command": "python "
"command": "python {path} {args}"
},
...
]
Expand All @@ -65,13 +69,39 @@ The `executors` variable is a list of descriptions, of which

1. `name` is the string shown in the dialog

2. `command` is the executor command to run
2. `command` is the executor command template to run, where `{path}`
is the file path returned by the content manager in the JupyterLab,
and `args` is the arguments passed in by the users.

The environment variables are always appended at the beginning of the
command.

For example, the following execution parameters

The execution script format is `${command}${path} ${args}`, where
`args` is the user defined arguments in the dialog.
![Execute](doc/README/executor.png)

run the following command on the terminal

```
PYTHONPATH=. bash test.py --time 1
```

## Contributing

### Roadmap

The following features are not yet completed but on the roadmap.

- Inject environment variables

- Support script argument template

- Support default script arguments

- Support refreshing the list of executors after the setting update

The above features will come out very soon.

### Development install

Note: You will need NodeJS to build the extension package.
Expand Down
Binary file modified doc/README/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/README/executor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gavincyi/jupyterlab-executor",
"version": "2021.1.1",
"version": "2021.1.2",
"description": "JupyterLab extension of executing the scripts",
"keywords": [
"jupyter",
Expand Down
4 changes: 2 additions & 2 deletions schema/executor.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"default": [
{
"name": "bash",
"command": "bash "
"command": "bash {path} {args}"
},
{
"name": "python",
"command": "python "
"command": "python {path} {args}"
}
]
}
Expand Down
53 changes: 42 additions & 11 deletions src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export class ExecutorOptions {
executors: any;
}

function createDialogBody(options: ExecutorOptions): HTMLElement {
function createDialogBody(options: ExecutorOptions, path: string): HTMLElement {
const body = document.createElement('div');

// Add executor selector
const executorLabel = document.createElement('label');
executorLabel.textContent = 'Executor';
body.appendChild(executorLabel);
var label = document.createElement('label');
label.textContent = 'Executor';
body.appendChild(label);
const selector = document.createElement('select');
for (const executor of options.executors) {
const option = document.createElement('option');
Expand All @@ -39,11 +39,33 @@ function createDialogBody(options: ExecutorOptions): HTMLElement {
}
body.appendChild(selector);

// Add path (disabled)
label = document.createElement('label');
label.textContent = 'Path';
body.appendChild(label);
var textbox = document.createElement('input');
textbox.className = 'path';
textbox.type = 'text';
textbox.value = path;
textbox.disabled = true;
body.appendChild(textbox);

// Add execute arguments
const arugmentsLabel = document.createElement('label');
arugmentsLabel.textContent = 'Arugments';
body.appendChild(arugmentsLabel);
const textbox = document.createElement('input');
label = document.createElement('label');
label.textContent = 'Arugments';
body.appendChild(label);
var textbox = document.createElement('input');
textbox.className = 'arguments';
textbox.type = 'text';
textbox.value = '';
body.appendChild(textbox);

// Add environment variable
label = document.createElement('label');
label.textContent = 'Environment variables';
body.appendChild(label);
textbox = document.createElement('input');
textbox.className = 'envs';
textbox.type = 'text';
textbox.value = '';
body.appendChild(textbox);
Expand All @@ -59,14 +81,23 @@ export class ExecutionWidget extends Widget {
* Create a new kernel selector widget.
*/
constructor(path: string, options: ExecutorOptions) {
super({ node: createDialogBody(options) });
super({ node: createDialogBody(options, path) });
this._path = path;
}

getValue(): string {
const executor = this.node.querySelector('select') as HTMLSelectElement;
const args = this.node.querySelector('input') as HTMLInputElement;
return `${executor.value}${this._path} ${args.value}`;
const args = this.node.querySelector('.arguments') as HTMLInputElement;
const envs = this.node.querySelector('.envs') as HTMLInputElement;
var value = executor.value;
if (!!envs.value) {
value = `${envs.value} ${value}`;
}
return (
value
.replace('{path}', this._path)
.replace('{args}', args.value)
);
}

private _path = '';
Expand Down

0 comments on commit 914fa34

Please sign in to comment.