fix: install black's transitive deps in the pyodide code formatter (#29503)

Saving any tool or function in the admin UI threw "ModuleNotFoundError:
No module named 'click'" in the browser, even on a fresh tool with no
custom code, because the click name never appears in user code at all.

The in-browser formatter runs black through a Pyodide/micropip worker.
black needs click, mypy_extensions, pathspec, platformdirs and pytokens
at import time, but the vendored pyodide-lock.json records none of
these as black's dependencies, and micropip only walks a locked
package's declared deps when install() is given explicit constraints,
which this worker never does. So only black itself ever got installed.

Requesting the five packages explicitly alongside black fixes it
without touching the worker or the lock file.
This commit is contained in:
Classic298 2026-09-04 06:45:58 +02:00 committed by GitHub
parent 8aa25dd358
commit 59f9502240
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -122,7 +122,15 @@ print(black.format_str("""${code.replace(/\\/g, '\\\\').replace(/`/g, '\\`').rep
print("${endTag}")
`;
const packages = ['black'];
// black's pyodide-lock entry declares no dependencies, so micropip installs none of them
const packages = [
'black',
'click',
'mypy_extensions',
'pathspec',
'platformdirs',
'pytokens'
];
function handleMessage(event) {
const { id: eventId, stdout, stderr } = event.data;