Skip to content
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

add tests for runtime config inside py-config and remove usage of indexURL #734

Merged
merged 10 commits into from
Aug 31, 2022

Conversation

madhur-tandon
Copy link
Member

@madhur-tandon madhur-tandon commented Aug 29, 2022

@hoodmane You might be able to chime in here.

The test loads the pyodide.js file which is present under node_modules/pyodide.
This further leads to loading of pyodide_py.tar and pyodide.asm.js

While /pyodide/pyodide.js and /pyodide/pyodide_py.tar are loaded correctly, the path for the last one is always wrong.
It is /build/pyodide/pyodide.asm.js instead of just /pyodide/pyodide.asm.js

What could be the reason for this? I also tried downloading the release from here: https://github.com/pyodide/pyodide/releases/tag/0.21.1

and using the downloaded folder as the path to indexURL (instead of the one from under node_modules/pyodide).

It seems like somewhere the path for where to look at pyodide.asm.js is set incorrectly. Can you confirm this?
Maybe it is related to the issue fixed here: pyodide/pyodide#3015?

@madhur-tandon madhur-tandon added the sprint issue has been pulled into current sprint and is actively being worked on label Aug 29, 2022
@madhur-tandon
Copy link
Member Author

TLDR:
The above issue is finally fixed.

Lessons learnt: Avoid using indexURL , let it be determined implicitly underneath

Issue:
Importing import { loadPyodide } from 'pyodide'; leads to weird behaviours where paths of files to be fetched such as pyodide.asm.js changes and it somehow uses /build/ prefix in the path which results in a 404. But if we don't import it, jest will be unhappy and won't let the unit tests for the runtime to pass as it won't be able to find loadPyodide since we didn't use the import explicitly.

Solution:

  • Don't use import { loadPyodide } from 'pyodide'; at the top to avoid the wrong path behaviour.
  • Use dynamic import in the unit test and make loadPyodide available to the global namespace, just for the sake of tests / making jest happy.
  • Remove the usage of indexURL completely since it will always be determined automatically now, which is correct.
  • Also, since indexURL is determined correctly now, the snippet to determine if we are inside jest is no longer needed and thus has been removed.

I have added comments to explain the JS voodo I did.

Consequence: All tests will pass and manually using py-config will also not fail now.

Copy link
Contributor

@antocuni antocuni left a comment

Choose a reason for hiding this comment

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

Thank you @madhur-tandon: I suppose it was not an easy task to debug the indexURL issue, good job!

In general I'm very happy with this PR; I suggested a number of changes to make it even better. Don't be scared by the number of comments, most are shallow :).

I think this PR is missing a test, though. As I wrote in the comments, the current test_config is misnamed because it should be test_runtimes. But indeed, we do miss a test_config, i.e. the simplest possible test to check that <py-config> is loaded and evaluated by pyscript. Ideally, it should be placed before test_runtimes, because it tests a basic functionality which is a prerequisite for test_runtimes to work.

Looking at AppConfig, it seems we can also set the name and version of our app:

export type AppConfig = {
autoclose_loader: boolean;
name?: string;
version?: string;
runtimes?: Array<RuntimeConfig>;
};

So, a good way to write a test_config could be:

  1. add some logging inside our typescript files to console.log appConfig_.name and .version if they are set (which looks generally useful)
  2. write a minimal test which sets them via <py-config>
  3. check that the correct name and version are printed to console.log

examples/webgl/raycaster/index.html Show resolved Hide resolved
pyscriptjs/src/pyodide.ts Show resolved Hide resolved
pyscriptjs/src/utils.ts Show resolved Hide resolved
pyscriptjs/tests/integration/support.py Outdated Show resolved Hide resolved
pyscriptjs/tests/integration/test_py_config.py Outdated Show resolved Hide resolved
pyscriptjs/tests/integration/test_py_config.py Outdated Show resolved Hide resolved
@madhur-tandon
Copy link
Member Author

But indeed, we do miss a test_config, i.e. the simplest possible test to check that <py-config> is loaded and evaluated by pyscript.

Did you check the file pyscriptjs/tests/unit/pyconfig.test.ts @antocuni ?
I think that file serves the purpose doesn't it?

@madhur-tandon madhur-tandon changed the title add tests for py-config add tests for runtime config inside py-config and remove usage of indexURL Aug 31, 2022
Copy link
Contributor

@fpliger fpliger left a comment

Choose a reason for hiding this comment

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

Overall LGTM, left minor comments and, as @antocuni mentioned, can be addressed in a follow up PR

pyscriptjs/src/pyodide.ts Show resolved Hide resolved
@madhur-tandon madhur-tandon requested review from antocuni and removed request for ntoll August 31, 2022 19:03
TMP_TAR_LOCATION = os.path.join(TMP_DIR, TAR_NAME)
with open(TMP_TAR_LOCATION, "wb") as f:
f.write(response.raw.read())
val = TMP_TAR_LOCATION
Copy link
Contributor

Choose a reason for hiding this comment

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

veeeery nitpicking, but note that here you are loading 151MB in memory all at once, just to write them to disk. I'm sure there are better ways to save an http request to disk.
That said, it's not a blocker for this PR, but just wanted to say it as a general comment/suggestion for the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Chunking perhaps?

Copy link
Contributor

Choose a reason for hiding this comment

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

chunking is surely a good option.
I would have expected requests to have a direct way to save to disk but apparently there isn't.
A quick google reveals this.

@madhur-tandon madhur-tandon merged commit e31e03a into pyscript:main Aug 31, 2022
@madhur-tandon madhur-tandon deleted the tests-py-config branch August 31, 2022 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sprint issue has been pulled into current sprint and is actively being worked on
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants