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

all_files support for py-shinylive's base-deps function #14

Merged
merged 1 commit into from
Sep 29, 2023
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
13 changes: 9 additions & 4 deletions shinylive/_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,27 @@ def _pyodide_pkg_infos_to_quarto_html_dep_items(
# =============================================================================
def shinylive_base_deps_htmldep(
sw_dir: Optional[str] = None,
*,
all_files: bool = False,
) -> list[QuartoHtmlDependency]:
return [
_serviceworker_dep(sw_dir),
_shinylive_common_dep_htmldep(),
_shinylive_common_dep_htmldep(all_files=all_files),
]


# =============================================================================
# Common dependencies
# =============================================================================
def _shinylive_common_dep_htmldep() -> QuartoHtmlDependency:
def _shinylive_common_dep_htmldep(*, all_files: bool = False) -> QuartoHtmlDependency:
"""
Return an HTML dependency object consisting of files that are base dependencies; in
other words, the files that are always included in a Shinylive deployment.
"""
assets_dir = shinylive_assets_dir()

# First, get the list of base files.
base_files = shinylive_common_files()
base_files = shinylive_common_files(all_files=all_files)

# Next, categorize the base files into scripts, stylesheets, and resources.
scripts: list[str | HtmlDepItem] = []
Expand Down Expand Up @@ -208,7 +210,7 @@ def scripts_sort_fun(x: str | HtmlDepItem) -> int:
}


def shinylive_common_files() -> list[str]:
def shinylive_common_files(*, all_files: bool = False) -> list[str]:
"""
Return a list of files that are base dependencies; in other words, the files that are
always included in a Shinylive deployment.
Expand All @@ -224,6 +226,9 @@ def shinylive_common_files() -> list[str]:
dirs.remove("export_template")
elif rel_root == Path("shinylive"):
files.remove("examples.json")
# Remove webr folder as it is only needed for R support
if not all_files:
dirs.remove("webr")
elif rel_root == Path("shinylive/pyodide"):
dirs.remove("fonts")
files[:] = BASE_PYODIDE_FILES
Expand Down
6 changes: 5 additions & 1 deletion shinylive/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def verbose_print(*args: object) -> None:
f"Copying base Shinylive files from {assets_dir}/ to {destdir}/",
file=sys.stderr,
)
base_files = _deps.shinylive_common_files()

base_files = _deps.shinylive_common_files(
# Do not include r-only support files
all_files=False,
)
for file in base_files:
src_path = assets_dir / file
dest_path = destdir / Path(file)
Expand Down
14 changes: 12 additions & 2 deletions shinylive/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,18 @@ def assets(
default=None,
help="Directory where shinylive-sw.js is located, relative to the output directory.",
)
def base_deps(sw_dir: Optional[str]) -> None:
deps = _deps.shinylive_base_deps_htmldep(sw_dir)
# @click.option(
# "--all-files",
# is_flag=True,
# default=False,
# show_default=False,
# # help="Include all language dependencies, not just the ones needed for the application.",
# )
def base_deps(
sw_dir: Optional[str],
# all_files: Optional[bool]
) -> None:
deps = _deps.shinylive_base_deps_htmldep(sw_dir, all_files=True)
print(json.dumps(deps, indent=2))


Expand Down