Skip to content

Commit f46fa1d

Browse files
committed
adopt pre-commit
1 parent 3031084 commit f46fa1d

10 files changed

+155
-41
lines changed

.github/workflows/build.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ jobs:
6363
6464
install:
6565
needs: [build]
66-
runs-on: ${{ matrix.os }}-latest
66+
runs-on: ${{ matrix.os }}
6767
strategy:
6868
fail-fast: false
6969
matrix:
70-
os: [ubuntu, macos, windows]
70+
os: [ubuntu-latest, macos-latest, windows-latest]
7171
python: ['3.7', '3.10']
7272
include:
7373
- python: '3.7'
@@ -109,3 +109,14 @@ jobs:
109109
jupyter server extension list 2>&1 | grep -ie "notebook.*enabled" -
110110
jupyter notebook --version
111111
jupyter notebook --help
112+
113+
pre-commit:
114+
runs-on: ubuntu-latest
115+
timeout-minutes: 10
116+
steps:
117+
- uses: actions/checkout@v2
118+
- name: Base Setup
119+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
120+
- name: Install Jupyterlab
121+
run: pip install -e .
122+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
ci:
2+
# skip any check that needs internet access
3+
skip: [check-jsonschema, prettier, eslint, integrity]
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.1.0
8+
hooks:
9+
- id: forbid-new-submodules
10+
# - id: end-of-file-fixer
11+
# - id: check-case-conflict
12+
# - id: check-executables-have-shebangs
13+
# - id: requirements-txt-fixer
14+
# - id: check-added-large-files
15+
# - id: check-case-conflict
16+
# - id: check-toml
17+
# - id: check-yaml
18+
# - id: debug-statements
19+
# - id: check-builtin-literals
20+
# - id: trailing-whitespace
21+
# exclude: .bumpversion.cfg
22+
23+
# - repo: https://github.com/psf/black
24+
# rev: 22.3.0
25+
# hooks:
26+
# - id: black
27+
# args: ["--line-length", "100"]
28+
29+
# - repo: https://github.com/PyCQA/isort
30+
# rev: 5.10.1
31+
# hooks:
32+
# - id: isort
33+
# files: \.py$
34+
# args: [--profile=black]
35+
36+
# - repo: https://github.com/pycqa/flake8
37+
# rev: 4.0.1
38+
# hooks:
39+
# - id: flake8
40+
# additional_dependencies:
41+
# [
42+
# "flake8-bugbear==20.1.4",
43+
# "flake8-logging-format==0.6.0",
44+
# "flake8-implicit-str-concat==0.2.0",
45+
# ]
46+
47+
- repo: https://github.com/sirosen/check-jsonschema
48+
rev: 0.10.2
49+
hooks:
50+
- id: check-jsonschema
51+
name: 'Check GitHub Workflows'
52+
files: ^\.github/workflows/
53+
types: [yaml]
54+
args: ['--schemafile', 'https://json.schemastore.org/github-workflow']
55+
56+
- repo: local
57+
hooks:
58+
- id: prettier
59+
name: prettier
60+
entry: 'npm run prettier:files'
61+
language: node
62+
types_or: [json, markdown, ts, tsx, javascript, jsx, css]
63+
- id: eslint
64+
name: eslint
65+
entry: 'npm run eslint:files'
66+
language: node
67+
types_or: [ts, tsx, javascript, jsx]
68+
- id: integrity
69+
name: integrity
70+
entry: 'npm run integrity --force'
71+
language: node
72+
stages: [push]

CONTRIBUTING.md

