-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
435632e
commit 1395a76
Showing
8 changed files
with
96 additions
and
10 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 |
---|---|---|
|
@@ -21,3 +21,6 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
__pycache__ | ||
src/dashboard.json |
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
Empty file.
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,9 @@ | ||
name: build-env | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python | ||
- pip | ||
- pip: | ||
- voici>=0.3.2,<0.4.0 | ||
- jupyterlite-xeus-python>=0.8.0,<0.9.0 |
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 |
---|---|---|
@@ -1,25 +1,82 @@ | ||
from ast import Dict, List | ||
import json | ||
from pathlib import Path | ||
|
||
import subprocess | ||
import sys | ||
from typing import Optional | ||
import yaml | ||
import voici | ||
import logging | ||
|
||
from utils import create_dir | ||
|
||
logger = logging.getLogger(__file__) | ||
ROOT_DIR = Path(__file__).parents[1] | ||
VOICI_BUILD_DIR = ROOT_DIR / "voici_build" | ||
VOICI_STATIC_DIR = VOICI_BUILD_DIR / "voici" | ||
GIT = "git" | ||
VOICI = "voici" | ||
|
||
|
||
|
||
|
||
class Builder: | ||
def __init__(self, config_path: Path) -> None: | ||
self.load_config(config_path) | ||
create_dir(VOICI_BUILD_DIR) | ||
create_dir(VOICI_STATIC_DIR) | ||
self._artifact = [] | ||
|
||
def load_config(self, config_path: Path) -> None: | ||
with open(config_path, "r") as f: | ||
self._yaml_data: List[Dict] = yaml.load(f, Loader=yaml.CLoader) | ||
|
||
def build(self) -> None: | ||
for config in self._yaml_data: | ||
self.build_single(config) | ||
for idx, config in enumerate(self._yaml_data): | ||
self.build_single(idx, config) | ||
|
||
artifact_path = ROOT_DIR / 'src' / 'dashboard.json' | ||
with open(artifact_path, 'w') as f: | ||
json.dump(self._artifact, f, indent=2) | ||
|
||
def build_single(self, index: int, config: Dict) -> None: | ||
repo_path = VOICI_BUILD_DIR / str(index) | ||
create_dir(repo_path) | ||
cloned = self.clone_repo(config["repo_url"], config.get("branch"), repo_path) | ||
if cloned: | ||
dashboard_url = self.build_voici(repo_path, config.get("content_path", "."), index) | ||
if dashboard_url is not None: | ||
config['dashboard_url'] = dashboard_url | ||
self._artifact.append(config) | ||
|
||
def build_single(self, config: Dict) -> None: | ||
pass | ||
def clone_repo(self, url: str, branch: Optional[str], dest: Path) -> bool: | ||
branch = branch or "main" | ||
cmd = ["git", "clone", "-b", branch, url, str(dest)] | ||
logger.debug(f"Cloning {url} at {branch}") | ||
try: | ||
subprocess.run(cmd) | ||
return True | ||
except Exception as e: | ||
logger.error(e) | ||
return False | ||
|
||
def build_voici(self, repo_path: Path, content_path: str, index: int) -> Optional[str]: | ||
output_dir = VOICI_STATIC_DIR / str(index) | ||
logger.debug(f"Building voici from {repo_path} to {output_dir}") | ||
cmd = [ "voici", "build", "--contents", content_path, "--output-dir", output_dir] | ||
|
||
try: | ||
subprocess.run(cmd, cwd=repo_path) | ||
return f"voici/{index}" | ||
except Exception: | ||
logger.error(e) | ||
return None | ||
|
||
if __name__ == "__main__": | ||
config_file = Path(__file__).parent / Path("gallery.yaml") | ||
debug = "--debug" in sys.argv | ||
if debug: | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
config_file = ROOT_DIR / "script" / Path("gallery.yaml") | ||
builder = Builder(config_file) | ||
builder.build() |
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
- title: voici-demo | ||
description: First Voici demo | ||
content_path: content/demo.ipynb | ||
build_env: build-environment.yml | ||
repo_url: https://github.com/voila-dashboards/voici-demo | ||
image_url: https://i.imgur.com/IeG75O3.png | ||
|
||
- title: voici-demo | ||
description: Second Voici demo | ||
content_path: content | ||
repo_url: https://github.com/voila-dashboards/voici-demo | ||
ref: HEAD | ||
build_env: build-environment.yml | ||
branch: main | ||
image_url: https://i.imgur.com/IeG75O3.png |
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,7 @@ | ||
import shutil | ||
from pathlib import Path | ||
|
||
def create_dir(path: Path) -> None: | ||
if path.exists(): | ||
shutil.rmtree(path) | ||
path.mkdir() |
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