* Add display impl, remove outputManage, print and console.log defaults to terminal
* Fixing tests
* Lint
* Erase unecessary code, add cuter CSS formating for errors, fix problems around REPL output
* Add fix to repl2 and lint
* lint
* Allow for list of display, fix elif to else
* Add better global option
* test work
* xfails
* (antocuni, mariana): let's try to start again with TDD methodology: write the minimum test and code for a simple display()
* (antocuni, mariana): this test works out of the box
* WIP: this test is broken, mariana is going to fix it
* add a failing test
* Add ability to deal with targets
* Add append arg and append tests
* Add multiple values to display
* Small adjustments to tests. I noticed I wasn;t running all at some point
* add display test
* Add console tests
* Add async tests
* Fix repl tests
* Fixing merging issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Address antocuni's review
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fixing more tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* linting
* Improve repl tests
* Change my test so codespell is hapy with it
* Test: change test_runtime_config to use json instead of toml to see if stops failing on CI
* kill this file: it is a merge artifact since it was renamed into test_py_config.py on the main branch
* Change test execution order and add async tests to async test file
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
As the title stays, the main goal of the branch is to kill the infamous runtimeLoaded global store and all the complications, problems and bugs caused by the fact that in many places we needed to ensure/wait that the global runtime was properly set before being able to execute code.
The core idea is that runtime is never a global object and that it's passed around explicitly, which means that when a function receives it, it is guaranteed to be initialized&ready.
This caused a bit of complications in pybutton.ts, pyinputbox.ts and pyrepl.ts, because they indirectly want to call runtime.run from connectedCallback, which is the only place where we cannot explicitly pass the runtime because it's automatically called by the browser.
But also, it is also a sign of a bad design, because it were entirely possible that connectedCallback was called before the runtime was ready, which probably caused many bugs, see e.g. #673 and #747.
The solution to is use dependency injection and create the class later on: so instead of having a global PyButton class which relies on a global runtime (whose state is uncertain) we have a make_PyButton function which takes a runtime and make a PyButton class which is tied to that specific runtime (whose state is certainly ready, because we call make_PyButton only when we know that the runtime is ready).
Similar for PyInputBox and PyRepl.
Other highlights: thanks to this, I could kill the also infamous runAfterRuntimeInitialized and a couple of smelly lines which used setTimeout to "wait" for the runtime.
While I was at it, I also called a lot of other stores which were completely unused and where probably leftovers from a past universe.
* Use only single copy() plugin to avoid race condition
* clean production def, better copy_target structure
* Restore '!process.env.ROLLUP_WATCH to production definition
Co-authored-by: Ted Patrick <tpatrick@anaconda.com>
* Hide py-config element
* display:none for all web components
* docs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add style tests for raw html and pyscript enabled html
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* test naming
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Upgrade and Pin Dependencies
* Removal all unused deps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* lock
* remove svelte-fa reference from the svg style.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add directly listing for releases
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add cache, fetch, retry logic to tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* run in parallel
* add pytest-xdist
* undo parallelism. Need to remove http server to enable.
* woops a extra space
* Pass flake8
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* spell fulfill
* use decorator for fetch if not in cache
* Fix --headed and limit to PlaywrightRequestError
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docs on cache
* CICD caching of conda on unstable builds
* fix config issues
* empty commit to trigger gh-actions
* restore build-unstable
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove http server, add parallel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* temp: Bypass zip runtime test and point to v0.21.3 on CDN
* suport for files in zip under /pyodide
* remove test-one
* self.http_server and remove content_type
* domcontentloaded w no timeout on base url + longer timeout on wait_for_pyscript
* Fixed#678
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* set default timeout to 60000
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* seamless --headed support
* add test-integration-parallel and default for GHActions
* simplify the code. Use http://fakeserver instead of localhost:8080 so that it's clearer that the browser is NOT hitting a real server, and use urllib to parse the url. Moreover, the special case for pyodide is no longer needed, it's automatically handled by the normal 'fakeserver' logic
* The page-routing logic is becoming too much complicated to stay as an inner function. Move it to its own class, and add some logic to workaround a limitation of playwright which just hangs if a Python exception is raised inside it
* no need to use a hash, we can use the url as the key
* re-implement the retry logic. The old @retry decorator was nice but a bit too over-engineered and most importantly failed silently in case of exceptions. This new approach is less powerful but since we want to retry only two times, simple is better than complex -- and in case of exception, the exception is actually raised
* improve logging
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Madhur Tandon <madhurtandon23@gmail.com>
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
This is a follow-up of PR #806 and it's a big step forward towards solving issue #763.
The basic idea is that at this stage I want to streamline the execution logic
and make it as linear and easy to read/understand as possible. The diff is
relatively big, but for the most part is just "shuffling code around".
Svelte stores:
the idea is to eventually kill of them, so that we can remove the dependency
on svelte but also to avoid relying on so much global state, which makes
things more complicated and error-prone (e.g., we have several issues related
to using runtime when it's not ready yet).
I killed addInitializer, addPostInitializer and the corresponding svelte
stores tada. They are no longer needed since the relevant code is called
directly from main.ts.
I started to kill the usage of the runtimeLoaded svelte store: instead of
relying on a global variable, I want to arrive at the point in which the
runtime is passed as a parameter in all places where it's needed: pyscript.ts
is now free of global state, but I couldn't kill it yet because it's used
heavily by base.ts and pyrepl.ts. I will do it in another PR.
Other misc changes:
I added sanity checks (and corresponding tests!) which complain if you specify
0 or multiple runtimes. Currently we support having one and only one, so there
is no point to pretend otherwise
I modified the messages displayed by the loader, to be more informative from
the user point of view.
This PR is the first step to improve and rationalize the life-cycle of a pyscript app along the lines of what I described in #763 .
It is not a complete solution, more PRs will follow.
Highlights:
- py-config is no longer a web component: the old code relied on PyConfig.connectedCallback to do some logic, but then if no <py-config> tag was present, we had to introduce a dummy one with the sole goal of activating the callback. Now the logic is much more linear.
- the new pyconfig.ts only contains the code which is needed to parse the config; I also moved some relevant code from utils.ts because it didn't really belong to it
- the old PyConfig class did much more than dealing with the config: in particular, it contained the code to initialize the env and the runtime. Now this logic has been moved directly into main.ts, inside the new PyScriptApp class. I plan to refactor the initialization code in further PRs
- the current code relies too much on global state and global variables, they are everywhere. This PR is a first step to solve the problem by introducing a PyScriptApp class, which will hold all the mutable state of the page. Currently only config is stored there, but eventually I will migrate more state to it, until we will have only one global singleton, globalApp
- thanks to what I described above, I could kill the appConfig svelte store: one less store to kill :).
* TOML Error Cases
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove traceback
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* any is a ts feature
* full eslint
* format and disable eslint for toml.js
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Madhur Tandon <madhurtandon23@gmail.com>
* simplify OutputCtxManager logging
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Minimium viable py-config default schema
* Add packages and paths to default
* Add in default for plugins
* Remove tests for values no longer in the default config
* Loading and Script evaluate with Promise.all
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Move to 'void script.evaluate();'
* chmod files to 644
* Add a test
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add unit tests for pyloader and pytitle
* Add more unit tests for pyrepl, pybox and pyinputbox
* Add more tests for pyscript and pyconfig
* White space
* Fix d3 tests and improve more examples test
* Update matplotlib test
* Add numpy to dependencies
* Address Madhur comments
* Update test name
* add toml support for configs with fast-toml
* fix package-lock.json and pin pyodide to 0.21.2
* use browser version of fast-toml
* disable eslint and add credits
* fix jest issues
* use type attribute for py-config
* refactor py-config to use toml
* switch from toml to json and add unit tests
* fix test for py-config
* fix integration test
* use flat structure for JSON
* allow merging configs
* replace arrays instead of concatenating them
* remove extra keys from inline config of integration test
* simplify array replacement logic
* allow config from src to be partial as well
* add comments to unit tests
* add unit test for setting config from both inline and src
* handle parse errors + validate config supplied
* separate functions for src and inline
* suggested improvements
* show error message in red on parser error
* fix eslint
* use resolveJsonModule as true
* use default config defined as a variable without import
* remove disable eslint comment
* remove import for covfefe.json as well
* metadata injection
* add support for schema + extra keys
* use schema_version
* Execute pys-on* events when triggered, not at load
Mimicing the behavior of Javascripts 'onLoad' event, we should
not be executing the use code at page-load time, only when
the event is triggered.
* Update examples to new syntax
* Fix merge issue
* Await running event handler code
* Restore pys-on* events with original behavior, deprecation warning
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* xfail toga example
* Add missing { (typo)
* Adjust callback chandling to make linter happy
* Change alpha to latest (#760)
* Don't create custom elements in main and fix various small issues on tests (#747)
* Create custom elements when the runtime finishes loading
* Remove xfails and fix repl integration test
* Fix commented ignore
* Address Antonio's comments
* Fix bad rebase
* Make ure to wait for repl to be in attached state before asserting content
* Move createCustomeElement up so it runs before we close the loader, xfail flaky d3 test
* Fix xfail
* [pre-commit.ci] pre-commit autoupdate (#762)
updates:
- [github.com/pre-commit/mirrors-eslint: v8.23.0 → v8.23.1](https://github.com/pre-commit/mirrors-eslint/compare/v8.23.0...v8.23.1)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* change documentation to point to latest instead of frozen alpha (#764)
* Toga example is xpass
* Correct 'xpass' to 'xfail' mark
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Peter W <34256109+pww217@users.noreply.github.com>
Co-authored-by: Fábio Rosado <fabiorosado@outlook.com>
* Create custom elements when the runtime finishes loading
* Remove xfails and fix repl integration test
* Fix commented ignore
* Address Antonio's comments
* Fix bad rebase
* Make ure to wait for repl to be in attached state before asserting content
* Move createCustomeElement up so it runs before we close the loader, xfail flaky d3 test
* Fix xfail
This PR tries to improve and rationalize what we log. Key points:
- introduce `logger.ts`: each file/component is encouraged to use the logger instead of writing directly to `console.*`
* the logger automatically prepend a prefix like `[py-config]`, `[py-env]` which make it easier to understand where a certain message is printed from
* it provide a central place where to add more features in the future. E.g., I can imagine having a config setting to completely silence the logs (not implemented yet)
- use the new loggers everywhere
- write to `.info()` instead of `.log()`. The idea is to keep `console.log` free, so that for the users it's easier to tell apart their own messages and the pyscript ones
- generally improve what we log. This is an endless exercise, but I tried to print more things which are useful to understand what's going on and in which order the various things are executed, and remove prints which were clearly debugging leftovers
* add integration test for py-config
* fix bug
* fix test
* remove indexURL altogether
* make jest happy
* fix create_proxy import
* check that py-config loads an older version
* add unit test
* suggested changes
* don't use /tmp because of bandit
* make runtime an object of Runtime class when it is just an object
* fix constructor
* remove explicit string type
* define default values out of pyodide runtime and use default config instead of initializing a DEFAULT_RUNTIME instance
Co-authored-by: Fabio Pliger <fabio.pliger@gmail.com>
* 585: Add a line to the makefile to run the examples on a python server with one line command
* Build exs and run server with previous makefile cmds
Co-authored-by: Todd Keech <tkeech1@hotmail.com>
Co-authored-by: mariana <marianameireles@protonmail.com>
* PyodideRuntime should be one of the runtimes
* subsume interpreter into runtime API
* fix eslint
* add comments
* move initializers, postInitializers, scriptsQueue, etc. to initialize() of Runtime Super Class
* modify comment for initialize
* small renaming
* change id to default
* fix pyscript.py import
* try adding tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add inlineDynamicImports option
* Make jest happy about ESM modules
* Attempt to make jest happy about pyodide
* point to version in accordance with node module being used
* fix base.ts
* fix tests
* fix indexURL path determination
* edit pyodide.asm.js as a part of setup process
* load runtime beforeAll tests
* add test for loading a package
* use only runPythonAsync underneath for pyodide
* import PyodideInterface type directly from pyodide
* add some comments
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philipp Rudiger <prudiger@anaconda.com>