Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
3e10127
Update the build logic to support toolkit config and pyscript.toml me…
kavi2du Aug 4, 2025
107f1e6
Added functions to gather backend configuration files
caydnn Aug 11, 2025
eed7ec4
If statement logic fix
caydnn Aug 11, 2025
07c14f3
Added _process_wheel function from PR#1285
caydnn Aug 4, 2025
251914f
Additional _process_wheel content from PR#1285
caydnn Aug 4, 2025
ac2a30a
Added _merge_insert_content and _write_inserts functions from PR#1285
caydnn Aug 4, 2025
2ad86c2
Add phase 3 insert injection support with HTML & CSS markers
kavi2du Aug 11, 2025
48b47ad
More specific configuration file exception and edits to pyscript.toml…
caydnn Aug 18, 2025
2504757
Address review comments in _write_inserts and wheel processing
kavi2du Aug 18, 2025
1a306c1
Address review comments
kavi2du Aug 19, 2025
184e428
Addressing nesting issue in gather_backend_config
caydnn Aug 25, 2025
6ac4712
function name and visibility changes
caydnn Aug 26, 2025
b5eaa82
write_inserts dict type annotation
caydnn Aug 26, 2025
99b3aed
pattern defined outside of loop
caydnn Aug 26, 2025
7790ceb
remove continues from loop in _process_wheel
caydnn Aug 26, 2025
d1f9f74
find pyscript.toml logic fix
caydnn Aug 26, 2025
a520633
Address review comments
kavi2du Aug 26, 2025
920a95f
Minor code update
kavi2du Aug 26, 2025
6c1aa2a
Optimise write_inserts by pre-compiling regex patterns outside the loop
kavi2du Aug 26, 2025
c882bee
Minor typo fix
kavi2du Aug 26, 2025
19e673b
Remove continues in process_wheel
kavi2du Sep 2, 2025
a618536
remove continue from process_wheel
caydnn Sep 2, 2025
e295e86
fix indentation issue with if-elif condition
caydnn Sep 2, 2025
7e664a1
fix conditional logic error and update to match new insert content na…
caydnn Sep 2, 2025
b1c06b9
removed unused line
caydnn Sep 2, 2025
0130acb
remove reference to source
caydnn Sep 2, 2025
f3e37c1
Functionality to insert pyscript version in index.html
caydnn Sep 3, 2025
6416bd1
Update /static handling
kavi2du Sep 8, 2025
0029857
Update the docstring and the inline comments of the process_wheel method
kavi2du Sep 8, 2025
6a08c52
Apply one-arg-per-line style to long function defs
kavi2du Sep 9, 2025
bd1ea40
Apply one-arg-per-line style to long function defs
kavi2du Sep 9, 2025
7c8cb8f
Change pyscript insertion to non-destructive
caydnn Sep 15, 2025
3905608
Simplify process_wheel by removing redundant guard and fix .lower() call
kavi2du Sep 15, 2025
36ec34b
Remove duplicate CSS headers
kavi2du Sep 15, 2025
e03a754
Simplified if-else failure logic in extract_backend_config
caydnn Sep 16, 2025
5ad56fe
Change failures to warnings in write_pryscript_version for backwards …
caydnn Sep 16, 2025
58a0da0
enforce one-arg-per-line formatting
caydnn Sep 16, 2025
926d288
Minor edits
caydnn Sep 16, 2025
482a169
Further simplify nested if-else logic within extract_backend_config()
caydnn Sep 16, 2025
0a9f76c
remove unused static_path variable
caydnn Sep 16, 2025
3cfbfc7
Unify wheel insert handling and escape slot regex
kavi2du Sep 17, 2025
a124d40
Indent insertion content and markers within write_inserts()
caydnn Sep 17, 2025
1e8814c
Apply matching indentation to write_pyscript_version
caydnn Sep 17, 2025
5689006
Update insert handling for `filename.filetype~insert` file name conve…
caydnn Sep 19, 2025
0117229
Minor update in process_wheel docstring
kavi2du Sep 20, 2025
30bf837
Remove pyscript.toml from conftest.py
caydnn Sep 20, 2025
84cd196
initial mock pyscript.toml extraction from wheels and remove template…
caydnn Sep 20, 2025
7bd1481
Define HTML/CSS banners as module level constants
kavi2du Sep 22, 2025
af516a3
convert write_pyscript_version to_write_pyscript_insert
caydnn Sep 22, 2025
3c04733
Merge branch 'briefcase-build-logic-update' of https://github.com/kav…
caydnn Sep 22, 2025
1c79f9b
Use split(~) with validation for insert filenames in process_wheel
kavi2du Sep 22, 2025
181523e
Update fixtures with new insert markers and config handling in confte…
kavi2du Sep 25, 2025
8b3a4b2
Conftest.py css markers moved below sentinel banner
caydnn Sep 28, 2025
fa2eb1e
check pyscript insertions in index.html for test_build_app
caydnn Sep 29, 2025
c9cfe8c
Add test_build_app_no_config
caydnn Sep 29, 2025
4bfea45
test_build_app_multiple_config
caydnn Sep 29, 2025
550e45f
test_build_app_config_no_backend
caydnn Sep 29, 2025
e57819d
no pyscript.toml supplies basic config and test_build_app_no_wheel_py…
caydnn Sep 29, 2025
f570375
Invalid pyscript.toml check and test_build_app_invalid_wheel_pyscript…
caydnn Sep 29, 2025
032b18c
Remove pyscript.toml checks in test_app_package_fail and test_depende…
caydnn Sep 29, 2025
e2a9a38
Update test_build__process_wheel.py
kavi2du Oct 1, 2025
eb71d78
Expand _process_wheel test coverage
kavi2du Oct 1, 2025
0e4f0fb
Update src/briefcase/platforms/web/static.py
caydnn Oct 1, 2025
e684693
change _write_pyscript_insert to _append_pyscript_insert
caydnn Oct 1, 2025
422b0af
changing insert tags to lower case
caydnn Oct 1, 2025
8f48e87
change CSS tag in legacy handling to lower case
caydnn Oct 1, 2025
faed786
Expand _process_wheel test coverage
kavi2du Oct 1, 2025
00d1dbe
Merge branch 'main' into briefcase-build-logic-update
kavi2du Oct 1, 2025
930bf4f
Address review comments
kavi2du Oct 1, 2025
e71d946
Address review comments
kavi2du Oct 1, 2025
46d4436
Minor fix in build_app()
kavi2du Oct 1, 2025
b3b9c33
Create test_build_write_inserts.py
kavi2du Oct 1, 2025
344d843
Update _process_wheel test coverage
kavi2du Oct 2, 2025
78acd8c
Update non UTF8 wheel tests to expect UnicodeDecodeError
kavi2du Oct 2, 2025
973b426
Minor comment tweak
kavi2du Oct 2, 2025
5563047
Expand write_inserts() test coverage
kavi2du Oct 2, 2025
4a21802
Expand write_inserts() test coverage
kavi2du Oct 2, 2025
477ea2e
fixes to css checks in test_build.py
caydnn Oct 3, 2025
5c698cb
test_build_app_config_backend_warning
caydnn Oct 3, 2025
79239a2
add enconding to readtext calls
caydnn Oct 3, 2025
9170b47
remove pyscript.toml from test_package_app
caydnn Oct 3, 2025
c20e55b
move extract_backend_config test to own file
caydnn Oct 3, 2025
e6ad0cc
Update to pyscript version collection and added test_extract_backend_…
caydnn Oct 3, 2025
7d5949e
update test_extract_backend_config_no_config
caydnn Oct 3, 2025
8883494
update test_extract_backend_config_multiple_config
caydnn Oct 3, 2025
a924361
update test_extract_backend_config_no_backend
caydnn Oct 3, 2025
699b463
test_extract_backend_config_no_pyscript_toml and test_extract_backen…
caydnn Oct 4, 2025
e74ba4a
test_extract_backend_config_invalid_wheel_pyscript_toml
caydnn Oct 4, 2025
6b864a7
Add change rst
caydnn Oct 4, 2025
c361363
fix to preserving indentation
caydnn Oct 4, 2025
2cea15d
add boolean to parameters for test_handle_insert_skip_dir_entries(
caydnn Oct 4, 2025
c8bc019
missing pre-commits
caydnn Oct 4, 2025
25b887c
update exception for 3.14 compatibility in extract_backend_config
caydnn Oct 4, 2025
06a4df7
Add output assertion to test_extract_backend_config_no_pyscript_toml
caydnn Oct 4, 2025
ce49a34
missing pre-commits
caydnn Oct 4, 2025
39a9ad3
Minor cleanups and fixes.
freakboy3742 Oct 8, 2025
b487898
add body-python content to _append_pyscript_insert
caydnn Oct 8, 2025
b8b0ccb
minor fix to test_build.py
caydnn Oct 8, 2025
604b763
Minor comment update
kavi2du Oct 9, 2025
042b0e3
Create test_build__handle_legacy_css.py
kavi2du Oct 9, 2025
bbf4afd
Create test_build__handle_insert.py
kavi2du Oct 9, 2025
bac1000
Address review comments
kavi2du Oct 9, 2025
7bf50d0
fixes to tests and _handle_legacy)css
caydnn Oct 11, 2025
48fad39
fixes for test_build__handle_legacy_css.py
caydnn Oct 11, 2025
89b7aec
remove monkeypatch from test_build__handle_insert.py
caydnn Oct 11, 2025
cab03a9
add quotes to pyscript body script
caydnn Oct 11, 2025
2214b3c
change Path for PurePosixPath for safety
caydnn Oct 14, 2025
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
1 change: 1 addition & 0 deletions changes/2442.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Briefcase’s build system to support GUI toolkit-owned pyscript/backend configuration and insertion content.
438 changes: 377 additions & 61 deletions src/briefcase/platforms/web/static.py

