From e2887fbac7e6b6b4e753fd18eb399c24adfb148f Mon Sep 17 00:00:00 2001 From: Tony Hirst Date: Thu, 17 Jun 2021 18:25:13 +0100 Subject: [PATCH] Refactor; add subdir example --- .github/workflows/deploy.yml | 15 ++++-------- all_generator.py | 19 +++++++++++++-- content/{ => subdir_example}/pyolite.ipynb | 0 deploy.sh | 28 ++++++++++++++++++++++ jupyterlite-install.sh | 9 +++++++ 5 files changed, 59 insertions(+), 12 deletions(-) rename content/{ => subdir_example}/pyolite.ipynb (100%) create mode 100755 deploy.sh create mode 100755 jupyterlite-install.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7df61c170..e1b67b09a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,8 +16,8 @@ jobs: uses: actions/checkout@v2 - name: Fetch the release run: | - curl -L https://github.com/jtpio/jupyterlite/releases/download/v0.1.0a0/jupyterlite-app-0.1.0-alpha.0.tgz | tar -xz - mv package dist + chmod u+x ./jupyterlite-install.sh + ./jupyterlite-install.sh - name: Copy the federated extensions run: | # TODO @@ -25,15 +25,10 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 - - name: Create all.json + - name: Create manifest and stage run: | - pip install jupyter_server - python all_generator.py - - name: Copy the content - run: | - mkdir -p dist/api/contents/ dist/files - cp all.json dist/api/contents/ - cp -r content/* dist/files/ + chmod u+x ./deploy.sh + ./deploy.sh - name: List the content of the app run: | tree dist diff --git a/all_generator.py b/all_generator.py index 28c4cd8df..0fa7cb6b6 100644 --- a/all_generator.py +++ b/all_generator.py @@ -16,7 +16,9 @@ def default(self, o): path = '.' -outdir = Path(path) + +outdir = Path(path) / 'file_manifests' +outdir.mkdir(exist_ok=True) files_dir = Path(path) / 'content' @@ -30,5 +32,18 @@ def default(self, o): json.dumps( fm.get(''), indent=2, sort_keys=True, cls=DateTimeEncoder ), - encoding="utf-8", + encoding="utf-8" ) + +# We then need to do this for every directory in the contents dir +for p in files_dir.iterdir(): + if p.is_dir(): + rel_p = p.relative_to(str(files_dir)) + + all_json = (outdir / rel_p / "all.json") + all_json.parent.mkdir(parents=True, exist_ok=True) + + all_json.write_text( + json.dumps(fm.get(str(rel_p)), indent=2, sort_keys=True, cls=DateTimeEncoder), + encoding="utf-8" + ) diff --git a/content/pyolite.ipynb b/content/subdir_example/pyolite.ipynb similarity index 100% rename from content/pyolite.ipynb rename to content/subdir_example/pyolite.ipynb diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 000000000..72825c6f1 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Ensure this file is executable: chmod u+x deploy.sh + +# Ensure that jupyterlite is installed: ./jupyterlite-install.sh + +# Create all.json manifest +pip3 install jupyter_server +python3 all_generator.py + +# Ensure distrribtiuon file directory available +mkdir -p dist/api/contents/ dist/files + +# Copy manifest +#cp all.json dist/api/contents/ +cp -R file_manifests/* dist/api/contents/ + +cp jupyter-lite.json dist/ +cp config-utils.js dist/ +cp -R custom/* dist/ + +# Copy content +rm -rf dist/files/* +cp -r content/* dist/files/ + + + +# Local webserver +# python3 -m http.server 8111 -d dist/ diff --git a/jupyterlite-install.sh b/jupyterlite-install.sh new file mode 100755 index 000000000..3c1e05b4c --- /dev/null +++ b/jupyterlite-install.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Ensure this file is executable: chmod u+x jupyterlite-install.sh + +# Install jupyterlite +curl -L https://github.com/jtpio/jupyterlite/releases/download/v0.1.0a0/jupyterlite-app-0.1.0-alpha.0.tgz | tar -xz +mv package dist + +# Install packages +#cp -R packages/* dist/ \ No newline at end of file