Skip to content

Commit 2d7aed6

Browse files
Revert "Single source of truth for installation defaults"
This reverts commit b3f7808.
1 parent a9a62b3 commit 2d7aed6

File tree

2 files changed

+29
-40
lines changed

2 files changed

+29
-40
lines changed

packages/pyodide-kernel/py/piplite/piplite/piplite.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,14 @@
2727
#: a cache of available packages
2828
_PIPLITE_INDICES = {}
2929

30+
#: don't fall back to pypi.org if a package is not found in _PIPLITE_URLS
31+
_PIPLITE_DISABLE_PYPI = False
32+
3033
#: a well-known file name respected by the rest of the build chain
3134
ALL_JSON = "/all.json"
3235

33-
#: default arguments for piplite.install
34-
_PIPLITE_DEFAULT_INSTALL_ARGS = {
35-
"requirements": None,
36-
"keep_going": False,
37-
"deps": True,
38-
"credentials": None,
39-
"pre": False,
40-
"index_urls": None,
41-
"verbose": False,
42-
}
43-
44-
# Internal flags that affect package lookup behavior
45-
_PIPLITE_INTERNAL_FLAGS = {
46-
"disable_pypi": False, # don't fall back to pypi.org if package not found in _PIPLITE_URLS
47-
}
36+
#: default index URLs to use when no specific index URLs are provided
37+
_PIPLITE_DEFAULT_INDEX_URLS = None
4838

4939

5040
class PiplitePyPIDisabled(ValueError):
@@ -107,7 +97,7 @@ async def _query_package(
10797
if pypi_json_from_index:
10898
return pypi_json_from_index
10999

110-
if _PIPLITE_INTERNAL_FLAGS["disable_pypi"]:
100+
if _PIPLITE_DISABLE_PYPI:
111101
raise PiplitePyPIDisabled(
112102
f"{name} could not be installed: PyPI fallback is disabled"
113103
)
@@ -132,30 +122,28 @@ async def _install(
132122
"""Invoke micropip.install with a patch to get data from local indexes"""
133123

134124
try:
135-
install_args = _PIPLITE_DEFAULT_INSTALL_ARGS.copy()
136-
137-
provided_args = {
138-
"requirements": requirements,
139-
"keep_going": keep_going,
140-
"deps": deps,
141-
"credentials": credentials,
142-
"pre": pre,
143-
"index_urls": index_urls,
144-
"verbose": verbose,
145-
}
146-
install_args.update({k: v for k, v in provided_args.items() if v is not None})
147-
125+
# Use default index URLs if none provided and defaults exist
126+
effective_index_urls = (
127+
index_urls if index_urls is not None else _PIPLITE_DEFAULT_INDEX_URLS
128+
)
148129

149130
if verbose:
150-
logger.info(f"Installing with arguments: {install_args}")
131+
logger.info(f"Installing with index URLs: {effective_index_urls}")
151132

152133
with patch("micropip.package_index.query_package", _query_package):
153-
return await micropip.install(**install_args)
154-
134+
return await micropip.install(
135+
requirements=requirements,
136+
keep_going=keep_going,
137+
deps=deps,
138+
credentials=credentials,
139+
pre=pre,
140+
index_urls=effective_index_urls,
141+
verbose=verbose,
142+
)
155143
except Exception as e:
156-
if install_args.get("index_urls"):
144+
if effective_index_urls:
157145
logger.error(
158-
f"Failed to install using index URLs {install_args['index_urls']}: {e}"
146+
f"Failed to install using index URLs {effective_index_urls}: {e}"
159147
)
160148
raise
161149

packages/pyodide-kernel/src/worker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ export class PyodideRemoteKernel {
8888

8989
const pythonConfig = [
9090
'import piplite.piplite',
91-
`piplite.piplite._PIPLITE_DEFAULT_INSTALL_ARGS = ${JSON.stringify({
92-
...pipliteInstallDefaultOptions,
93-
})}`,
94-
`piplite.piplite._PIPLITE_INTERNAL_FLAGS = ${JSON.stringify({
95-
disable_pypi: disablePyPIFallback,
96-
})}`,
91+
`piplite.piplite._PIPLITE_DISABLE_PYPI = ${disablePyPIFallback ? 'True' : 'False'}`,
9792
`piplite.piplite._PIPLITE_URLS = ${JSON.stringify(pipliteUrls)}`,
9893
];
9994

95+
if (pipliteInstallDefaultOptions?.indexUrls) {
96+
pythonConfig.push(
97+
`piplite.piplite._PIPLITE_DEFAULT_INDEX_URLS = ${JSON.stringify(pipliteInstallDefaultOptions.indexUrls)}`,
98+
);
99+
}
100+
100101
// get piplite early enough to impact pyodide-kernel dependencies
101102
await this._pyodide.runPythonAsync(pythonConfig.join('\n'));
102103
}

0 commit comments

Comments
 (0)