Skip to content

Commit

Permalink
Automatically download labvariables CSS instead of shipping them
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jan 18, 2022
1 parent 63e0f91 commit 03e5429
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 1,028 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ package-lock.json
share/jupyter/voila/templates/base/static/*voila.js
share/jupyter/voila/templates/base/static/*[woff|woff2|eot|svg]

share/jupyter/voila/templates/classic/static/labvariables.css
share/jupyter/voila/templates/classic/static/materialcolors.css

share/jupyter/voila/templates/reveal/static/labvariables.css
share/jupyter/voila/templates/reveal/static/materialcolors.css

lib

voila/labextension
Expand All @@ -40,4 +46,4 @@ tsconfig.tsbuildinfo
ui-tests/playwright-report
ui-tests/test-results
ui-tests/benchmark-results
ui-tests/jlab_root
ui-tests/jlab_root
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ test =
[options.entry_points]
console_scripts =
voila = voila.app:main

[check-manifest]
ignore =
share/jupyter/voila/templates/classic/static/labvariables.css
share/jupyter/voila/templates/classic/static/materialcolors.css
share/jupyter/voila/templates/reveal/static/labvariables.css
share/jupyter/voila/templates/reveal/static/materialcolors.css
78 changes: 77 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
# The full license is in the file LICENSE, distributed with this software. #
#############################################################################
from pathlib import Path

from urllib.request import urlopen
import setuptools
import sys
import os

HERE = Path(__file__).parent.resolve()

Expand Down Expand Up @@ -47,13 +49,87 @@
("share/jupyter/voila/templates", "share/jupyter/voila/templates", "**/*[!.map]"),
]


jupyterlab_apputils_version = "3.2.8"
jupyterlab_theme_light_version = "3.2.8"

css_files = [
(
"https://unpkg.com/@jupyterlab/apputils@%s/style/materialcolors.css"
% jupyterlab_apputils_version,
"materialcolors.css",
),
(
"https://unpkg.com/@jupyterlab/theme-light-extension@%s/style/variables.css"
% jupyterlab_theme_light_version,
"labvariables.css",
),
]


class FetchCSS(setuptools.Command):
"""Fetch CSS files from the CDNs."""

description = "Fetch CSS from CDN"
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
for template_name in ["classic", "reveal"]:
for url, filename in css_files:
directory = os.path.join(
"share", "jupyter", "voila", "templates", template_name, "static"
)
dest = os.path.join(directory, filename)
if not os.path.exists(directory):
os.makedirs(directory)
if not os.path.exists(".git") and os.path.exists(dest):
# not running from git, nothing to do
return
print("Downloading CSS: %s" % url)
try:
css = urlopen(url).read()
except Exception as e:
msg = "Failed to download css from %s: %s" % (url, e)
print(msg, file=sys.stderr)

if os.path.exists(dest):
print("Already have CSS: %s, moving on." % dest)
else:
raise OSError("Need CSS to proceed.")
return

with open(dest, "wb") as f:
f.write(css)
print("Downloaded Notebook CSS to %s" % dest)


def download_css_first(command):
class CSSFirst(command):
def run(self):
self.distribution.run_command("download_css")
return command.run(self)

return CSSFirst


try:
from jupyter_packaging import wrap_installers, npm_builder, get_data_files

# In develop mode, just run yarn
builder = npm_builder(build_cmd="build", npm="jlpm", force=True)
cmdclass = wrap_installers(post_develop=builder, ensured_targets=ensured_targets)

cmdclass["download_css"] = FetchCSS
cmdclass["develop"] = download_css_first(cmdclass["develop"])
cmdclass["sdist"] = download_css_first(cmdclass["sdist"])
cmdclass["bdist_wheel"] = download_css_first(cmdclass["bdist_wheel"])

setup_args = dict(cmdclass=cmdclass, data_files=get_data_files(data_files_spec))
except ImportError:
setup_args = dict()
Expand Down
209 changes: 0 additions & 209 deletions share/jupyter/voila/templates/classic/static/labvariables.css

This file was deleted.

Loading

0 comments on commit 03e5429

Please sign in to comment.