8000 Allow pyscript package to contain multiple files by hoodmane · Pull Request #1262 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Allow pyscript package to contain multiple files #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from

Conversation

hoodmane
Copy link
Contributor
@hoodmane hoodmane commented Mar 8, 2023

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
Copy link
Contributor Author
hoodmane commented Mar 8, 2023

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
Copy link
Contributor
@marimeireles marimeireles left a comment

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.

@@ -163,15 +166,15 @@ const pyAttributeToEvent: Map<string, string> = new Map<string, string>([
]);

/** Initialize all elements with py-* handlers attributes */
export function initHandlers(interpreter: InterpreterClient) {
export async function initHandlers(interpreter: InterpreterClient) {
Copy link
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
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...

plugins: [terser()],
},
],
output: [{ minify: true }, { minify: false }].map(({ minify }) => ({
Copy link
Contributor
@marimeireles marimeireles Mar 23, 2023

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
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.

67ED
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
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
Contributor Author

Thanks for the review @marimeireles!

@hoodmane
Copy link
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
0