Files
edx-platform/xmodule/util/builtin_assets.py
Kyle McCormick 2769a00e39 build: Remove unneccessary built-in XBlock Sass built steps (#35833)
Since all built-in block Sass is gone, we remove two final pieces of code:

* the steps in `npm run compile-sass` which compiled `xmodule/assets`, and
* the now-unused `add_sass_to_fragment` function.

This should speed up the edx-platform assets build a little bit.
This commit also includes some minor dev doc updates.

Part of: https://github.com/openedx/edx-platform/issues/35300
2024-11-14 14:05:30 +00:00

50 lines
2.1 KiB
Python

"""
Utilities for adding edx-platform assets to built-in XBlocks.
These should not be used to support any XBlocks outside of edx-platform.
"""
from pathlib import Path
import webpack_loader
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from openedx.core.djangoapps.theming.helpers_static import get_static_file_url
def add_css_to_fragment(fragment, css_relative_path):
"""
Given a css path relative to xmodule/static/css-builtin-blocks, add the CSS URL to the fragment.
Raises:
* ValueError if {css_relative_path} is absolute or does not end in '.css'.
* FileNotFoundError if edx-platform/xmodule/static/css-builtin-blocks/{css_relative_path} is missing.
* ImproperlyConfigured if the lookup of the static CSS URL fails. This could happen
if CSS wasn't collected, or the staticfiles app is misconfigured.
"""
if not isinstance(css_relative_path, Path):
css_relative_path = Path(css_relative_path)
if css_relative_path.is_absolute():
raise ValueError(f"css_file_name should be relative; is absolute: {css_relative_path}")
if css_relative_path.suffix != '.css':
raise ValueError(f"css_file_name should be .css file; is: {css_relative_path}")
css_absolute_path = Path(settings.REPO_ROOT) / "xmodule" / "static" / "css-builtin-blocks" / css_relative_path
if not css_absolute_path.is_file():
raise FileNotFoundError(f"css file not found: {css_absolute_path}")
css_static_path = Path('css-builtin-blocks') / css_relative_path.with_suffix('.css')
css_url = get_static_file_url(str(css_static_path))
if not css_url:
raise ImproperlyConfigured(
f"Did not find static CSS file {css_static_path} in staticfiles storage. Perhaps it wasn't collected?"
)
fragment.add_css_url(css_url)
def add_webpack_js_to_fragment(fragment, bundle_name):
"""
Add all JS webpack chunks to the supplied fragment.
"""
for chunk in webpack_loader.utils.get_files(bundle_name, None, 'DEFAULT'):
if chunk['name'].endswith(('.js', '.js.gz')):
fragment.add_javascript_url(chunk['url'])