From c9476aba371b8ccc9528d4c7f2845cef62d8817e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 28 Mar 2022 06:19:24 -0500 Subject: [PATCH] Install pre-commit automatically (#763) * install pre-commit automatically * add to build reqs --- CONTRIBUTING.rst | 7 +++++-- pyproject.toml | 2 +- setup.cfg | 1 + setup.py | 16 +++++++++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 09b67e0dca..9f643ebb2a 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -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. @@ -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 diff --git a/pyproject.toml b/pyproject.toml index c98a59e79f..7f54551dc2 100644 --- a/pyproject.toml +++ b/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] diff --git a/setup.cfg b/setup.cfg index f4699347bc..6a7282a5d2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py index 33b952f110..499eb46d94 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,24 @@ +import subprocess +import sys + from setuptools import setup try: from jupyter_packaging import npm_builder, wrap_installers 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 = {}