8000 Deprecate `py-mount` Attribute (#1330) · ocdex/pyscript@d7ab177 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7ab177

Browse files
authored
Deprecate py-mount Attribute (pyscript#1330)
* Deprecate py-mount attribute, with comments as to when it was deprecated * Add changelog entry for deprecation * Fix 'unused' examples that used py-mount (handtrack and mario)
1 parent f4c6093 commit d7ab177

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Features
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
88
--------
99

10+
- The `py-mount` attribute on HTML elements has been deprecated, and will be removed in a future release.
11+
1012

1113
### <py-terminal>
1214
- Added a `docked` field and attribute for the `<py-terminal>` custom element, enabled by default when the terminal is in `auto` mode, and able to dock the terminal at the bottom of the page with auto scroll on new code execution.

docs/development/deprecation-cycle.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ showWarning(`
2828
</p>
2929
`, "html")
3030
```
31+
32+
## Deprecation History
33+
34+
This section tracks deprecations of specific features, both for historical record and to help the development team remember to actually remove deprecated features in future releases.
35+
36+
|Attribute/Object/Functionality|Deprecated In|Removed In|
37+
|-|-|-|
38+
|`py-mount` attribute | (Release following 2023.03.1) | -|

examples/handtrack/say_hello.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111
rel="stylesheet"
1212
href="https://pyscript.net/latest/pyscript.css"
1313
/>
14-
15-
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
14+
<script defer src="../../pyscriptjs/build/pyscript.js"></script>
15+
<!-- <script defer src="https://pyscript.net/latest/pyscript.js"></script> -->
1616
</head>
1717

1818
<body>
1919
<py-script>
20-
from js import handTrack, requestAnimationFrame
20+
from js import handTrack, requestAnimationFrame, console
2121
from pyodide import create_once_callable
2222
import asyncio
2323

24+
update_note = Element("update-note")
25+
canvas = Element("canvas")
26+
video = Element("myvideo")
2427
context = canvas.element.getContext("2d")
2528

2629
isVideo = False
@@ -33,7 +36,7 @@
3336
"scoreThreshold": 0.6, # confidence threshold for predictions.
3437
}
3538

36-
def toggle_video(evt):
39+
def toggle_video():
3740
global isVideo
3841
if (not isVideo):
3942
update_note.write("Starting video")
@@ -124,13 +127,11 @@
124127
>
125128
Next Image
126129
</button>
127-
<div id="update-note" py-mount class="updatenote mt10">
128-
loading model ..
129-
</div>
130+
<div id="update-note" class="updatenote mt10">loading model ..</div>
130131
</div>
131132
<div>
132133
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
133-
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
134+
<canvas id="canvas" class="border canvasbox"></canvas>
134135
</div>
135136
<script src="lib/handtrack.min.js"></script>
136137
</body>

examples/mario/play_mario.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
from pyodide import create_once_callable
4747
import asyncio
4848

49+
update_note = Element("update-note")
50+
canvas = Element("canvas")
51+
video = Element("myvideo")
4952
context = canvas.element.getContext("2d")
5053

10000
5154
isVideo = False
@@ -60,7 +63,7 @@
6063
"scoreThreshold": 0.6, # confidence threshold for predictions.
6164
}
6265

63-
def toggle_video(evt):
66+
def toggle_video():
6467
global isVideo
6568
player.jump()
6669

pyscriptjs/src/components/pyscript.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ export async function mountElements(interpreter: InterpreterClient) {
237237
const matches: NodeListOf<HTMLElement> = document.querySelectorAll('[py-mount]');
238238
logger.info(`py-mount: found ${matches.length} elements`);
239239

240+
if (matches.length > 0) {
241+
//last non-deprecated version: 2023.03.1
242+
const deprecationMessage =
243+
'The "py-mount" attribute is deprecated. Please add references to HTML Elements manually in your script.';
244+
createDeprecationWarning(deprecationMessage, 'py-mount');
245+
}
246+
240247
let source = '';
241248
for (const el of matches) {
242249
const mountName = el.getAttribute('py-mount') || el.id.split('-').join('_');

pyscriptjs/tests/integration/test_01_basic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,17 @@ def myfunc():
345345
btn.click()
346346
assert self.console.log.lines[-1] == "hello world!"
347347
assert self.console.error.lines == []
348+
349+
def test_py_mount_shows_deprecation_warning(self):
350+
# last non-deprecated version: 2023.03.1
351+
self.pyscript_run(
352+
"""
353+
<div id="foo" py-mount></div>
354+
"""
355+
)
356+
banner = self.page.locator(".alert-banner")
357+
expected_message = (
358+
'The "py-mount" attribute is deprecated. '
359+
+ "Please add references to HTML Elements manually in your script."
360+
)
361+
assert banner.inner_text() == expected_message

0 commit comments

Comments
 (0)
0