Skip to content

Commit

Permalink
Allow skipping the build plugin (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Sep 27, 2022
1 parent 51f2c9f commit 0a59d72
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ To test this package locally with another package, use the following:
dependencies = ["hatch-jupyter-builder@file://<path_to_this_repo>"]
```

## Skipping the Build

You can skip the build by setting the `SKIP_JUPYTER_BUILDER` environment
variable.

## Migration

This library can be used to migrate from a `setuptools` based package to
Expand Down
8 changes: 7 additions & 1 deletion hatch_jupyter_builder/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import typing as t
from dataclasses import dataclass, field, fields

Expand Down Expand Up @@ -33,7 +34,11 @@ def initialize(self, version, build_data):
log.info("Running jupyter-builder")
if self.target_name not in ["wheel", "sdist"]:
log.info(f"ignoring target name {self.target_name}")
return
return False

if os.getenv("SKIP_JUPYTER_BUILDER"):
log.info("Skipping the build hook since SKIP_JUPYTER_BUILDER was set")
return False

kwargs = normalize_kwargs(self.config)
available_fields = [f.name for f in fields(JupyterBuildConfig)]
Expand Down Expand Up @@ -76,3 +81,4 @@ def initialize(self, version, build_data):
ensure_targets(config.ensured_targets)

log.info("Finished running jupyter-builder")
return True
23 changes: 15 additions & 8 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


def test_build_hook(tmp_path):
if "SKIP_JUPYTER_BUILD" in os.environ:
del os.environ["SKIP_JUPYTER_BUILD"]

config = {
"build-function": "test.foo",
"ensured-targets": ["test.py"],
Expand All @@ -23,24 +26,28 @@ def foo(target_name, version, foo_bar=None, fizz_buzz=None):
os.makedirs(".git/hooks")

hook = JupyterBuildHook(tmp_path, config, {}, {}, tmp_path, "wheel")
hook.initialize("standard", {})
hook.initialize("editable", {})
assert hook.initialize("standard", {})
assert hook.initialize("editable", {})

hook = JupyterBuildHook(tmp_path, config, {}, {}, tmp_path, "sdist")
hook.initialize("standard", {})
assert hook.initialize("standard", {})

hook = JupyterBuildHook(tmp_path, {}, {}, {}, tmp_path, "wheel")
hook.initialize("standard", {})
hook.initialize("editable", {})
assert hook.initialize("standard", {})
assert hook.initialize("editable", {})

config["skip-if-exists"] = ["foo", "bar"]
hook.initialize("standard", {})
assert hook.initialize("standard", {})

config["editable-build-kwargs"] = {"foo-bar": "2", "fizz_buzz": "3"}
hook.initialize("editable", {})
assert hook.initialize("editable", {})

hook = JupyterBuildHook(tmp_path, config, {}, {}, tmp_path, "foo")
hook.initialize("standard", {})
assert not hook.initialize("standard", {})

os.environ["SKIP_JUPYTER_BUILD"] = "1"
assert not hook.initialize("standard", {})
del os.environ["SKIP_JUPYTER_BUILD"]


HERE = Path(__file__).parent
Expand Down

0 comments on commit 0a59d72

Please sign in to comment.