Large diffs are not rendered by default.

44 changes: 28 additions & 16 deletions tests/platforms/web/static/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,45 @@ def first_app_generated(first_app_config, tmp_path):
""",
)

# Create index.html
create_file(bundle_path / "www/index.html", "<html></html>")

# Create the initial pyscript.toml
# Create index.html with insert markers
create_file(
bundle_path / "www/pyscript.toml",
"""
existing-key-1 = "value-1"
existing-key-2 = 2
bundle_path / "www/index.html",
"""<!doctype html>
<html>
<head>
<!--@@ head:start @@-->
<!--@@ head:end @@-->
<!--@@ head-python:start @@-->
<!--@@ head-python:end @@-->
</head>
<body>
<div id="briefcase-splash"></div>

<!--@@ body-start:start @@-->
<!--@@ body-start:end @@-->

<!--@@ body-python:start @@-->
<!--@@ body-python:end @@-->

<!--@@ body-end:start @@-->
<!--@@ body-end:end @@-->
</body>
</html>
""",
)

# Create the initial briefcase.css
# Create the initial briefcase.css with CSS insert markers
create_file(
bundle_path / "www/static/css/briefcase.css",
"""
#pyconsole {
display: None;
}
/*******************************************************************
******************** Wheel contributed styles ********************/
******************** Wheel contributed styles ********************/
/*@@ css:start @@*/
/*@@ css:end @@*/

""",
)

