* removed unnecessary getAttribute
* removed unnecessary shadow and ShadowDOM in general, as it was never used
* dropped redundant constructor
* removed unnecessary usage of the label element
* fixed redundant always-same buttons IDs
* Unvendor toml package
* Fix many ESlint errors
For mysterious reasons, these errors appear on my branch #1262 even
though they are not related to changes there. The eslint config seems
a bit unstable.
Anyways this fixes them.
* Put back Record
* Fix typescript compilation
* Fix lints
* Try @iarna/toml instead
* Fix import
* Use @ltd/j-toml
* Update test
* Use toml-j0.4
* Some changes
* Fix toml import
* Try adding eslint gha job
* Add forgotten checkout action
* Force CI to run
* Blah
* Fix
* Revert changes to github workflow
* Fix lints
* wget toml-j0.4 type definitions
* Add toml-j types workaround to eslint workflow
* Apply formatter
* Use @hoodmane/toml-j0.4
* Import from @hoodmane/toml-j0.4
* split interpreter class
* add new files
* add newlines
* disable eslint for run
* remove usage of interpreter from unit test
* delete fakeinterpreter class
* fix unit tests
* add comments
* remove interpreter.ts and pyodide.ts files
* suggested changes
* Improves repl id output
* Fix tests for new REPL output ids
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add new REPL tests
* Pre commit linting
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove mistake
* Fixing tests that i didn't notice were broken?
* [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>
* Revert to runPython instead of await runPythonAsync
* "Implicit Coroutines" are no longer permitted in py-script tags
* Tests added for the above
* xfail test_importmap (See #938)
Major highlights:
1. Merge&simplify base.ts and pyrepl.ts; kill base.ts
2. improve and extente the py-repl integration tests
3. Reorder the code in pyrepl.ts. This part of the PR doesn't change much of the concrete logic: it's just a sequence of renaming variables, moving code around, group code into functions, killing code which is no longer needed. But the end result is much better and nicer to read, IMHO.
Minor highlights:
1. py-repl now uses the new logic in pyexec.ts to run the code
2. after PR Add display impl, rm outputManage, print and console.log default to browser console #749 py-repl no longer displayed the result of the last evaluated expression (e.g. if you typed 42 and run it, it displayed nothing). This PR re-introduces this behavior, which is what you would expect by a REPL.
3. improve the pytest --dev option: now it implies --no-fake-server so that sourcemaps works automatically
4. improve the names of the CSS classes to be more consistent
5. kill pyrepl.test.ts: the old tests didn't check anything useful, this style of unit test doesn't really add much value if you have good integration tests (which now we have) and trying to revive them was not worth the hassle
Yet another refactoring to untangle the old mess.
Highlights:
base.ts, pyscript.ts and pyrepl.ts were a tangled mess of code, in which each of them interacted with the others in non-obvious ways. Now PyScript is no longer a subclass of BaseEvalElement and it is much simpler. I removed code for handling the attributes std-out and std-err because they are no longer needed with the new display() logic.
The logic for executing python code is now in pyexec.ts: so we are decoupling the process of "finding" the python code (handled by the py-script web component) and the logic to actually execute it. This has many advantages, including the fact that it will be more easily usable by other components (e.g. pyrepl). Also, note that it's called pyexec and not pyeval: in the vast majority of cases in Python you have statements to execute, and almost never expressions to evaluate.
I killed the last remaining global store, scriptQueue tada. As a bonus effect, now we automatically do the correct thing when a <py-script> tag is dynamically added to the DOM (I added a test for it). I did not remove svelte from packages.json, because I don't fully understand the implications: there are various options which mention svelte in rollup.js and tsconfig.json, so it's probably better to kill it in its own PR.
pyexec.ts is also responsible of handling the default target for display() and correct handling/visualization of exceptions. I fixed/improved/added display/output tests in the process.
I also found a problem though, see issue #878, so I improved the test and marked it as xfail.
I removed BaseEvalElement as the superclass of most components. Now the only class which inherits from it is PyRepl. In a follow-up PR, I plan to merge them into a single class and do more cleanup.
During the refactoring, I killed guidGenerator: now instead of generating random py-* IDs which are very hard to read for humans, we generated py-internal-X IDs, where X is 0, 1, 2, 3, etc. This makes writing tests and debugging much easier.
I improved a lot our test machinery: it turns out that PR #829 broke the ability to use/view sourcemaps inside the playwright browser (at least on my machine).
For some reason chromium is unable to find sourcemaps if you use playwrights internal routing. So I reintroduced the http_server fixture which was removed by that PR, and added a pytest option --no-fake-server to use it instead, useful for debugging. By default we are still using the fakeserver though (which is faster and parallelizable).
Similarly, I added --dev which implies --headed and also automatically open chrome dev tools.
* ts strict getAttribute
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* mark xfail
* fix to string
* Remove
* use getAttribute for theme
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.
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
* start removing tailwind and rebuilding some css
* add css to pybox and add class to repl
* set output component visibility
* replace tailwind class with single component class
* add styles to css
* replace classes on button
* replace classes on input
* replace classes in title
* replace classes on list
* replace classes
* add new style file
* add list element style
* remove tailwind classes from todo example
* revert link on examples files
* remove tailwind config files
* remove commented old code
* add missing ;
Adds utils.htmlDecode arround innerHTML to read the code for <py-repl> and
<py-script>, which preserves all newlines, tabs, and < & > characters.
Fix bug #480
* fix OutputManager _append setter
* fix OutputManager change parameters
* fix OutputCtxManager __init__ and change methods
* replacing OutputManager pyscript.write with write function
* add optional output-append attribute to py-repl
* add appendOutput(default: true) to base component
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update pyscriptjs/src/components/pyrepl.ts
Co-authored-by: woxtu <woxtup@gmail.com>
* change from output-append flag to output-mode attribute
* removed type annotation
* repositioned setOutputMode call for auto-generated REPLs to work
* fixed indentation error for indented input
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* added preEvaluate method
* moved output-mode logic to preEvaluate
* remove static write method from PyScript, add write method to Element
* removed err parameter from OutputCtxManager
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add PyScript.write back with a deprecation warning
* fix wrong input name
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: woxtu <woxtup@gmail.com>
Co-authored-by: Fabio Pliger <fabio.pliger@gmail.com>
* Add type annotations
* Replace `StateCommand` with `Command`
* Revert "Replace `StateCommand` with `Command`"
This reverts commit 2dfc2d34e4.
* Fix the return value
* Add onscreen error when using py-env paths in local HTTP files without file server
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove redundant code, fix error handling, add 404 error
* Lint and Format
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* manage errors loading files
* use handleFetchError for handling fetch errors in env
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabio Pliger <fabio.pliger@gmail.com>
* fix: theme for <py-repl>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove comment
* fix: populate initial theme on auto generated repls.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* make copy of .py files part of build process
* move code out ofinterpreter file and make it download and load code during initialization
* fix double ; in interpreter
* remove debugging print
* update dependencies
* fix project name and version
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* change fmt-py
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove extra content
* define missing strict type
* create build folder if doesn't exist
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>