Skip to content

Commit e617a8a

Browse files
fcollonvalSteven Silvester
authored andcommitted
Add Pre-Commit Config
Adds support for [`pre-commit`](https://pre-commit.com/) following the example from [`jupyter_client`](jupyter/jupyter_client#631).
1 parent 1444737 commit e617a8a

34 files changed

+136
-58
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Initial pre-commit reformat

.gitconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[blame]
2+
ignoreRevsFile = .git-blame-ignore-revs

.github/workflows/python-linux.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ on:
55
pull_request:
66
branches: '*'
77
jobs:
8+
# Run "pre-commit run --all-files"
9+
pre-commit:
10+
runs-on: ubuntu-20.04
11+
timeout-minutes: 2
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.8
18+
19+
# ref: https://github.com/pre-commit/action
20+
- uses: pre-commit/[email protected]
21+
- name: Help message if pre-commit fail
22+
if: ${{ failure() }}
23+
run: |
24+
echo "You can install pre-commit hooks to automatically run formatting"
25+
echo "on each commit with:"
26+
echo " pre-commit install"
27+
echo "or you can run by hand on staged files with"
28+
echo " pre-commit run"
29+
echo "or after-the-fact on already committed files with"
30+
echo " pre-commit run --all-files"
31+
832
build:
933
runs-on: ${{ matrix.os }}-latest
1034
strategy:

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
repos:
2+
- repo: https://github.com/asottile/reorder_python_imports
3+
rev: v1.9.0
4+
hooks:
5+
- id: reorder-python-imports
6+
- repo: https://github.com/psf/black
7+
rev: 20.8b1
8+
hooks:
9+
- id: black
10+
args: ["--line-length", "100"]
11+
- repo: https://github.com/pre-commit/mirrors-prettier
12+
rev: v2.2.1
13+
hooks:
14+
- id: prettier
15+
- repo: https://gitlab.com/pycqa/flake8
16+
rev: "3.8.4"
17+
hooks:
18+
- id: flake8
19+
- repo: https://github.com/pre-commit/pre-commit-hooks
20+
rev: v3.4.0
21+
hooks:
22+
- id: end-of-file-fixer
23+
- id: check-case-conflict
24+
- id: check-executables-have-shebangs
25+
- id: requirements-txt-fixer
26+
- repo: https://github.com/pre-commit/mirrors-eslint
27+
rev: v7.32.0
28+
hooks:
29+
- id: eslint
30+
- repo: https://github.com/pre-commit/mirrors-pylint
31+
rev: v3.0.0a3
32+
hooks:
33+
- id: pylint
34+
args: [--disable=all, --enable=unused-import]

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/templates/*.html

CONTRIBUTING.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ from any directory in your system with::
3737

3838
jupyter server
3939

40+
41+
Code Styling
42+
-----------------------------
43+
`jupyter_server` has adopted automatic code formatting so you shouldn't
44+
need to worry too much about your code style.
45+
As long as your code is valid,
46+
the pre-commit hook should take care of how it should look.
47+
To install `pre-commit`, run the following::
48+
49+
pip install pre-commit
50+
pre-commit install
51+
52+
53+
You can invoke the pre-commit hook by hand at any time with::
54+
55+
pre-commit run
56+
57+
which should run any autoformatting on your code
58+
and tell you about any errors it couldn't fix automatically.
59+
You may also install [black integration](https://github.com/psf/black#editor-integration)
60+
into your text editor to format code automatically.
61+
62+
If you have already committed files before setting up the pre-commit
63+
hook with ``pre-commit install``, you can fix everything up using
64+
``pre-commit run --all-files``. You need to make the fixing commit
65+
yourself after that.
66+
4067
Troubleshooting the Installation
4168
--------------------------------
4269

docs/source/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import sys
1717
import os
1818
import os.path as osp
19-
import shlex
2019
import shutil
2120

2221
HERE = osp.abspath(osp.dirname(__file__))
@@ -378,7 +377,7 @@
378377
spelling_word_list_filename='spelling_wordlist.txt'
379378

380379
# import before any doc is built, so _ is guaranteed to be injected
381-
import jupyter_server.transutils
380+
import jupyter_server.transutils # pylint: disable=unused-import
382381

383382

384383
def setup(app):

examples/simple/setup.py

100755100644
File mode changed.

examples/simple/simple_ext1/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, jinja2
1+
import os
22
from traitlets import Unicode
33
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
44
from .handlers import (DefaultHandler, RedirectHandler,

examples/simple/simple_ext1/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get(self):
77
# The name of the extension to which this handler is linked.
88
self.log.info("Extension Name in {} Default Handler: {}".format(self.name, self.name))
99
# A method for getting the url to static files (prefixed with /static/<name>).
10-
self.log.info("Static URL for / in simple_ext1 Default Handler:".format(self.static_url(path='/')))
10+
self.log.info("Static URL for / in simple_ext1 Default Handler: {}".format(self.static_url(path='/')))
1111
self.write('<h1>Hello Simple 1 - I am the default...</h1>')
1212
self.write('Config in {} Default Handler: {}'.format(self.name, self.config))
1313

0 commit comments

Comments
 (0)