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

Automatically download labvariables CSS instead of shipping them #1062

Merged
merged 1 commit into from
Jan 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ before-build-python = ["jlpm clean"]
version-cmd = "python scripts/bump-version.py --force"

[tool.check-manifest]
ignore = [".binder/**", "docs/**", "notebooks/**", "packages/**", "share/**/*.js", "share/**/*.woff", "*.json", "*.gif", "yarn.lock", "environment.yml", "readthedocs.yml", ".*", "lint-staged.config.js", "scripts/**", "voila/labextension/**", "voila/static/**", "tests/**", "ui-tests/**"]
ignore = [
".binder/**", "docs/**", "notebooks/**",
"packages/**",
"share/**/*.js", "share/**/*.woff", "share/**/*.css",
"*.json", "*.gif", "yarn.lock",
"environment.yml", "readthedocs.yml", ".*",
"lint-staged.config.js", "scripts/**",
"voila/labextension/**", "voila/static/**",
"tests/**", "ui-tests/**",
]
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