Resolve the npm directory with dirname so a patched os.name cannot pick the wrong Path flavour
_install_command used Path(npm).parent. pathlib chooses PosixPath or WindowsPath from os.name at call time, so a caller that overrides os.name (the install tests set it to posix) builds the flavour the host cannot instantiate, and the call raised NotImplementedError on Windows. os.path.dirname gives the same answer without consulting os.name. An empty result now leaves PATH alone rather than prepending the current directory.
This commit is contained in:
parent
fb43e3faf2
commit
a5c4c07faf
1 changed files with 6 additions and 2 deletions
|
|
@ -2560,9 +2560,13 @@ def _install_command(install_hint: str) -> tuple[list[str], Optional[dict]]:
|
|||
)
|
||||
args = shlex.split(install_hint)
|
||||
env = dict(os.environ)
|
||||
npm_dir = str(Path(npm).parent)
|
||||
# dirname, not Path().parent: Path picks its flavour from os.name, so a caller that
|
||||
# overrides it (the tests do) builds the wrong one. Empty means npm is a bare name,
|
||||
# and prepending "" would put the cwd on PATH.
|
||||
npm_dir = os.path.dirname(npm)
|
||||
current_path = env.get("PATH", "")
|
||||
env["PATH"] = os.pathsep.join([npm_dir, current_path]) if current_path else npm_dir
|
||||
if npm_dir:
|
||||
env["PATH"] = os.pathsep.join([npm_dir, current_path]) if current_path else npm_dir
|
||||
if os.name == "nt":
|
||||
command = "& " + " ".join(_powershell_quote(arg) for arg in [npm, *args[1:]])
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue