Skip to content

Commit

Permalink
Adopt pre-commit (#6331)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Apr 1, 2022
1 parent 3031084 commit ebc7615
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 248 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ jobs:
install:
needs: [build]
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
os: [ubuntu-latest, macos-latest, windows-latest]
python: ['3.7', '3.10']
include:
- python: '3.7'
dist: 'notebook*.tar.gz'
- python: '3.10'
dist: 'notebook*.whl'
- os: windows
- os: windows-latest
py_cmd: python
- os: macos
- os: macos-latest
py_cmd: python3
- os: ubuntu
- os: ubuntu-latest
py_cmd: python
steps:
- name: Install Python
Expand Down Expand Up @@ -109,3 +109,14 @@ jobs:
jupyter server extension list 2>&1 | grep -ie "notebook.*enabled" -
jupyter notebook --version
jupyter notebook --help
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Install Jupyterlab
run: pip install -e .
- uses: pre-commit/[email protected]
72 changes: 72 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
ci:
# skip any check that needs internet access
skip: [check-jsonschema, prettier, eslint, integrity]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: forbid-new-submodules
# - id: end-of-file-fixer
# - id: check-case-conflict
# - id: check-executables-have-shebangs
# - id: requirements-txt-fixer
# - id: check-added-large-files
# - id: check-case-conflict
# - id: check-toml
# - id: check-yaml
# - id: debug-statements
# - id: check-builtin-literals
# - id: trailing-whitespace
# exclude: .bumpversion.cfg

# - repo: https://github.com/psf/black
# rev: 22.3.0
# hooks:
# - id: black
# args: ["--line-length", "100"]

# - repo: https://github.com/PyCQA/isort
# rev: 5.10.1
# hooks:
# - id: isort
# files: \.py$
# args: [--profile=black]

# - repo: https://github.com/pycqa/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies:
# [
# "flake8-bugbear==20.1.4",
# "flake8-logging-format==0.6.0",
# "flake8-implicit-str-concat==0.2.0",
# ]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.10.2
hooks:
- id: check-jsonschema
name: 'Check GitHub Workflows'
files: ^\.github/workflows/
types: [yaml]
args: ['--schemafile', 'https://json.schemastore.org/github-workflow']

- repo: local
hooks:
- id: prettier
name: prettier
entry: 'npm run prettier:files'
language: node
types_or: [json, markdown, ts, tsx, javascript, jsx, css]
- id: eslint
name: eslint
entry: 'npm run eslint:files'
language: node
types_or: [ts, tsx, javascript, jsx]
- id: integrity
name: integrity
entry: 'npm run integrity --force'
language: node
stages: [push]
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,47 @@ Checkout the [Playwright Command Line Reference](https://playwright.dev/docs/tes
Running the end to end tests in headful mode will trigger something like the following:

![playwight-headed-demo](https://user-images.githubusercontent.com/591645/141274633-ca9f9c2f-eef6-430e-9228-a35827f8133d.gif)

## Code Styling

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
When code is modified and committed, all staged files will be
automatically formatted using pre-commit git hooks (with help from
[pre-commit](https://github.com/pre-commit/pre-commit). The benefit of
using a code formatters like `prettier` and `black` is that it removes the topic of
code style from the conversation when reviewing pull requests, thereby
speeding up the review process.

As long as your code is valid,
the pre-commit hook should take care of how it should look.
`pre-commit` and its associated hooks will automatically be installed when
you run `pip install -e ".[test]"`

To install `pre-commit` manually, run the following:

```shell
pip install pre-commit
pre-commit install
```

You can invoke the pre-commit hook by hand at any time with:

```shell
pre-commit run
```

which should run any autoformatting on your code
and tell you about any errors it couldn't fix automatically.
You may also install [black integration](https://github.com/psf/black#editor-integration)
into your text editor to format code automatically.

If you have already committed files before setting up the pre-commit
hook with `pre-commit install`, you can fix everything up using
`pre-commit run --all-files`. You need to make the fixing commit
yourself after that.

You may also use the prettier npm script (e.g. `npm run prettier` or
`yarn prettier` or `jlpm prettier`) to format the entire code base.
We recommend installing a prettier extension for your code editor and
configuring it to format your code with a keyboard shortcut or
automatically on save.
2 changes: 1 addition & 1 deletion docs/jsdoc_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports.handlers = {
// e.doclet will refer to the newly created doclet
// you can read and modify properties of that doclet if you wish
if (typeof e.doclet.name === 'string') {
if (e.doclet.name[0] == '_') {
if (e.doclet.name[0] === '_') {
console.log(
'Private method "' + e.doclet.longname + '" not documented.'
);
Expand Down
27 changes: 0 additions & 27 deletions lint-staged.config.js

This file was deleted.

10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
"develop": "jupyter labextension develop . --overwrite && node ./buildutils/lib/develop.js --overwrite",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"eslint:files": "eslint --fix",
"install": "lerna bootstrap",
"integrity": "node buildutils/lib/ensure-repo.js",
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:files": "prettier --write",
"release:bump": "node ./buildutils/lib/release-bump.js",
"release:patch": "node ./buildutils/lib/release-patch.js",
"test": "lerna run test",
Expand All @@ -39,11 +41,6 @@
"watch:app": "lerna exec --stream --scope \"@jupyter-notebook/app\" jlpm watch",
"watch:lib": "lerna exec --stream --scope @jupyter-notebook/metapackage jlpm watch"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"devDependencies": {
"@jupyterlab/buildutils": "^4.0.0-alpha.7",
"@typescript-eslint/eslint-plugin": "^4.2.0",
Expand All @@ -54,17 +51,14 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.5",
"extra-watch-webpack-plugin": "^1.0.3",
"husky": "^3",
"jest": "^26.4.2",
"jest-junit": "^11.1.0",
"jest-raw-loader": "^1.0.1",
"jest-summary-reporter": "^0.0.2",
"lerna": "^3.22.1",
"lint-staged": "^10.4.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.0",
"rimraf": "^3.0.2",
"shell-quote": "^1.7.2",
"typescript": "~4.1.3"
},
"jupyter-releaser": {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["jupyter_packaging~=0.10", "jupyterlab>=4.0.0a22,<5"]
requires = ["jupyter_packaging~=0.10", "jupyterlab>=4.0.0a22,<5", "pre-commit"]
build-backend = "jupyter_packaging.build_api"

[license]
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test =
pytest-tornasync
pytest-console-scripts
ipykernel
pre-commit

[options.entry_points]
console_scripts =
Expand Down
15 changes: 14 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Distributed under the terms of the Modified BSD License.

from pathlib import Path
import subprocess
import sys

import setuptools

Expand Down Expand Up @@ -42,7 +44,18 @@

# In develop mode, just run yarn
builder = npm_builder(build_cmd="build", npm="jlpm", force=True)
cmdclass = wrap_installers(post_develop=builder, ensured_targets=ensured_targets)

def post_develop(*args, **kwargs):
builder(*args, **kwargs)
try:
subprocess.run([sys.executable, "-m", "pre_commit", "install"])
subprocess.run(
[sys.executable, "-m", "pre_commit", "install", "--hook-type", "pre-push"]
)
except Exception:
pass

cmdclass = wrap_installers(post_develop=post_develop, ensured_targets=ensured_targets)

setup_args = dict(cmdclass=cmdclass, data_files=get_data_files(data_files_spec))
except ImportError:
Expand Down
8 changes: 7 additions & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"extends": "./tsconfigbase",
"include": ["packages/**/*", "app/**/*", "buildutils/**/*", "ui-tests/**/*"],
"include": [
"packages/**/*",
"app/**/*",
"buildutils/**/*",
"ui-tests/**/*",
"docs/**/*"
],
"types": ["jest"]
}
Loading

0 comments on commit ebc7615

Please sign in to comment.