Introduce DeprecatedGlobal and show proper warnings (#1014)

* kill the PyScript class and the weird pyscript instance; from the user point of view its functionalities are still available as pyscript.*, but pyscript is not the module, not the instance of PyScript

* simplify the code in _set_version_info, while I'm at it

* start to implement DeprecatedGlobal

* DeprecatedGlobal.__getattr__

* don't show the same warning twice

* DeprecatedGlobal.__call__

* make it possible to specify a different warning message for every global

* WIP: carefully use DeprecatedGlobal to show reasonable warning messages depending on which name you are accessing to. More names to follow

* deprecate more names

* deprecate private names

* depreacte direct usage of console and document

* deprecate the PyScript class

* use a better error message

* fix test_pyscript.py

* introduce a __repr__ for DeprecatedGlobal

* add an helper to ensure that we don't show any error or warning on the page

* WIP: ensure that examples don't use depreacted features. Many tests are failing

* don't deprecate Element

* don't use the global micropip to install packages, else we trigger a warning

* use a better error message for micropip

* fix test_todo_pylist to avoid using deprecated globals

* fix test_webgl_raycaster

* fix tests

* make HTML globally available

* add MIME_RENDERERS and MIME_METHODS

* fix the typing of Micropip, thanks to @FabioRosado
This commit is contained in:
Antonio Cuni
2022-12-06 14:31:57 +01:00
committed by GitHub
parent 94f2ac6204
commit e8318a98f0
12 changed files with 407 additions and 115 deletions

View File

@@ -2,7 +2,8 @@ from .support import PyScriptTest
# Source code of a simple plugin that creates a Custom Element for testing purposes
CE_PLUGIN_CODE = """
from pyscript import Plugin, console
from pyscript import Plugin
from js import console
plugin = Plugin('py-upper')
@@ -20,7 +21,8 @@ class Upper:
# Source of a plugin hooks into the PyScript App lifecycle events
HOOKS_PLUGIN_CODE = """
from pyscript import Plugin, console
from pyscript import Plugin
from js import console
class TestLogger(Plugin):
def configure(self, config):
@@ -44,7 +46,8 @@ plugin = TestLogger()
# Source of a script that doesn't call define a `plugin` attribute
NO_PLUGIN_CODE = """
from pyscript import Plugin, console
from pyscript import Plugin
from js import console
class TestLogger(Plugin):
pass
@@ -52,7 +55,8 @@ class TestLogger(Plugin):
# Source code of a simple plugin that creates a Custom Element for testing purposes
CODE_CE_PLUGIN_BAD_RETURNS = """
from pyscript import Plugin, console
from pyscript import Plugin
from js import console
plugin = Plugin('py-broken')