Skip to content

Commit

Permalink
Don't build the extension in pre-commit envs
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Apr 27, 2024
1 parent 642c709 commit c607e7d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
31 changes: 31 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
import os
import sys

from hatch_jupyter_builder.plugin import JupyterBuildHook

LOGGER = logging.getLogger(__name__)


class CustomBuildHook(JupyterBuildHook):
"""
We use a custom build hook to detect pre-commit environments. In those
environments there is no need to build the extension (and, in addition
the build will fail if npm is not available, which is often the case
of pre-commit environments).
"""

def initialize(self, version, _):
if "/.cache/pre-commit/".replace("/", os.path.sep) in sys.executable:
LOGGER.info(
"This environment looks like a pre-commit environment. "
"We will skip the build of the Jupytext extension for JupyterLab."
)
self._skipped = True
return

return super().initialize(version=version, _=_)


# hatch wants a single hook
del JupyterBuildHook
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ packages = ["src/jupytext", "src/jupytext_config", "jupyterlab/jupyterlab_jupyte
"jupyterlab/jupyter-config" = "etc/jupyter"
"jupyterlab/jupyterlab_jupytext/labextension" = "share/jupyter/labextensions/jupyterlab-jupytext"

[tool.hatch.build.hooks.jupyter-builder]
[tool.hatch.build.hooks.custom]
# 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
# Runtime dependency for this build hook
# We need jupyterlab as build time depdendency to get jlpm (wrapper around yarn)
# We need jupyterlab as build time dependency to get jlpm (wrapper around yarn)
dependencies = [
"hatch-jupyter-builder>=0.5", "jupyterlab>=4"
]
Expand All @@ -154,15 +154,15 @@ ensured-targets = [
# the extension, build will be triggered even if the build assets exist
skip-if-exists = ["jupyterlab/jupyterlab_jupytext/labextension/static/style.js"]

[tool.hatch.build.hooks.jupyter-builder.build-kwargs]
[tool.hatch.build.hooks.custom.build-kwargs]
# Root directory where build should be done
path = "jupyterlab"
# Build command that is defined in package.json
build_cmd = "build:prod"
# We use jlpm, which is wrapper around yarn to build transpiled assets
npm = ["jlpm"]

[tool.hatch.build.hooks.jupyter-builder.editable-build-kwargs]
[tool.hatch.build.hooks.custom.editable-build-kwargs]
path = "jupyterlab"
build_cmd = "build"
npm = ["jlpm"]
Expand Down

0 comments on commit c607e7d

Please sign in to comment.