mirror of
https://github.com/pyscript/pyscript.git
synced 2026-03-26 17:00:13 -04:00
Updated requirements (#2461)
* Added a manual test for t-strings * Updating requirements to allow t-strings
This commit is contained in:
committed by
GitHub
parent
0ca6d42bf7
commit
1c6be7e84a
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@@ -19,9 +19,6 @@ on:
|
||||
jobs:
|
||||
BuildAndTest:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MINICONDA_PYTHON_VERSION: py38
|
||||
MINICONDA_VERSION: 4.11.0
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
@@ -36,6 +33,12 @@ jobs:
|
||||
- name: git log
|
||||
run: git log --graph -3
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.14
|
||||
cache: "pip"
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
@@ -54,12 +57,9 @@ jobs:
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: setup Miniconda
|
||||
uses: conda-incubator/setup-miniconda@v3
|
||||
|
||||
- name: Create and activate virtual environment
|
||||
run: |
|
||||
python3 -m venv test_venv
|
||||
python3.14 -m venv test_venv
|
||||
source test_venv/bin/activate
|
||||
echo PATH=$PATH >> $GITHUB_ENV
|
||||
echo VIRTUAL_ENV=$VIRTUAL_ENV >> $GITHUB_ENV
|
||||
|
||||
@@ -4,6 +4,9 @@ ci:
|
||||
#skip: [eslint]
|
||||
autoupdate_schedule: monthly
|
||||
|
||||
default_language_version:
|
||||
python: python3.14
|
||||
|
||||
default_stages: [pre-commit]
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
@@ -24,14 +27,14 @@ repos:
|
||||
- id: trailing-whitespace
|
||||
|
||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||
rev: 25.9.0
|
||||
rev: 26.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
exclude: core/tests
|
||||
args: ["-l", "88", "--skip-string-normalization"]
|
||||
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v2.4.1
|
||||
rev: v2.4.2
|
||||
hooks:
|
||||
- id: codespell # See 'pyproject.toml' for args
|
||||
exclude: fs\.py|\.js\.map$
|
||||
@@ -39,7 +42,7 @@ repos:
|
||||
- tomli
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.13.3
|
||||
rev: v0.15.5
|
||||
hooks:
|
||||
- id: ruff
|
||||
exclude: core/tests
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -205,7 +205,6 @@ from js import console
|
||||
from pyscript import document, Event # noqa: F401
|
||||
from pyscript.ffi import create_proxy, is_none
|
||||
|
||||
|
||||
# Utility functions for finding and wrapping DOM elements.
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
11
core/tests/manual/t-strings.html
Normal file
11
core/tests/manual/t-strings.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>t-strings</title>
|
||||
<link rel="stylesheet" href="../../dist/core.css">
|
||||
<script type="module" src="../../dist/core.js"></script>
|
||||
<script type="mpy" src="t-strings.py"></script>
|
||||
</head>
|
||||
</html>
|
||||
69
core/tests/manual/t-strings.py
Normal file
69
core/tests/manual/t-strings.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from pyscript import window, document
|
||||
|
||||
SHOW_COMMENT = window.NodeFilter.SHOW_COMMENT
|
||||
|
||||
already_parsed = {}
|
||||
|
||||
# accepts a t-string template, returns a JS DOM node 🤯
|
||||
def domdom(template):
|
||||
strings = template.strings
|
||||
if strings in already_parsed:
|
||||
content = already_parsed[strings].cloneNode(True)
|
||||
else:
|
||||
interpolations = template.interpolations
|
||||
el = document.createElement('template')
|
||||
|
||||
# create unique content that can be understood by the parser
|
||||
el.innerHTML = '<!--🐍-->'.join(strings)
|
||||
content = el.content
|
||||
already_parsed[strings] = el.content
|
||||
|
||||
tw = document.createTreeWalker(content, SHOW_COMMENT)
|
||||
i = 0
|
||||
while True :
|
||||
node = tw.nextNode()
|
||||
if node is None: break
|
||||
if node.data == '🐍':
|
||||
node.replaceWith(interpolations[i].value.node)
|
||||
i += 1
|
||||
|
||||
return content
|
||||
|
||||
|
||||
class Text:
|
||||
def __init__(self, value, node=None):
|
||||
self._value = str(value)
|
||||
self.node = document.createTextNode(self._value) if node is None else node
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = str(value)
|
||||
self.node.data = self._value
|
||||
|
||||
def __str__(self):
|
||||
return f'#text: {self._value}'
|
||||
|
||||
# just to demo JS string casting
|
||||
def toString(self):
|
||||
return str(self)
|
||||
|
||||
|
||||
# create a new text and leak it for demo purposes
|
||||
content = Text('Hello World!')
|
||||
window.content = content
|
||||
|
||||
print(f"<div>{content}</div>")
|
||||
|
||||
# see domdom in action 🥳
|
||||
document.body.append(
|
||||
domdom(
|
||||
t"<div>{content}</div>"
|
||||
),
|
||||
# domdom(
|
||||
# t"<div>{content}</div>"
|
||||
# )
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
black==24.10.0
|
||||
pre-commit==3.7.1
|
||||
python-minifier==3.1.0
|
||||
setuptools==72.1.0
|
||||
black==26.1.0
|
||||
pre-commit==4.5.1
|
||||
python-minifier==3.2.0
|
||||
setuptools==82.0.0
|
||||
|
||||
Reference in New Issue
Block a user