Add documentation extension to Jupyter Lab (#745)

* Add documentation extension to Jupyter Lab

* Fix lint

* fix pyupgrade

* Change label from Documentation to Gamestonk Documentation

* Improve code after review
This commit is contained in:
DidierRLopes
2021-09-12 23:07:29 +01:00
committed by GitHub
parent bb17974e7e
commit 6a2792ea8e
23 changed files with 450 additions and 6 deletions

View File

@@ -26,7 +26,7 @@ repos:
rev: 'v0.812'
hooks:
- id: mypy
args: [ --ignore-missing-imports --exclude '/setup\.py$' ]
args: [ --ignore-missing-imports ]
- repo: https://github.com/pre-commit/mirrors-pylint
rev: 'v3.0.0a4'
hooks:

View File

@@ -0,0 +1,5 @@
node_modules
dist
coverage
**/*.d.ts
ui-tests

53
jupyterlab/documentation/.eslintrc.js vendored Normal file
View File

@@ -0,0 +1,53 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:jsdoc/recommended',
'plugin:prettier/recommended',
'plugin:react/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'jsdoc'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z]',
match: true,
},
},
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false },
],
curly: ['error', 'all'],
eqeqeq: 'error',
'jsdoc/require-param-type': 'off',
'jsdoc/require-property-type': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/no-types': 'warn',
'prefer-arrow-callback': 'error',
},
settings: {
jsdoc: {
mode: 'typescript',
},
react: {
version: 'detect',
},
},
};

22
jupyterlab/documentation/MANIFEST.in vendored Normal file
View File

@@ -0,0 +1,22 @@
include LICENSE
include README.md
include pyproject.toml
include jupyter-config/gamestonk_terminal_documentation.json
include package.json
include ts*.json
graft gamestonk_terminal_documentation/labextension
# Javascript files
graft src
graft style
prune **/node_modules
prune lib
# Patterns to exclude from any directory
global-exclude *~
global-exclude *.pyc
global-exclude *.pyo
global-exclude .git
global-exclude .ipynb_checkpoints

17
jupyterlab/documentation/README.md vendored Normal file
View File

@@ -0,0 +1,17 @@
# Gamestonk Teminal Documentation
This extensions adds a button into the Gamestonk Terminal category of the Jupyter Lab launcher panel.
## Install, Use and Develop
```bash
pip install -e .
jlpm
jlpm run build:prod
jupyter labextension install .
# Rebuild Typescript source after making changes
jlpm build
# Rebuild JupyterLab after making any changes
jupyter lab build
```

3
jupyterlab/documentation/RELEASE.md vendored Normal file
View File

@@ -0,0 +1,3 @@
# Making a new release of gamestonk-settings
Check out the [workflow documentation](https://github.com/jupyter-server/jupyter_releaser#typical-workflow) for information.

View File

@@ -0,0 +1,13 @@
import json
import os.path as osp
from ._version import __version__ # noqa: F401
HERE = osp.abspath(osp.dirname(__file__))
with open(osp.join(HERE, "labextension", "package.json")) as fid:
data = json.load(fid)
def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": data["name"]}]

View File

@@ -0,0 +1,2 @@
version_info = (0, 1, 0)
__version__ = ".".join(map(str, version_info))

5
jupyterlab/documentation/install.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"packageManager": "python",
"packageName": "gamestonk_terminal_documentation",
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package gamestonk_terminal_documentation"
}

80
jupyterlab/documentation/package.json vendored Normal file
View File

@@ -0,0 +1,80 @@
{
"name": "@gamestonk/documentation",
"version": "0.1.0",
"description": "Gamestonk terminal documentation",
"keywords": [
"jupyter",
"jupyterlab",
"jupyterlab-extension"
],
"homepage": "https://github.com/GamestonkTerminal/GamestonkTerminal",
"bugs": {
"url": "https://github.com/GamestonkTerminal/GamestonkTerminal/issues"
},
"license": "MIT",
"author": {
"name": "Project Jupyter Contributors",
"email": "dro.lopes@campus.fct.unl.pt"
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/**/*.{css,eot,js,gif,html,jpg,json,png,svg,woff2,ttf}",
"schema/**/*.json"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"repository": {
"type": "git",
"url": "https://github.com/GamestonkTerminal/GamestonkTerminal.git"
},
"scripts": {
"build": "jlpm run build:lib && jlpm run build:labextension:dev",
"build:all": "jlpm run build:lib && jlpm run build:labextension",
"build:labextension": "jupyter labextension build .",
"build:labextension:dev": "jupyter labextension build --development True .",
"build:lib": "tsc",
"build:prod": "jlpm run clean && jlpm run build:lib && jlpm run build:labextension",
"clean": "jlpm run clean:lib",
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
"clean:labextension": "rimraf gamestonk_terminal_documentation/labextension",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"install:extension": "jlpm run build",
"prepare": "jlpm run clean && jlpm run build:prod",
"watch": "run-p watch:src watch:labextension",
"watch:labextension": "jupyter labextension watch .",
"watch:src": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^3.1.0",
"@jupyterlab/launcher": "^3.1.0",
"@jupyterlab/mainmenu": "^3.1.7"
},
"devDependencies": {
"@jupyterlab/builder": "^3.1.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-jsdoc": "^36.0.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.18.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"rimraf": "^3.0.2",
"typescript": "~4.1.3"
},
"sideEffects": [
"style/*.css",
"style/*.svg",
"style/index.js"
],
"jupyterlab": {
"extension": true,
"outputDir": "gamestonk_terminal_documentation/labextension",
"schemaDir": "schema"
},
"styleModule": "style/index.js"
}

17
jupyterlab/documentation/pyproject.toml vendored Normal file
View File

@@ -0,0 +1,17 @@
[build-system]
requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1"]
build-backend = "jupyter_packaging.build_api"
[tool.jupyter-packaging.options]
skip-if-exists = ["gamestonk_terminal_documentation/labextension/static/style.js"]
ensured-targets = ["gamestonk_terminal_documentation/labextension/static/style.js", "gamestonk_terminal_documentation/labextension/package.json"]
[tool.jupyter-packaging.builder]
factory = "jupyter_packaging.npm_builder"
[tool.jupyter-packaging.build-args]
build_cmd = "build:prod"
npm = ["jlpm"]
[tool.check-manifest]
ignore = ["gamestonk_terminal_documentation/labextension/**", "yarn.lock", ".*", "package-lock.json"]

View File

@@ -0,0 +1,25 @@
{
"title": "Gamestonk Terminal Documentation",
"description": "Gamestonk Terminal Documentation.",
"jupyter.lab.menus": {
"main": [
{
"id": "jp-mainmenu-file",
"items": [
{
"type": "submenu",
"id": "jp-mainmenu-file-new",
"items": [
{
"command": "gamestonk:documentation",
"rank": 30
}
]
}
]
}
]
},
"additionalProperties": false,
"type": "object"
}

View File

@@ -0,0 +1,86 @@
"""
gamestonk_terminal_documentation setup
"""
import json
import sys
from pathlib import Path
import setuptools
HERE = Path(__file__).parent.resolve()
# The name of the project
name = "gamestonk_terminal_documentation"
lab_path = HERE / name.replace("-", "_") / "labextension"
# Representative files that should exist after a successful build
ensured_targets = [str(lab_path / "package.json"), str(lab_path / "static/style.js")]
labext_name = "@gamestonk/documentation"
data_files_spec = [
(
"share/jupyter/labextensions/%s" % labext_name,
str(lab_path.relative_to(HERE)),
"**",
),
("share/jupyter/labextensions/%s" % labext_name, ".", "install.json"),
]
long_description = (HERE / "README.md").read_text()
# Get the package info from package.json
pkg_json = json.loads((HERE / "package.json").read_bytes())
setup_args = dict(
name=name,
version=pkg_json["version"],
url=pkg_json["homepage"],
author=pkg_json["author"]["name"],
author_email=pkg_json["author"]["email"],
description=pkg_json["description"],
license=pkg_json["license"],
long_description=long_description,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
install_requires=[],
zip_safe=False,
include_package_data=True,
python_requires=">=3.6",
platforms="Linux, Mac OS X, Windows",
keywords=["Jupyter", "JupyterLab", "JupyterLab3"],
classifiers=[
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Framework :: Jupyter",
],
)
try:
from jupyter_packaging import wrap_installers, npm_builder, get_data_files
post_develop = npm_builder(
build_cmd="install:extension", source_dir="src", build_dir=lab_path
)
setup_args["cmdclass"] = wrap_installers(
post_develop=post_develop, ensured_targets=ensured_targets
)
setup_args["data_files"] = get_data_files(data_files_spec)
except ImportError as e:
import logging
logging.basicConfig(format="%(levelname)s: %(message)s")
logging.warning(
"Build tool `jupyter-packaging` is missing. Install it with pip or conda."
)
if not ("--name" in sys.argv or "--version" in sys.argv):
raise e
if __name__ == "__main__":
setuptools.setup(**setup_args)

77
jupyterlab/documentation/src/index.ts vendored Normal file
View File

@@ -0,0 +1,77 @@
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
import { ICommandPalette } from '@jupyterlab/apputils';
import { ILauncher } from '@jupyterlab/launcher';
import { IMainMenu } from "@jupyterlab/mainmenu";
import { LabIcon } from '@jupyterlab/ui-components';
import docsIconStr from '../style/docs.svg';
const CATEGORY = "Gamestonk Terminal";
namespace CommandIDs {
export const createNew = 'jlab-examples:create-new-python-file';
}
const extension: JupyterFrontEndPlugin<void> = {
id: 'documentation',
autoStart: true,
optional: [ILauncher, ICommandPalette],
activate: (
app: JupyterFrontEnd,
launcher: ILauncher | null,
menu: IMainMenu | null,
palette: ICommandPalette | null
) => {
const { commands } = app;
const command = CommandIDs.createNew;
const icon = new LabIcon({
name: 'documentation:docs-icon',
svgstr: docsIconStr,
});
commands.addCommand(command, {
label: 'Gamestonk Documentation',
icon: icon,
execute: (args: any) => {
window.open(
'https://gamestonkterminal.github.io/GamestonkTerminal/',
'_blank'
);
},
});
// Add the command to the launcher
if (launcher) {
launcher.add({
command,
category: CATEGORY,
rank: 3,
});
}
// Add the command to the palette
if (palette) {
palette.addItem({
command,
args: { isPalette: true },
category: CATEGORY,
});
}
// Add the command to the menu
if (menu) {
menu.fileMenu.newMenu.addGroup([{ command }], 30);
}
console.log("Added Gamestonk Settings Extension.");
},
};
export default extension;

4
jupyterlab/documentation/src/svg.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
declare module '*.svg' {
const value: string;
export default value;
}

View File

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="256px" height="256px" viewBox="0 0 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>docs</title>
<g id="docs" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="Rectangle" fill="#424242" x="15" y="18" width="225" height="220"></rect>
<path d="M128.5,67.5 C121.320298,67.5 115.5,73.3202983 115.5,80.5 C115.5,87.6797017 121.320298,93.5 128.5,93.5 C135.679702,93.5 141.5,87.6797017 141.5,80.5 C141.5,77.0521856 140.130361,73.7455848 137.692388,71.3076118 C135.254415,68.8696389 131.947814,67.5 128.5,67.5 Z" id="Path" stroke="#FFFFFF" stroke-width="10" fill-rule="nonzero"></path>
<rect id="Rectangle" fill="#FFFFFF" x="115.652174" y="108" width="25.7391304" height="74" rx="12"></rect>
</g>
</svg>

After

Width:  |  Height:  |  Size: 866 B

View File

@@ -0,0 +1 @@
@import url('base.css');

View File

@@ -0,0 +1 @@
import './base.css';

24
jupyterlab/documentation/tsconfig.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": true,
"declaration": true,
"esModuleInterop": true,
"incremental": true,
"jsx": "react",
"module": "esnext",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"outDir": "lib",
"rootDir": "src",
"strict": true,
"strictNullChecks": false,
"target": "es2017",
"types": []
},
"include": ["src/*"]
}

View File

@@ -11,10 +11,10 @@
"bugs": {
"url": "https://github.com/GamestonkTerminal/GamestonkTerminal/issues"
},
"license": "BSD-3-Clause",
"license": "MIT",
"author": {
"name": "Gamestonk Contributors",
"email": ""
"email": "dro.lopes@campus.fct.unl.pt"
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",

View File

@@ -83,7 +83,7 @@ const extension: JupyterFrontEndPlugin<void> = {
if (menu) {
menu.fileMenu.newMenu.addGroup([{ command }], 30);
}
console.log("Added Gamestonk Settings Exstension.");
console.log("Added Gamestonk Settings Extension.");
},
};

View File

@@ -11,10 +11,10 @@
"bugs": {
"url": "https://github.com/GamestonkTerminal/GamestonkTerminal/issues"
},
"license": "BSD-3-Clause",
"license": "MIT",
"author": {
"name": "Gamestonk Contibuters",
"email": ""
"email": "dro.lopes@campus.fct.unl.pt"
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",