Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping the build plugin #74

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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