Expand All @@ -50,12 +68,6 @@ def first_app_generated(first_app_config, tmp_path):
def first_app_built(first_app_generated, tmp_path):
bundle_path = tmp_path / "base_path/build/first-app/web/static"

# Create pyscript.toml
create_file(
bundle_path / "www/pyscript.toml",
'packages = ["dummy-1.2.3-py3-none-all.whl"]',
)

# Create an app wheel
create_wheel(bundle_path / "www/static/wheels")

Expand Down
188 changes: 103 additions & 85 deletions tests/platforms/web/static/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from briefcase.integrations.subprocess import Subprocess
from briefcase.platforms.web.static import StaticWebBuildCommand

from ....utils import create_file, create_wheel
from ....utils import create_wheel


@pytest.fixture
Expand Down Expand Up @@ -47,6 +47,22 @@ def mock_run(*args, **kwargs):
"first_app",
extra_content=[
("dependency/static/style.css", "span { margin: 10px; }\n"),
(
"dependency/deploy/config.toml",
"""
implementation = "pyscript"

[pyscript]
version = "2024.11.1"
""",
),
(
"dependency/deploy/pyscript.toml",
"""
existing-key-1 = "value-1"
existing-key-2 = 2
""",
),
],
)
elif args[0][5] == "pip":
Expand Down Expand Up @@ -132,6 +148,60 @@ def mock_run(*args, **kwargs):
],
}

