Repository: mwouts/jupytext (language: python)

Issue:
The Jupytext pre-commit hook fails to install when node is not available
The Jupytext pre-commit hook documented [here](https://jupytext.readthedocs.io/en/latest/using-pre-commit.html#what-is-the-point-of-having-a-jupytext-pre-commit-hook) fails to install when selecting `v1.16.0` or above.

This is because `node` is required to build the JupyterLab extension for Jupytext.

We need to figure out how to not build the extension (e.g. set `HATCH_BUILD_HOOKS_ENABLE=false`) when `jupytext` is installed by `pre-commit`.

The current workaround is to use Jupytext in version `v1.15.2` in the pre-commit hooks.



Discussion / hints:
I can reproduce the issue with `tests/external/pre_commit/test_pre_commit_1_sync.py` when `node` is not installed.
What I think we could do is set `HATCH_BUILD_HOOKS_ENABLE=false` for when the `jupytext` pre-commit hook is installed. There are many similar questions on the pre-commit project, see e.g. https://github.com/pre-commit/pre-commit/issues/2367, but it is not yet obvious to me how we can set a variable for the hook installation.

Fix patch:
diff --git a/.github/workflows/comment-pr.yml b/.github/workflows/comment-pr.yml
index 267dcbb7..0500f369 100644
--- a/.github/workflows/comment-pr.yml
+++ b/.github/workflows/comment-pr.yml
@@ -24,7 +24,7 @@ jobs:
 
             Also, the version of Jupytext developed in this PR can be installed with `pip`:
             ```
-            pip install git+${{ github.event.pull_request.head.repo.clone_url }}@${{ github.event.pull_request.head.ref }}
+            HATCH_BUILD_HOOKS_ENABLE=true pip install git+${{ github.event.pull_request.head.repo.clone_url }}@${{ github.event.pull_request.head.ref }}
             ```
             (this requires `nodejs`, see more at [Developing Jupytext](https://jupytext.readthedocs.io/en/latest/developing.html))
           comment_tag: binder_link
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 0a65697f..453bb109 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -65,7 +65,7 @@ jobs:
       - name: Build package
         run: |
           python -m pip install wheel build
-          python -m build
+          HATCH_BUILD_HOOKS_ENABLE=true python -m build
 
       - name: Publish
         uses: pypa/gh-action-pypi-publish@release/v1
diff --git a/.github/workflows/step_build.yml b/.github/workflows/step_build.yml
index 910acfba..f41e2078 100644
--- a/.github/workflows/step_build.yml
+++ b/.github/workflows/step_build.yml
@@ -29,7 +29,7 @@ jobs:
           python_version: "3.x"
 
       - name: Build package
-        run: hatch build
+        run: HATCH_BUILD_HOOKS_ENABLE=true hatch build
 
       - name: Archive build artifacts
         uses: actions/upload-artifact@v3
diff --git a/.github/workflows/step_coverage.yml b/.github/workflows/step_coverage.yml
index 8220545d..2a23c6e6 100644
--- a/.github/workflows/step_coverage.yml
+++ b/.github/workflows/step_coverage.yml
@@ -28,7 +28,7 @@ jobs:
           python_version: 3.x
 
       - name: Install from source
-        run: HATCH_BUILD_HOOKS_ENABLE=false python -m pip install -e '.[test-cov,test-${{ matrix.coverage }}]'
+        run: python -m pip install -e '.[test-cov,test-${{ matrix.coverage }}]'
 
       - name: Install a Jupyter Kernel
         run: python -m ipykernel install --name python_kernel --user
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2aec9109..7a49c75c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Jupytext ChangeLog
 - Added support for Xonsh notebooks ([#1213](https://github.com/mwouts/jupytext/pull/1213)) - thanks to [Jeffrey Odongo](https://github.com/jsquaredosquared) for this contribution
 
 **Changed**
+- By default, the JupyterLab extension for Jupytext is not included in the build (set `HATCH_BUILD_HOOKS_ENABLE=true` to include it). This simplifies the installation of Jupytext in pre-commit hooks ([#1210](https://github.com/mwouts/jupytext/issues/1210))
 - Temporary text notebooks for the `--pipe` or `--check` commands are now created in the notebook directory ([#1206](https://github.com/mwouts/jupytext/issues/1206))
 - Jupytext uses the standard library `tomllib` in Python 3.11, or `tomli` in Python 3.10 or older, to match JupyterLab's dependencies ([#1195](https://github.com/mwouts/jupytext/issues/1195))
 
diff --git a/binder/postBuild b/binder/postBuild
index 0efabf83..81c03c8f 100644
--- a/binder/postBuild
+++ b/binder/postBuild
@@ -4,7 +4,7 @@ set -e
 # Install from sources
 # NB: If you want to use Jupytext on your binder, don't install it from source,
 # just add "jupytext" to your "binder/requirements.txt" instead.
-pip install .
+HATCH_BUILD_HOOKS_ENABLE=true pip install .
 
 mkdir -p ${HOME}/.jupyter/labconfig
 cp binder/labconfig/* ${HOME}/.jupyter/labconfig
diff --git a/docs/developing.md b/docs/developing.md
index 05e3e2ce..68b9dada 100644
--- a/docs/developing.md
+++ b/docs/developing.md
@@ -4,7 +4,7 @@
 
 If you want to test a feature that has been integrated in `main` but not delivered yet to `pip` or `conda`, use
 ```
-pip install git+https://github.com/mwouts/jupytext.git
+HATCH_BUILD_HOOKS_ENABLE=true pip install git+https://github.com/mwouts/jupytext.git
 ```
 
 The above requires `node`. You can install it with e.g.
@@ -12,12 +12,11 @@ The above requires `node`. You can install it with e.g.
 conda install 'nodejs>=20' -c conda-forge
 ```
 
-Alternatively you can build only Jupytext core (e.g. skip the JupyterLab extension). To do so, prefix the
-above with `HATCH_BUILD_HOOKS_ENABLE=false`.
+Alternatively you can build only Jupytext core (e.g. skip the JupyterLab extension). To do so, remove `HATCH_BUILD_HOOKS_ENABLE=true` in the above.
 
 Finally, if you want to test a development branch, use
 ```
-pip install git+https://github.com/mwouts/jupytext.git@branch
+HATCH_BUILD_HOOKS_ENABLE=true pip install git+https://github.com/mwouts/jupytext.git@branch
 ```
 where `branch` is the name of the branch you want to test.
 
@@ -31,7 +30,7 @@ conda activate jupytext-dev
 
 Install the `jupytext` package in development mode with
 ```
-pip install -e '.[dev]'
+HATCH_BUILD_HOOKS_ENABLE=true pip install -e '.[dev]'
 ```
 
 We use the [pre-commit](https://pre-commit.com) package to run pre-commit scripts like `black` and `ruff` on the code.
diff --git a/pyproject.toml b/pyproject.toml
index e6bd196d..fa624cff 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -131,11 +131,11 @@ packages = ["src/jupytext", "src/jupytext_config", "jupyterlab/jupyterlab_jupyte
 "jupyterlab/jupyterlab_jupytext/labextension" = "share/jupyter/labextensions/jupyterlab-jupytext"
 
 [tool.hatch.build.hooks.jupyter-builder]
-# Enable running hook by default.
-# We disable this hook only by setting env var HATCH_BUILD_HOOKS_ENABLE=false
-# So `HATCH_BUILD_HOOKS_ENABLE=false pip install .` will **not** build JupyterLab related
-# extension. A simple `pip install .` will **always** build extension
-enable-by-default = true
+enable-by-default = false
+# We enable this hook by setting env var HATCH_BUILD_HOOKS_ENABLE=true
+# So `pip install .` will **not** build JupyterLab related
+# extension. To install the extension, it is required to run
+# `HATCH_BUILD_HOOKS_ENABLE=true pip install .`
 # Runtime dependency for this build hook
 # We need jupyterlab as build time depdendency to get jlpm (wrapper around yarn)
 dependencies = [


Test patch:
diff --git a/.github/workflows/step_tests-conda.yml b/.github/workflows/step_tests-conda.yml
index 41f0b7f8..00fb1826 100644
--- a/.github/workflows/step_tests-conda.yml
+++ b/.github/workflows/step_tests-conda.yml
@@ -43,7 +43,7 @@ jobs:
           environment-file: .ci/environment-ci.yml
 
       - name: Install from source
-        run: python -m pip install -e '.[test-external,test-cov]'
+        run: HATCH_BUILD_HOOKS_ENABLE=true python -m pip install -e '.[test-external,test-cov]'
 
       - name: Conda list
         run: conda list
diff --git a/.github/workflows/step_tests-pip.yml b/.github/workflows/step_tests-pip.yml
index eb055570..43564714 100644
--- a/.github/workflows/step_tests-pip.yml
+++ b/.github/workflows/step_tests-pip.yml
@@ -55,7 +55,7 @@ jobs:
 
       - name: Install from source
         run: >
-          python -m pip install
+          HATCH_BUILD_HOOKS_ENABLE=true python -m pip install
           -e '.[test-cov,test-external]'
           jupyterlab
           ${{ format('markdown-it-py{0}', matrix.markdown-it-py) }}
diff --git a/.github/workflows/step_tests-ui.yml b/.github/workflows/step_tests-ui.yml
index abc48c27..ce960315 100644
--- a/.github/workflows/step_tests-ui.yml
+++ b/.github/workflows/step_tests-ui.yml
@@ -22,7 +22,7 @@ jobs:
           python_version: 3.x
 
       - name: Install from source
-        run: python -m pip install -e '.[test-ui]'
+        run: HATCH_BUILD_HOOKS_ENABLE=true python -m pip install -e '.[test-ui]'
 
       - name: Install galata
         working-directory: jupyterlab/packages/jupyterlab-jupytext-extension/ui-tests