Name | denomagics JSON |
Version |
1.1.15
JSON |
| download |
home_page | None |
Summary | Python package to run JavaScript/TypeScript(Deno backend) in Jupyter notebooks and Google Colab. |
upload_time | 2024-09-17 02:15:07 |
maintainer | None |
docs_url | None |
author | tonidy |
requires_python | None |
license | MIT License |
keywords |
deno
jupyter
magic
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Deno Magic Command
This fork simplifies the magic command; instead of `%%run_deno`, we change it to `%%d`.
And also translate all Japanese to English.
## Overview
This is a magic command to write and execute Deno (JavaScript/TypeScript) code in code cells in Jupyter (notebook/lab) or Google Colab.
## Usage
### Installation
In Jupyter environments, you need to install Deno in advance and add it to your PATH. For installation methods, please refer to [Deno's official website](https://deno.com/). If you're using Jupyter (extension) via VSCode, additionally install the Deno extension and set `Deno.enable` to true in the settings.
In the Google Colab environment, there's an installation function provided in the package, so you don't need to install it separately.
### Adding the Magic Command
Paste the following code into a code cell and execute it to register the magic command. You need to re-run it each time you restart the kernel or runtime.
```python
%pip install denomagics
import denomagics
```
# Install Deno (for Google Colab; calling this in other environments won't install Deno)
```python
denomagics.install_deno_colab()
# Register the magic command
denomagics.register_deno_magics()
```
### How to Use the Magic Command
At the beginning of a code cell, write the magic command as follows. When executed, the JavaScript/TypeScript code in the code cell will be run by Deno.
```javascript
%%d
console.log("Hello, world!");
```
or with old syntax
```javascript
%%run_deno
console.log("Hello, world!");
```
We also provide a magic command that transpiles the JavaScript/TypeScript code in the code cell using Deno and runs it inside an iframe.
Below is an example using p5.js, a library for browsers.
```javascript
%%run_deno_iframe 830 430
import "https://cdn.jsdelivr.net/npm/p5@1.9.4/lib/p5.js";
const sketch = (p: any) => {
let x = 0;
let y = 0;
let speed = 2;
let color: [number, number, number] = [0, 0, 0];
p.setup = () => {
p.createCanvas(800, 400);
x = p.width / 2;
y = p.height / 2;
};
p.draw = () => {
p.background(220);
p.fill(color);
p.ellipse(x, y, 50, 50);
if (p.keyIsDown(p.LEFT_ARROW) === true) {
x -= speed;
}
if (p.keyIsDown(p.RIGHT_ARROW) === true) {
x += speed;
}
if (p.keyIsDown(p.UP_ARROW) === true) {
y -= speed;
}
if (p.keyIsDown(p.DOWN_ARROW) === true) {
y += speed;
}
};
p.mousePressed = () => {
color = [p.random(255), p.random(255), p.random(255)];
};
};
new p5(sketch);
```
### Magic Command
#### %%d
```jupyter
%%run_deno [userval]
```
Executes the JavaScript/TypeScript code in the code cell using Deno.
- **userval**: Specifies whether to use Jupyter user variables in Deno. The default is `False`.
When `userval` is set to `True`, you can access Jupyter's user variables through `globalThis.jupyter`, allowing variable exchange across cells.
Internally, data is exchanged between Jupyter and Deno using a temporary JSON file, so objects that cannot be converted to JSON cannot be used.
Behavior is undefined if such objects are used.
If the code is being executed within a Jupyter code cell, `globalThis.isJupyterCell` is defined. By checking whether this is not `undefined`, you can determine if the code is being executed from a Jupyter code cell.
If you want to terminate the execution in the middle of a code cell while using Jupyter user variables, use `jupyterExit()` instead of `Deno.exit`. If you exit with `Deno.exit`, Jupyter's user variables will not be updated.
#### %%run_deno_iframe
Transpiles the JavaScript/TypeScript in the code cell using Deno and runs it inside an iframe.
```jupyter
%%run_deno_iframe [width] [height] [srcs]
```
- **width**: Specifies the width of the iframe. The default is 500.
- **height**: Specifies the height of the iframe. The default is 500.
- **srcs**: Specifies the URLs of external JavaScript files. If specifying multiple URLs, separate them with spaces.
#### %%run_deno_bundle_iframe
Transpiles and bundles the JavaScript/TypeScript in the code cell, including the imported code, and runs it inside an iframe.
The arguments are the same as `%%denoiframe`.
### %%view_deno_iframe
Outputs the HTML generated after transpiling the JavaScript/TypeScript in the code cell using Deno.
The arguments are the same as `%%run_deno_iframe`.
#### %%view_deno_bundle_iframe
Outputs the HTML generated after transpiling and bundling the JavaScript/TypeScript in the code cell, including the imported code.
The arguments are the same as `%%run_deno_iframe`.
Raw data
{
"_id": null,
"home_page": null,
"name": "denomagics",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "deno, jupyter, magic",
"author": "tonidy",
"author_email": "toni_d_y@live.com",
"download_url": "https://files.pythonhosted.org/packages/24/f6/d6221a8f1aaedf37d48e758668536081c57ffce11293f99ee1be29d21638/denomagics-1.1.15.tar.gz",
"platform": null,
"description": "# Deno Magic Command\n\nThis fork simplifies the magic command; instead of `%%run_deno`, we change it to `%%d`.\nAnd also translate all Japanese to English.\n\n## Overview\n\nThis is a magic command to write and execute Deno (JavaScript/TypeScript) code in code cells in Jupyter (notebook/lab) or Google Colab.\n\n## Usage\n\n### Installation\n\nIn Jupyter environments, you need to install Deno in advance and add it to your PATH. For installation methods, please refer to [Deno's official website](https://deno.com/). If you're using Jupyter (extension) via VSCode, additionally install the Deno extension and set `Deno.enable` to true in the settings.\n\nIn the Google Colab environment, there's an installation function provided in the package, so you don't need to install it separately.\n\n### Adding the Magic Command\n\nPaste the following code into a code cell and execute it to register the magic command. You need to re-run it each time you restart the kernel or runtime.\n\n```python\n%pip install denomagics\nimport denomagics\n```\n\n# Install Deno (for Google Colab; calling this in other environments won't install Deno)\n\n```python\ndenomagics.install_deno_colab()\n# Register the magic command\ndenomagics.register_deno_magics()\n```\n\n### How to Use the Magic Command\n\nAt the beginning of a code cell, write the magic command as follows. When executed, the JavaScript/TypeScript code in the code cell will be run by Deno.\n\n```javascript\n%%d\n\nconsole.log(\"Hello, world!\");\n```\n\nor with old syntax\n\n```javascript\n%%run_deno\n\nconsole.log(\"Hello, world!\");\n```\n\nWe also provide a magic command that transpiles the JavaScript/TypeScript code in the code cell using Deno and runs it inside an iframe.\n\nBelow is an example using p5.js, a library for browsers.\n\n```javascript\n%%run_deno_iframe 830 430\nimport \"https://cdn.jsdelivr.net/npm/p5@1.9.4/lib/p5.js\";\n\nconst sketch = (p: any) => {\n let x = 0;\n let y = 0;\n let speed = 2;\n let color: [number, number, number] = [0, 0, 0];\n\n p.setup = () => {\n p.createCanvas(800, 400);\n x = p.width / 2;\n y = p.height / 2;\n };\n\n p.draw = () => {\n p.background(220);\n p.fill(color);\n p.ellipse(x, y, 50, 50);\n if (p.keyIsDown(p.LEFT_ARROW) === true) {\n x -= speed;\n }\n\n if (p.keyIsDown(p.RIGHT_ARROW) === true) {\n x += speed;\n }\n\n if (p.keyIsDown(p.UP_ARROW) === true) {\n y -= speed;\n }\n\n if (p.keyIsDown(p.DOWN_ARROW) === true) {\n y += speed;\n }\n };\n\n p.mousePressed = () => {\n color = [p.random(255), p.random(255), p.random(255)];\n };\n};\n\nnew p5(sketch);\n```\n\n### Magic Command\n\n#### %%d\n\n```jupyter\n%%run_deno [userval]\n```\n\nExecutes the JavaScript/TypeScript code in the code cell using Deno.\n\n- **userval**: Specifies whether to use Jupyter user variables in Deno. The default is `False`.\n\nWhen `userval` is set to `True`, you can access Jupyter's user variables through `globalThis.jupyter`, allowing variable exchange across cells. \nInternally, data is exchanged between Jupyter and Deno using a temporary JSON file, so objects that cannot be converted to JSON cannot be used. \nBehavior is undefined if such objects are used.\n\nIf the code is being executed within a Jupyter code cell, `globalThis.isJupyterCell` is defined. By checking whether this is not `undefined`, you can determine if the code is being executed from a Jupyter code cell.\n\nIf you want to terminate the execution in the middle of a code cell while using Jupyter user variables, use `jupyterExit()` instead of `Deno.exit`. If you exit with `Deno.exit`, Jupyter's user variables will not be updated.\n\n#### %%run_deno_iframe\n\nTranspiles the JavaScript/TypeScript in the code cell using Deno and runs it inside an iframe.\n\n```jupyter\n%%run_deno_iframe [width] [height] [srcs]\n```\n\n- **width**: Specifies the width of the iframe. The default is 500.\n- **height**: Specifies the height of the iframe. The default is 500.\n- **srcs**: Specifies the URLs of external JavaScript files. If specifying multiple URLs, separate them with spaces.\n\n#### %%run_deno_bundle_iframe\n\nTranspiles and bundles the JavaScript/TypeScript in the code cell, including the imported code, and runs it inside an iframe.\n\nThe arguments are the same as `%%denoiframe`.\n\n### %%view_deno_iframe\n\nOutputs the HTML generated after transpiling the JavaScript/TypeScript in the code cell using Deno.\n\nThe arguments are the same as `%%run_deno_iframe`.\n\n#### %%view_deno_bundle_iframe\n\nOutputs the HTML generated after transpiling and bundling the JavaScript/TypeScript in the code cell, including the imported code.\n\nThe arguments are the same as `%%run_deno_iframe`.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Python package to run JavaScript/TypeScript(Deno backend) in Jupyter notebooks and Google Colab.",
"version": "1.1.15",
"project_urls": {
"Homepage": "https://github.com/tonidy/DenoMagics",
"Repository": "https://github.com/tonidy/DenoMagics"
},
"split_keywords": [
"deno",
" jupyter",
" magic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e2a5d803e6af96ed07348633b62a0eefb257c9576c00127a6eb86b5ed3744e0a",
"md5": "55d0337e93513148090556d0e7396983",
"sha256": "caa013ac3ad823bc926b1ed14a2ac40e8fef463df0d6653736f40248b4de9acf"
},
"downloads": -1,
"filename": "denomagics-1.1.15-py3-none-any.whl",
"has_sig": false,
"md5_digest": "55d0337e93513148090556d0e7396983",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6516,
"upload_time": "2024-09-17T02:15:06",
"upload_time_iso_8601": "2024-09-17T02:15:06.364968Z",
"url": "https://files.pythonhosted.org/packages/e2/a5/d803e6af96ed07348633b62a0eefb257c9576c00127a6eb86b5ed3744e0a/denomagics-1.1.15-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "24f6d6221a8f1aaedf37d48e758668536081c57ffce11293f99ee1be29d21638",
"md5": "a34b9ec146651c526b353bdbd8a9c1c6",
"sha256": "722dcaeae2944dce91e3f1b06fb79d56e3b4bd4f7d7dc7dcd5a7c8e47de5a391"
},
"downloads": -1,
"filename": "denomagics-1.1.15.tar.gz",
"has_sig": false,
"md5_digest": "a34b9ec146651c526b353bdbd8a9c1c6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6598,
"upload_time": "2024-09-17T02:15:07",
"upload_time_iso_8601": "2024-09-17T02:15:07.678859Z",
"url": "https://files.pythonhosted.org/packages/24/f6/d6221a8f1aaedf37d48e758668536081c57ffce11293f99ee1be29d21638/denomagics-1.1.15.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-17 02:15:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tonidy",
"github_project": "DenoMagics",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "denomagics"
}