# index.html has insertions
with (bundle_path / "www/index.html").open(encoding="utf-8") as f:
assert (
f.read()
== "\n".join(
[
"<!doctype html>",
"<html>",
" <head>",
" <!--@@ head:start @@-->",
" <!--@@ head:end @@-->",
" <!--@@ head-python:start @@-->",
" <!--------------------------------------------------",
" * briefcase",
" -------------------------------------------------->",
' <script type="module">',
" // Hide the splash screen when the page is ready.",
' import { hooks } from "https://pyscript.net/releases/2024.11.1/core.js";',
" hooks.main.onReady.add(() => {",
' document.getElementById("briefcase-splash").classList.add("hidden");',
" });",
" </script>",
"",
' <link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css">',
' <script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script>',
" <!--@@ head-python:end @@-->",
" </head>",
" <body>",
' <div id="briefcase-splash"></div>',
"",
" <!--@@ body-start:start @@-->",
" <!--@@ body-start:end @@-->",
"",
" <!--@@ body-python:start @@-->",
" <!--------------------------------------------------",
" * briefcase",
" -------------------------------------------------->",
' <script type="py" async="false" config="pyscript.toml">',
" import runpy",
" result = runpy.run_module(",
' "first-app", run_name="__main__", alter_sys=True',
" )",
" </script>",
" <!--@@ body-python:end @@-->",
"",
" <!--@@ body-end:start @@-->",
" <!--@@ body-end:end @@-->",
" </body>",
"</html>",
]
)
+ "\n"
)

# briefcase.css has been appended
with (bundle_path / "www/static/css/briefcase.css").open(encoding="utf-8") as f:
assert (
Expand All @@ -143,25 +213,24 @@ def mock_run(*args, **kwargs):
" display: None;",
"}",
"/*******************************************************************",
" ******************** Wheel contributed styles ********************/",
"",
"/*******************************************************",
" * dependency 1.2.3::style.css",
" *******************************************************/",
"",
"******************** Wheel contributed styles ********************/",
"/*@@ css:start @@*/",
"/**************************************************",
" * dependency 1.2.3 (legacy static CSS: style.css)",
" *************************************************/",
"div { margin: 10px; }",
"",
"/*******************************************************",
" * first_app 1.2.3::style.css",
" *******************************************************/",
"",
"/**************************************************",
" * first_app 1.2.3 (legacy static CSS: style.css)",
" *************************************************/",
"span { margin: 10px; }",
"",
"/*******************************************************",
" * other 1.2.3::style.css",
" *******************************************************/",
"",
"/**************************************************",
" * other 1.2.3 (legacy static CSS: style.css)",
" *************************************************/",
"div { padding: 10px; }",
"/*@@ css:end @@*/",
"",
]
)
+ "\n"
Expand Down Expand Up @@ -195,6 +264,12 @@ def test_build_app_custom_pyscript_toml(build_command, first_app_generated, tmp_
bundle_path / "www/static/wheels"
)

# Mock extracting pyscript.toml from a wheel.
build_command.extract_pyscript_config = lambda _: (
{"existing-key-1": "value-1", "existing-key-2": 2},
"2024.11.1",
)