+44
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,47 @@ Checkout the [Playwright Command Line Reference](https://playwright.dev/docs/tes
9393
Running the end to end tests in headful mode will trigger something like the following:
9494

9595
![playwight-headed-demo](https://user-images.githubusercontent.com/591645/141274633-ca9f9c2f-eef6-430e-9228-a35827f8133d.gif)
96+
97+
## Code Styling
98+
99+
All non-python source code is formatted using [prettier](https://prettier.io) and python source code is formatted using [black](https://github.com/psf/black)s
100+
When code is modified and committed, all staged files will be
101+
automatically formatted using pre-commit git hooks (with help from
102+
[pre-commit](https://github.com/pre-commit/pre-commit). The benefit of
103+
using a code formatters like `prettier` and `black` is that it removes the topic of
104+
code style from the conversation when reviewing pull requests, thereby
105+
speeding up the review process.
106+
107+
As long as your code is valid,
108+
the pre-commit hook should take care of how it should look.
109+
`pre-commit` and its associated hooks will automatically be installed when
110+
you run `pip install -e ".[test]"`
111+
112+
To install `pre-commit` manually, run the following:
113+
114+
```shell
115+
pip install pre-commit
116+
pre-commit install
117+
```
118+
119+
You can invoke the pre-commit hook by hand at any time with:
120+
121+
```shell
122+
pre-commit run
123+
```
124+
125+
which should run any autoformatting on your code
126+
and tell you about any errors it couldn't fix automatically.
127+
You may also install [black integration](https://github.com/psf/black#editor-integration)
128+
into your text editor to format code automatically.
129+
130+
If you have already committed files before setting up the pre-commit
131+
hook with `pre-commit install`, you can fix everything up using
132+
`pre-commit run --all-files`. You need to make the fixing commit
133+
yourself after that.
134+
135+
You may also use the prettier npm script (e.g. `npm run prettier` or
136+
`yarn prettier` or `jlpm prettier`) to format the entire code base.
137+
We recommend installing a prettier extension for your code editor and
138+
configuring it to format your code with a keyboard shortcut or
139+
automatically on save.

docs/jsdoc_plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exports.handlers = {
33
// e.doclet will refer to the newly created doclet
44
// you can read and modify properties of that doclet if you wish
55
if (typeof e.doclet.name === 'string') {
6-
if (e.doclet.name[0] == '_') {
6+
if (e.doclet.name[0] === '_') {
77
console.log(
88
'Private method "' + e.doclet.longname + '" not documented.'
99
);

lint-staged.config.js

-27
This file was deleted.

package.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
"develop": "jupyter labextension develop . --overwrite && node ./buildutils/lib/develop.js --overwrite",
2828
"eslint": "eslint . --ext .ts,.tsx --fix",
2929
"eslint:check": "eslint . --ext .ts,.tsx",
30+
"eslint:files": "eslint --fix",
3031
"install": "lerna bootstrap",
3132
"integrity": "node buildutils/lib/ensure-repo.js",
3233
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
3334
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
35+
"prettier:files": "prettier --write",
3436
"release:bump": "node ./buildutils/lib/release-bump.js",
3537
"release:patch": "node ./buildutils/lib/release-patch.js",
3638
"test": "lerna run test",
@@ -39,11 +41,6 @@
3941
"watch:app": "lerna exec --stream --scope \"@jupyter-notebook/app\" jlpm watch",
4042
"watch:lib": "lerna exec --stream --scope @jupyter-notebook/metapackage jlpm watch"
4143
},
42-
"husky": {
43-
"hooks": {
44-
"pre-commit": "lint-staged"
45-
}
46-
},
4744
"devDependencies": {
4845
"@jupyterlab/buildutils": "^4.0.0-alpha.7",
4946
"@typescript-eslint/eslint-plugin": "^4.2.0",
@@ -54,17 +51,14 @@
5451
"eslint-plugin-prettier": "^3.1.4",
5552
"eslint-plugin-react": "^7.21.5",
5653
"extra-watch-webpack-plugin": "^1.0.3",
57-
"husky": "^3",
5854
"jest": "^26.4.2",
5955
"jest-junit": "^11.1.0",
6056
"jest-raw-loader": "^1.0.1",
6157
"jest-summary-reporter": "^0.0.2",
6258
"lerna": "^3.22.1",
63-
"lint-staged": "^10.4.0",
6459
"npm-run-all": "^4.1.5",
6560
"prettier": "^1.19.0",
6661
"rimraf": "^3.0.2",
67-
"shell-quote": "^1.7.2",
6862
"typescript": "~4.1.3"
6963
},
7064
"jupyter-releaser": {

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["jupyter_packaging~=0.10", "jupyterlab>=4.0.0a22,<5"]
2+
requires = ["jupyter_packaging~=0.10", "jupyterlab>=4.0.0a22,<5", "pre-commit"]
33
build-backend = "jupyter_packaging.build_api"
44

55
[license]

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ test =
4444
pytest-tornasync
4545
pytest-console-scripts
4646
ipykernel
47+
pre-commit
4748

4849
[options.entry_points]
4950
console_scripts =

setup.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Distributed under the terms of the Modified BSD License.
33

44
from pathlib import Path
5+
import subprocess
6+
import sys
57

68
import setuptools
79

@@ -42,7 +44,18 @@
4244

4345
# In develop mode, just run yarn
4446
builder = npm_builder(build_cmd="build", npm="jlpm", force=True)
45-
cmdclass = wrap_installers(post_develop=builder, ensured_targets=ensured_targets)
47+
48+
def post_develop(*args, **kwargs):
49+
builder(*args, **kwargs)
50+
try:
51+
subprocess.run([sys.executable, "-m", "pre_commit", "install"])
52+
subprocess.run(
53+
[sys.executable, "-m", "pre_commit", "install", "--hook-type", "pre-push"]
54+
)
55+
except Exception:
56+
pass
57+
58+
cmdclass = wrap_installers(post_develop=post_develop, ensured_targets=ensured_targets)
4659

4760
setup_args = dict(cmdclass=cmdclass, data_files=get_data_files(data_files_spec))
4861
except ImportError:

tsconfig.eslint.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"extends": "./tsconfigbase",
3-
"include": ["packages/**/*", "app/**/*", "buildutils/**/*", "ui-tests/**/*"],
3+
"include": [
4+
"packages/**/*",
5+
"app/**/*",
6+
"buildutils/**/*",
7+
"ui-tests/**/*",
8+
"docs/**/*"
9+
],
410
"types": ["jest"]
511
}

0 commit comments

Comments
 (0)