-
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
35 additions
and
4 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,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 |
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