Skip to content

Allow pyscript package to contain multiple files#1262

Closed
hoodmane wants to merge 31 commits into
pyscript:mainfrom
hoodmane:pyscript-package-2
Closed

Allow pyscript package to contain multiple files#1262
hoodmane wants to merge 31 commits into
pyscript:mainfrom
hoodmane:pyscript-package-2

Conversation

@hoodmane

@hoodmane hoodmane commented Mar 8, 2023

Copy link
Copy Markdown
Contributor

Followup to #1232. Closes #1226.

Use node to make a manifest of the src/python dir and then use terser to inject it into the bundle as a variable called pyscript_package. This means we need to always use the terser plugin even when not minifying. In the non-minify case, we disable terser minification and mangling and enable terser beautification. Note that we bundle mangled versions of many upstream npm dependencies, so even in debug/nonminified builds, these do not include symbol names.

Followup to pyscript#1232. Closes pyscript#1226.

Use node to make a manifest of the src/python dir and then use terser
to inject it into the bundle as a variable called pyscript_package.
This means we need to always use the terser plugin even when not minifying.
In the non-minify case, we disable terser minification and mangling and
enable terser beautification. Note that we bundle mangled versions of many
upstream npm dependencies, so even in debug/nonminified builds, these do
not include symbol names.
@hoodmane hoodmane force-pushed the pyscript-package-2 branch from 7195b0e to 1e34b4b Compare March 8, 2023 11:08
@hoodmane

hoodmane commented Mar 8, 2023

Copy link
Copy Markdown
Contributor Author

Oh we seem to vendor mangled npm dependencies. This is not very good.

hoodmane added a commit to hoodmane/pyscript that referenced this pull request Mar 8, 2023
For mysterious reasons, these errors appear on my branch pyscript#1262 even
though they are not related to changes there. The eslint config seems
a bit unstable.

Anyways this fixes them.
For mysterious reasons, these errors appear on my branch pyscript#1262 even
though they are not related to changes there. The eslint config seems
a bit unstable.

Anyways this fixes them.
@hoodmane hoodmane mentioned this pull request Mar 8, 2023
@hoodmane hoodmane force-pushed the pyscript-package-2 branch from b8ab0cd to 7957814 Compare March 9, 2023 14:22
antocuni pushed a commit that referenced this pull request Mar 13, 2023
* 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

@marimeireles marimeireles left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @hoodmane.
I've learned a bit of TS reviewing it, cool!

Most of my comments are questions of things that are not clear to me.
Once you rebase it it's good to me to merge.

Comment thread pyscriptjs/rollup.config.js

/** Initialize all elements with py-* handlers attributes */
export function initHandlers(interpreter: InterpreterClient) {
export async function initHandlers(interpreter: InterpreterClient) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these now async?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry these changes are unrelated...

Comment thread pyscriptjs/rollup.config.js
plugins: [terser()],
},
],
output: [{ minify: true }, { minify: false }].map(({ minify }) => ({

@marimeireles marimeireles Mar 23, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do I pass the minify argument to this? (in general, just because I don't really know what's calling this code)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to change because of #1298.

Comment thread pyscriptjs/src/main.ts
interpreter._remote.interface.FS.mkdirTree('/home/pyodide/pyscript');
interpreter._remote.interface.FS.writeFile('pyscript/__init__.py', pyscript);
// Write pyscript package into file system
for (let dir of pyscript_package.dirs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to test this code?

@hoodmane

Copy link
Copy Markdown
Contributor Author

Thanks for the review @marimeireles!

@hoodmane

Copy link
Copy Markdown
Contributor Author

Closed in favor of #1309.

@hoodmane hoodmane closed this Mar 25, 2023
@hoodmane hoodmane deleted the pyscript-package-2 branch March 27, 2023 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make pyscript.py into a Python package

2 participants