# Build the web app.
build_command.build_app(first_app_generated)

Expand All @@ -212,56 +287,6 @@ def test_build_app_custom_pyscript_toml(build_command, first_app_generated, tmp_
}


def test_build_app_no_template_pyscript_toml(
build_command, first_app_generated, tmp_path
):
"""An app whose template doesn't provide pyscript.toml gets a basic config."""
# Remove the templated pyscript.toml
bundle_path = tmp_path / "base_path/build/first-app/web/static"
(bundle_path / "www/pyscript.toml").unlink()

# Mock the side effect of invoking shutil
build_command.tools.shutil.rmtree.side_effect = lambda *args: shutil.rmtree(
bundle_path / "www/static/wheels"
)

# Build the web app.
build_command.build_app(first_app_generated)

# Pyscript.toml has been written with only the packages content
with (bundle_path / "www/pyscript.toml").open("rb") as f:
assert tomllib.load(f) == {
"packages": [],
}


def test_build_app_invalid_template_pyscript_toml(
build_command, first_app_generated, tmp_path
):
"""An app with an invalid pyscript.toml raises an error."""
# Re-write an invalid templated pyscript.toml
bundle_path = tmp_path / "base_path/build/first-app/web/static"
(bundle_path / "www/pyscript.toml").unlink()
create_file(
bundle_path / "www/pyscript.toml",
"""
This is not valid toml.
""",
)

# Mock the side effect of invoking shutil
build_command.tools.shutil.rmtree.side_effect = lambda *args: shutil.rmtree(
bundle_path / "www/static/wheels"
)

# Building the web app raises an error
with pytest.raises(
BriefcaseConfigError,
match=r"Briefcase configuration error: pyscript.toml content isn't valid TOML: Expected",
):
build_command.build_app(first_app_generated)


def test_build_app_invalid_extra_pyscript_toml_content(
build_command, first_app_generated, tmp_path
):
Expand Down Expand Up @@ -370,6 +395,12 @@ def mock_run(*args, **kwargs):
bundle_path / "www/static/wheels"
)

# Mock extracting pyscript.toml from a wheel.
build_command.extract_pyscript_config = lambda _: (
{"existing-key-1": "value-1", "existing-key-2": 2},
"2024.11.1",
)

# Build the web app.
build_command.build_app(first_app_generated)

Expand Down Expand Up @@ -436,13 +467,14 @@ def mock_run(*args, **kwargs):
" display: None;",
"}",
"/*******************************************************************",
" ******************** Wheel contributed styles ********************/",
"",
"/*******************************************************",
" * first_app 1.2.3::style.css",
" *******************************************************/",
"",
"******************** Wheel contributed styles ********************/",
"/*@@ css:start @@*/",
"/**************************************************",
" * first_app 1.2.3 (legacy static CSS: style.css)",
" *************************************************/",
"span { margin: 10px; }",
"/*@@ css:end @@*/",
"",
]
)
+ "\n"
Expand Down Expand Up @@ -499,13 +531,6 @@ def test_app_package_fail(build_command, first_app_generated, tmp_path):
# Wheels folder still exists
assert (bundle_path / "www/static/wheels").is_dir()

# Pyscript.toml content has not changed
with (bundle_path / "www/pyscript.toml").open("rb") as f:
assert tomllib.load(f) == {
"existing-key-1": "value-1",
"existing-key-2": 2,
}


def test_dependency_fail(build_command, first_app_generated, tmp_path):
"""If dependencies can't be downloaded, an error is raised."""
Expand Down Expand Up @@ -574,10 +599,3 @@ def test_dependency_fail(build_command, first_app_generated, tmp_path):

# Wheels folder still exists
assert (bundle_path / "www/static/wheels").is_dir()

# Pyscript.toml content has not changed
with (bundle_path / "www/pyscript.toml").open("rb") as f:
assert tomllib.load(f) == {
"existing-key-1": "value-1",
"existing-key-2": 2,
}
Loading