Repository: pyodide/pyodide

Issue:
Allow specifying the version of Pyodide just once
## 🚀 Feature

It seems that as things stand, to use Pyodide, you have to include the right version of the script (e.g., `<script src="https://cdn.jsdelivr.net/pyodide/v0.19.1/full/pyodide.js"></script>`) and request the right directory for `loadPyodide` (e.g., `loadPyodide({indexURL : "https://cdn.jsdelivr.net/pyodide/v0.19.1/full/"})`). The script should probably provide a function or variable that tells you the version (if it's not possible for it to recapitulate the entirety of its own URL) so that the version doesn't have to be repeated for `loadPyodide`.

### Motivation

Having to specify the same version twice makes it easy to accidentally desynchronize the versions.



Discussion:
> if it's not possible for it to recapitulate the entirety of its own URL

There is no way to do this in general I don't think. In an es6 module you can use [`import.meta`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta), in the main thread you can use [`document.currentScript`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) but if you are loaded with `importScripts` into a classic worker I think there is nothing. That isn't even getting into all the different ways we could be loaded in node, but the node situation might be easier. Arguably the classic worker use case is the most important though and I think it's not solvable. At least between html.spec.whatwg, MDN, and stack overflow I find no mention of how to deal with this.

> The script should probably provide a function or variable that tells you the version

Seems like a reasonable request. Currently we define the version in the Pyodide package `__init__.py` file and extract it at runtime using Python. We could import pyodide at build time and pull the version out and then inject it into the Javascript bundle.
You could hard-code the CDN URL into each version before you upload it to the CDN, but that would only work if you loaded the script from the CDN, so I'm not sure how useful it would be.
That's not a good idea, if we go that route we are going to screw up the deploy.
Well it seems like there is an approach that works by throwing and catching an error and then parsing the file name out of the stack trace.

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -155,7 +155,7 @@ def javascript_setup(self):
     def load_pyodide(self):
         self.run_js(
             """
-            let pyodide = await loadPyodide({ indexURL : './', fullStdLib: false, jsglobals : self });
+            let pyodide = await loadPyodide({ fullStdLib: false, jsglobals : self });
             self.pyodide = pyodide;
             globalThis.pyodide = pyodide;
             pyodide._api.inTestHoist = true; // improve some error messages for tests


Test patch:
diff --git a/src/js/test/conftest.js b/src/js/test/conftest.js
--- a/src/js/test/conftest.js
+++ b/src/js/test/conftest.js
@@ -3,5 +3,5 @@ import path from "path";
 globalThis.path = path;
 
 before(async () => {
-  globalThis.pyodide = await loadPyodide({ indexURL: "../../build/" });
+  globalThis.pyodide = await loadPyodide();
 });