Deprecate py-mount Attribute (#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)
This commit is contained in:
Jeff Glass
2023-03-29 10:49:31 -05:00
committed by GitHub
parent f4c6093c47
commit d7ab177cc5
6 changed files with 44 additions and 9 deletions

View File

@@ -7,6 +7,8 @@
Features Features
-------- --------
- The `py-mount` attribute on HTML elements has been deprecated, and will be removed in a future release.
### <py-terminal> ### <py-terminal>
- 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. - 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.

View File

@@ -28,3 +28,11 @@ showWarning(`
</p> </p>
`, "html") `, "html")
``` ```
## Deprecation History
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.
|Attribute/Object/Functionality|Deprecated In|Removed In|
|-|-|-|
|`py-mount` attribute | (Release following 2023.03.1) | -|

View File

@@ -11,16 +11,19 @@
rel="stylesheet" rel="stylesheet"
href="https://pyscript.net/latest/pyscript.css" href="https://pyscript.net/latest/pyscript.css"
/> />
<script defer src="../../pyscriptjs/build/pyscript.js"></script>
<script defer src="https://pyscript.net/latest/pyscript.js"></script> <!-- <script defer src="https://pyscript.net/latest/pyscript.js"></script> -->
</head> </head>
<body> <body>
<py-script> <py-script>
from js import handTrack, requestAnimationFrame from js import handTrack, requestAnimationFrame, console
from pyodide import create_once_callable from pyodide import create_once_callable
import asyncio import asyncio
update_note = Element("update-note")
canvas = Element("canvas")
video = Element("myvideo")
context = canvas.element.getContext("2d") context = canvas.element.getContext("2d")
isVideo = False isVideo = False
@@ -33,7 +36,7 @@
"scoreThreshold": 0.6, # confidence threshold for predictions. "scoreThreshold": 0.6, # confidence threshold for predictions.
} }
def toggle_video(evt): def toggle_video():
global isVideo global isVideo
if (not isVideo): if (not isVideo):
update_note.write("Starting video") update_note.write("Starting video")
@@ -124,13 +127,11 @@
> >
Next Image Next Image
</button> </button>
<div id="update-note" py-mount class="updatenote mt10"> <div id="update-note" class="updatenote mt10">loading model ..</div>
loading model ..
</div>
</div> </div>
<div> <div>
<video autoplay="autoplay" id="myvideo" py-mount="video"></video> <video autoplay="autoplay" id="myvideo" py-mount="video"></video>
<canvas id="canvas" py-mount class="border canvasbox"></canvas> <canvas id="canvas" class="border canvasbox"></canvas>
</div> </div>
<script src="lib/handtrack.min.js"></script> <script src="lib/handtrack.min.js"></script>
</body> </body>

View File

@@ -46,6 +46,9 @@
from pyodide import create_once_callable from pyodide import create_once_callable
import asyncio import asyncio
update_note = Element("update-note")
canvas = Element("canvas")
video = Element("myvideo")
context = canvas.element.getContext("2d") context = canvas.element.getContext("2d")
isVideo = False isVideo = False
@@ -60,7 +63,7 @@
"scoreThreshold": 0.6, # confidence threshold for predictions. "scoreThreshold": 0.6, # confidence threshold for predictions.
} }
def toggle_video(evt): def toggle_video():
global isVideo global isVideo
player.jump() player.jump()

View File

@@ -237,6 +237,13 @@ export async function mountElements(interpreter: InterpreterClient) {
const matches: NodeListOf<HTMLElement> = document.querySelectorAll('[py-mount]'); const matches: NodeListOf<HTMLElement> = document.querySelectorAll('[py-mount]');
logger.info(`py-mount: found ${matches.length} elements`); logger.info(`py-mount: found ${matches.length} elements`);
if (matches.length > 0) {
//last non-deprecated version: 2023.03.1
const deprecationMessage =
'The "py-mount" attribute is deprecated. Please add references to HTML Elements manually in your script.';
createDeprecationWarning(deprecationMessage, 'py-mount');
}
let source = ''; let source = '';
for (const el of matches) { for (const el of matches) {
const mountName = el.getAttribute('py-mount') || el.id.split('-').join('_'); const mountName = el.getAttribute('py-mount') || el.id.split('-').join('_');

View File

@@ -345,3 +345,17 @@ class TestBasic(PyScriptTest):
btn.click() btn.click()
assert self.console.log.lines[-1] == "hello world!" assert self.console.log.lines[-1] == "hello world!"
assert self.console.error.lines == [] assert self.console.error.lines == []
def test_py_mount_shows_deprecation_warning(self):
# last non-deprecated version: 2023.03.1
self.pyscript_run(
"""
<div id="foo" py-mount></div>
"""
)
banner = self.page.locator(".alert-banner")
expected_message = (
'The "py-mount" attribute is deprecated. '
+ "Please add references to HTML Elements manually in your script."
)
assert banner.inner_text() == expected_message