Skip to content

Commit

Permalink
Add linting and CI action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhad6 committed Oct 20, 2023
1 parent 73bd10e commit 45dde12
Show file tree
Hide file tree
Showing 8 changed files with 1,638 additions and 81 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-empty-function": "off",
"react/self-closing-comp": "error"
},
"settings": {
"import/resolver": "typescript",
"react": {
"version": "detect"
}
},
"overrides": [
{
"files": "webpack.config.js",
"env": {
"node": true
},
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
HATCH_VERSION: "1.7.0"
PYTHON_VERSION: "3.10"

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Hatch
run: pipx install hatch==${{ env.HATCH_VERSION }}

- name: Set up Python with pip cache
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc

- name: Yarn cache
uses: actions/cache@v3
with:
path: .yarn/cache
key: yarn-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-${{ runner.os }}-
- name: Enable corepack
run: corepack enable

- name: Install dependencies
run: yarn

- name: Lint frontend
run: yarn lint

- name: Check Formatting (Black)
run: hatch run black datalogger_jupyterlab --check

- name: Lint (Flake8)
run: hatch run flake8 datalogger_jupyterlab

- name: Lint (Pylint)
run: hatch run pylint datalogger_jupyterlab

- name: Mypy cache
uses: actions/cache@v3
with:
path: .mypy_cache
key: mypy-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-${{ github.sha }}
restore-keys: |
mypy-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-
- name: Type Check (Mypy)
run: hatch run mypy datalogger_jupyterlab
11 changes: 4 additions & 7 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v3

- name: Install Hatch
run: pipx install hatch==$HATCH_VERSION
run: pipx install hatch==${{ env.HATCH_VERSION }}

- name: Set up Python with pip cache
uses: actions/setup-python@v4
Expand All @@ -27,26 +27,23 @@ jobs:
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc

- name: Yarn cache
uses: actions/cache@v3
with:
path: .yarn/cache
key: yarn-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-${{ runner.os }}-
- name: Enable corepack
run: corepack enable

- name: Install dependencies
run: yarn

- name: Build frontend
run: yarn build:lib

- name: Build lab extension
run: hatch run jupyterlab:build
run: yarn build

- name: Build package
run: hatch build
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Also, in order to make use of this extension, DataLogger should be installed in
Python kernel. See https://github.com/PainterQubits/datalogger for installation
instructions.


## Development

To develop, the following dependencies must be installed:
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
"extension": true,
"outputDir": "labextension",
"schemaDir": "schema",
"webpackConfig": "./webpack.config.js"
"webpackConfig": "webpack.config.js"
},
"scripts": {
"dev": "run-s build dev:labextension && run-p watch:src watch:labextension jupyterlab",
"build": "run-s clean build:lib && hatch run jupyter labextension build .",
"preview": "yarn build && hatch env remove default && yarn jupyterlab",
"dev": "yarn build && hatch run jupyter labextension develop --overwrite . && run-p watch:src watch:labextension jupyterlab",
"build": "run-s clean cp:icons && tsc && hatch run jupyter labextension build .",
"preview": "yarn build && hatch env remove jupyterlab && yarn jupyterlab",
"clean": "rm -rf lib tsconfig.tsbuildinfo labextension",
"lint": "prettier --check .",
"lint": "tsc --noEmit && eslint . && prettier --check .",
"cp:icons": "mkdir -p lib/icons && cp src/icons/*.svg* lib/icons",
"build:lib": "yarn cp:icons && tsc",
"dev:labextension": "hatch run jupyter labextension develop --overwrite .",
"watch:src": "yarn cp:icons && tsc -w",
"watch:labextension": "hatch run jupyter labextension watch .",
"jupyterlab": "hatch run jupyter lab"
"jupyterlab": "hatch run jupyterlab:start"
},
"dependencies": {
"@jupyterlab/application": "^4.0.7",
Expand All @@ -32,12 +30,21 @@
"@jupyterlab/services": "^7.0.7",
"@jupyterlab/ui-components": "^4.0.7",
"@lumino/signaling": "^2.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-pdf": "^7.5.1"
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.7",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
Expand Down
19 changes: 11 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ exclude = ["**/*"]
"install.json" = "share/jupyter/labextensions/datalogger-jupyterlab/install.json"

[tool.hatch.envs.default]
dependencies = [
"jupyterlab>=4.0.7,<5",
"flake8>=6.1.0,<7",
"pylint>=3.0.0,<4",
"mypy>=1.5.1,<2",
"black>=23.9.1,<24",
]

[tool.hatch.envs.jupyterlab]
dependencies = [
"jupyterlab>=4.0.7,<5",
"datalogger>=0.1.1",
Expand All @@ -49,17 +58,11 @@ dependencies = [
"matplotlib>=3.8.0,<4",
]

[tool.hatch.envs.default.env-vars]
[tool.hatch.envs.jupyterlab.env-vars]
PIP_EXTRA_INDEX_URL = "https://painterqubits.github.io/datalogger/releases"

[tool.hatch.envs.jupyterlab]
detached = true
dependencies = [
"jupyterlab>=4.0.7,<5",
]

[tool.hatch.envs.jupyterlab.scripts]
build = "jupyter labextension build ."
start = "jupyter lab"

[build-system]
requires = ["hatchling"]
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dataloggerLoadCodePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const dataloggerLoadCodePlugin: JupyterFrontEndPlugin<void> = {
const files = [...fileBrowser.selectedItems()];

// Get the current notebook
let { currentWidget: notebookPanel } = notebookTracker;
const { currentWidget: notebookPanel } = notebookTracker;
if (notebookPanel === null) return;
await notebookPanel.context.ready;
const { content: notebook } = notebookPanel;
Expand Down
Loading

0 comments on commit 45dde12

Please sign in to comment.