-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't build the extension in pre-commit envs
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import sys | ||
from typing import Any | ||
|
||
from hatch_jupyter_builder.plugin import JupyterBuildHook, _get_log | ||
|
||
|
||
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: str, _: dict[str, Any]) -> None: | ||
log = _get_log() | ||
log.info( | ||
"Preparing the build of the JupyterLab extension for Jupytext " | ||
f"in this environment: {sys.executable}" | ||
) | ||
if "/.cache/pre-commit/".replace("/", os.path.sep) in sys.executable: | ||
log.info( | ||
"This environment looks like a pre-commit environment. " | ||
"Skipping the build of the extension" | ||
) | ||
self._skipped = True | ||
return | ||
|
||
return super().initialize(version=version, _=_) | ||
|
||
|
||
# hatch wants a single hook | ||
del JupyterBuildHook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters