Skip to content

Commit c9476ab

Browse files
authored
Install pre-commit automatically (#763)
* install pre-commit automatically * add to build reqs
1 parent 7239666 commit c9476ab

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

CONTRIBUTING.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ steps::
2727
pip install --upgrade setuptools pip
2828
git clone https://github.com/jupyter/jupyter_server
2929
cd jupyter_server
30-
pip install -e .
30+
pip install -e ".[test]"
3131

3232
If you are using a system-wide Python installation and you only want to install the server for you,
3333
you can add ``--user`` to the install commands.
@@ -44,7 +44,10 @@ Code Styling
4444
need to worry too much about your code style.
4545
As long as your code is valid,
4646
the pre-commit hook should take care of how it should look.
47-
To install `pre-commit`, run the following::
47+
`pre-commit` and its associated hooks will automatically be installed when
48+
you run ``pip install -e ".[test]"``
49+
50+
To install ``pre-commit`` manually, run the following::
4851

4952
pip install pre-commit
5053
pre-commit install

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["jupyter_packaging~=0.9"]
2+
requires = ["jupyter_packaging~=0.9", "pre-commit"]
33
build-backend = "jupyter_packaging.build_api"
44

55
[tool.jupyter-packaging.builder]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ test =
5757
pytest-tornasync
5858
pytest-console-scripts
5959
ipykernel
60+
pre-commit
6061
# NOTE: we cannot auto install examples/simple here because of:
6162
# https://github.com/pypa/pip/issues/6658
6263

setup.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
import subprocess
2+
import sys
3+
14
from setuptools import setup
25

36
try:
47
from jupyter_packaging import npm_builder, wrap_installers
58

69
ensured_targets = ["jupyter_server/static/style/bootstrap.min.css"]
7-
cmdclass = wrap_installers(pre_develop=npm_builder(), ensured_targets=ensured_targets)
10+
11+
def post_develop(*args, **kwargs):
12+
npm_builder()
13+
try:
14+
subprocess.run([sys.executable, "-m", "pre_commit", "install"])
15+
subprocess.run(
16+
[sys.executable, "-m", "pre_commit", "install", "--hook-type", "pre-push"]
17+
)
18+
except Exception:
19+
pass
20+
21+
cmdclass = wrap_installers(post_develop=post_develop, ensured_targets=ensured_targets)
822
except ImportError:
923
cmdclass = {}
1024

0 commit comments

Comments
 (0)