Airgap Tethys when STATICFILES_USE_NPM is true - #1300
Draft
James-Dolinar wants to merge 5 commits into
Draft
Conversation
- Register it in vendor_static_dependencies so it can be served locally - Replace the hardcoded jsDelivr CDN link in map_layout.html with the vendored dependency, so the Select2 Bootstrap 5 theme works air-gapped
- Add staticfiles_use_npm to map layout's context dictionary - Use staticfiles_use_npm to determine when to use the local plotly instead of the CDN provided plotly - Continue to allow specifying the version of plotly in the controller when staticfiles_use_npm is False - Local plotly is inlined from the installed Python package via the plotly_view gizmo dependency
- Register it in vendor_static_dependencies so it can be served locally - Replace the hardcoded Font Awesome CDN link (use.fontawesome.com) in tethys_layout.html with the vendored dependency, so fontawesome works air-gapped - Online, Font Awesome now loads from jsDelivr (the vendored dependency's CDN) instead of use.fontawesome.com
- Let app templates load third-party JS/CSS that is served from the app's local
node_modules when STATICFILES_USE_NPM is True, and from the CDN otherwise, so
apps work air-gapped without a manual local/CDN toggle
- Derive the local path automatically from jsDelivr and unpkg npm URLs, so authors
only pass the CDN URL they would normally use
- Accept an optional local_path for CDNs that can't be auto-derived (e.g. cdnjs)
- Register the tags in the tethys template tag library so they're available via {% load tethys %}
…ailable offline - In get_custom_version_url, serve the installed (default) version locally instead of the CDN when STATICFILES_USE_NPM is True and a different version is requested - The old CDN fallback failed in air-gapped environments; npm only installs the default version, so that's the only one available locally - Log a warning that the requested version isn't available and the installed one is used - Online behavior is unchanged: with STATICFILES_USE_NPM False, the requested version is still served from the CDN
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Remove hard coded requests to CDNs so the static dependencies are served through Tethys when
STATICFILES_USE_NPMis true. Additionally, add convenience tags{% dependency_script %}and{% dependency_link %}so app creators don't have to use conditionals in templates to determine whenSTATICFILES_USE_NPMis true or false.Changes Made to Code
select2-bootstrap-5-themeand Font Awesome (@fortawesome/fontawesome-free) tovendor_static_dependenciesso they can be served locally.StaticDependency.get_custom_version_urlto serve the locally-installed (default) version instead of falling back to a CDN whenSTATICFILES_USE_NPMis true and a non-installed version is requested (the old CDN fallback fails in an air-gapped environment). Online behavior is unchanged — the requested version is still fetched from the CDN.map_layout.html: replaced the hard codedselect2-bootstrap-5-themeCDN<link>with the vendored dependency; load Plotly locally (inlined from the installed Python package via theplotly_viewgizmo dependency) whenSTATICFILES_USE_NPMis true, and from the CDN otherwise (still version-configurable in the controller).map_layout.py: addedstaticfiles_use_npmto the template context to drive the Plotly conditional.tethys_layout.html: replaced the hard coded Font Awesome CDN<link>with the vendored dependency.tethys_apps/templatetags/dependency.py: added{% dependency_script %}and{% dependency_link %}. They emit a<script>/<link>that resolves to the app's localnode_moduleswhenSTATICFILES_USE_NPMis true and to the CDN otherwise. The local path is derived automatically from jsDelivr/unpkg npm URLs; an optionallocal_pathargument covers other CDNs (e.g. cdnjs).tethys_sdk/templatetags/tethys.py: registered the new tags in the aggregatedtethyslibrary so they're available via{% load tethys %}.Related PRs, Issues, and Discussions
Additional Notes
Quality Checks