Skip to content

Build wasn't detecting and setting the PyScript CDN URL. #64

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

Merged
merged 1 commit into from
Nov 20, 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
10 changes: 9 additions & 1 deletion src/psc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from psc.resources import Resources
from psc.resources import get_resources


templates = Jinja2Templates(directory=HERE / "templates")


Expand Down Expand Up @@ -68,6 +67,14 @@ async def example(request: Request) -> _TemplateResponse:
this_example = resources.examples[example_path]
root_path = "../../.."

# Set the pyscript URL to the CDN if we are being built from
# the ``psc build`` command.
user_agent = request.headers["user-agent"]
if user_agent == "testclient":
pyscript_url = "https://pyscript.net/latest/pyscript.js"
else:
pyscript_url = f"{root_path}/pyscript/pyscript.js"

return templates.TemplateResponse(
"example.jinja2",
dict(
Expand All @@ -77,6 +84,7 @@ async def example(request: Request) -> _TemplateResponse:
body=this_example.body,
request=request,
root_path=root_path,
pyscript_url=pyscript_url,
),
)

Expand Down
3 changes: 2 additions & 1 deletion src/psc/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def get_head_nodes(s: BeautifulSoup) -> str:

def is_local(test_path: Path = PYODIDE) -> bool:
"""Use a policy to decide local vs. CDN mode."""
return test_path.exists()
pyscript_file = test_path / "pyscript.js"
return pyscript_file.exists()


def get_body_content(s: BeautifulSoup, test_path: Path = PYODIDE) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/psc/templates/example.jinja2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "layout.jinja2" %}
{% block extra_head %}
<meta name="subtitle" content="{{ subtitle }}">
<script defer src="{{ root_path }}/pyscript/pyscript.js"></script>
<script defer src="{{ pyscript_url }}"></script>
{{ extra_head | safe }}{% endblock %}
{% block main %}
<main id="main_container" class="container">
Expand Down