Skip to content

Commit

Permalink
Add logging and handle editable npm arg (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Jul 1, 2022
1 parent 82b4e39 commit e1870bc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hatch_jupyter_builder/migrate/_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
if build_args_table:
builder_table["build-kwargs"] = build_args_table.copy()

if build_args_table.get("npm"):
if "editable-build-kwargs" in builder_table:
builder_table["editable-build-kwargs"]["npm"] = build_args_table["npm"]

# Add artifacts config for package data that would be ignored.
project_name = data.get("project", {}).get("name", "")
gitignore = Path(".gitignore")
Expand Down
13 changes: 13 additions & 0 deletions hatch_jupyter_builder/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

from .utils import (
_get_log,
ensure_targets,
get_build_func,
install_pre_commit_hook,
Expand All @@ -13,7 +14,10 @@ class JupyterBuildHook(BuildHookInterface):
PLUGIN_NAME = "jupyter-builder"

def initialize(self, version, build_data):
log = _get_log()
log.info("Running jupyter-builder")
if self.target_name not in ["wheel", "sdist"]:
log.info(f"ignoring target name {self.target_name}")
return

should_install_hook = self.config.get("install-pre-commit-hook")
Expand All @@ -33,17 +37,26 @@ def initialize(self, version, build_data):

should_skip_build = False
if not build_function:
log.warning("No build function found")
should_skip_build = True

elif skip_if_exists and version == "standard":
should_skip_build = should_skip(skip_if_exists)
if should_skip_build:
log.info("Skip-if-exists file(s) found")

# Get build function and call it with normalized parameter names.
if not should_skip_build:
build_func = get_build_func(build_function)
build_kwargs = normalize_kwargs(build_kwargs)
log.info(f"Building with {build_function}")
log.info(f"With kwargs: {build_kwargs}")
build_func(self.target_name, version, **build_kwargs)
else:
log.info("Skipping build")

# Ensure targets in distributable dists.
if version == "standard":
ensure_targets(ensured_targets)

log.info("Finished running jupyter-builder")
3 changes: 3 additions & 0 deletions hatch_jupyter_builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def npm_builder(
run(npm_cmd + ["install"], cwd=str(abs_path))
if build_cmd:
run(npm_cmd + ["run", build_cmd], cwd=str(abs_path))
else:
log.info("No build required")


def is_stale(target: Union[str, Path], source: Union[str, Path]) -> bool:
Expand Down Expand Up @@ -226,6 +228,7 @@ def ensure_targets(ensured_targets: List[str]) -> None:
for target in ensured_targets:
if not Path(target).exists():
raise ValueError(f'Ensured target "{target}" does not exist')
_get_log().info("Ensured target(s) exist!")


def should_skip(skip_if_exists):
Expand Down
3 changes: 3 additions & 0 deletions tests/data/npm_builder/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ npm = [
build_cmd = "install:extension"
source_dir = "src"
build_dir = "myextension/labextension"
npm = [
"jlpm",
]

[tool.tbump]
field = [
Expand Down

0 comments on commit e1870bc

Please sign in to comment.