From 13572098188d07e0d4c7b84f75bf59b6d2563892 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 28 Mar 2022 05:37:18 -0500 Subject: [PATCH 1/2] install pre-commit automatically --- CONTRIBUTING.rst | 7 +++++-- setup.cfg | 1 + setup.py | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 3 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/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 9a33dccc5d..71ff726231 100644 --- a/setup.py +++ b/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 = {} From ce9de07c6b1d419153ae0f7f0c92b0c28040678d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 28 Mar 2022 05:38:24 -0500 Subject: [PATCH 2/2] add to build reqs --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7055f94979..79d61c5cf5 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]