From a5c4c07fafa02c56e19792f1fe3297f5e39e368e Mon Sep 17 00:00:00 2001 From: danielhanchen Date: Wed, 29 Jul 2026 08:11:52 +0000 Subject: [PATCH] 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. --- unsloth_cli/commands/start.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.py index 8618eea213..31db1a9210 100644 --- a/unsloth_cli/commands/start.py +++ b/unsloth_cli/commands/start.py @@ -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 (