Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install pre-commit automatically #763

Merged
merged 2 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions CONTRIBUTING.rst
Expand Up @@ -27,7 +27,7 @@ steps::
pip install --upgrade setuptools pip
git clone https://github.com/jupyter/jupyter_server
cd jupyter_server
pip install -e .
pip install -e ".[test]"

If you are using a system-wide Python installation and you only want to install the server for you,
you can add ``--user`` to the install commands.
Expand All @@ -44,7 +44,10 @@ Code Styling
need to worry too much about your code style.
As long as your code is valid,
the pre-commit hook should take care of how it should look.
To install `pre-commit`, run the following::
`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::

pip install pre-commit
pre-commit install
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,5 +1,5 @@
[build-system]
requires = ["jupyter_packaging~=0.9"]
requires = ["jupyter_packaging~=0.9", "pre-commit"]
build-backend = "jupyter_packaging.build_api"

[tool.jupyter-packaging.builder]
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -57,6 +57,7 @@ test =
pytest-tornasync
pytest-console-scripts
ipykernel
pre-commit
# NOTE: we cannot auto install examples/simple here because of:
# https://github.com/pypa/pip/issues/6658

Expand Down
16 changes: 15 additions & 1 deletion setup.py
@@ -1,10 +1,24 @@
import subprocess
import sys

from setuptools import setup

try:
from jupyter_packaging import wrap_installers, npm_builder

ensured_targets = ["jupyter_server/static/style/bootstrap.min.css"]
cmdclass = wrap_installers(pre_develop=npm_builder(), ensured_targets=ensured_targets)

def post_develop(*args, **kwargs):
npm_builder()
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)
except ImportError:
cmdclass = {}

Expand Down