fix(qmd): run global npm CLIs without relying on PATH
CI / CI configuration security checks (push) Successful in 2s
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 25s
CI / QMD unit tests (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 15s
CI / PowerShell tests on Ubuntu (push) Successful in 1m5s
CI / Installed client configuration smoke tests (push) Successful in 40s
CI / Bash integration and installation guards (push) Successful in 1m10s
CI / CI configuration security checks (push) Successful in 2s
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 25s
CI / QMD unit tests (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 15s
CI / PowerShell tests on Ubuntu (push) Successful in 1m5s
CI / Installed client configuration smoke tests (push) Successful in 40s
CI / Bash integration and installation guards (push) Successful in 1m10s
npm's global bin directory is often missing from PATH on Windows, so the installer failed at `qmd pull` right after installing the package. Run the QMD CLI through node from `npm root --global`, as the QMD scripts already do, and look up other globally installed CLIs such as mcporter in `npm prefix --global` when they are not on PATH. Doctor now warns when npm's global bin directory is missing from PATH, since agents call mcporter directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a89be2604b
commit
6fad45105f
7 files changed
+101
-7
No files matched your search
@@ -55,8 +55,27 @@ def atomic_write(path, data):
|
||||
temporary.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def find_executable(name):
|
||||
found = shutil.which(name)
|
||||
if found or name == 'npm':
|
||||
return found
|
||||
# npm's global bin directory is often missing from PATH right after a Node.js setup on Windows,
|
||||
# so a CLI this setup just installed globally (such as mcporter) would not be found otherwise.
|
||||
npm = shutil.which('npm')
|
||||
if npm is None:
|
||||
return None
|
||||
try:
|
||||
prefix = subprocess.run([npm, 'prefix', '--global'], stdin=subprocess.DEVNULL, capture_output=True,
|
||||
text=True, timeout=60).stdout.strip()
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return None
|
||||
if not prefix:
|
||||
return None
|
||||
return shutil.which(name, path=prefix if os.name == 'nt' else os.path.join(prefix, 'bin'))
|
||||
|
||||
|
||||
def run_command(arguments, summary=False, home=None):
|
||||
executable = shutil.which(arguments[0])
|
||||
executable = find_executable(arguments[0])
|
||||
if executable is None:
|
||||
raise ValueError(f'{arguments[0]} CLI is required to manage plugins.')
|
||||
environment = os.environ.copy()
|
||||
|
||||
+9
-3
@@ -20,7 +20,7 @@ WINDOWS = os.name == 'nt'
|
||||
|
||||
def run(arguments, env=None, timeout=1800, check=True):
|
||||
result = subprocess.run(arguments, env=env, capture_output=True, text=True, encoding='utf-8', errors='replace',
|
||||
timeout=timeout, shell=WINDOWS and arguments[0] in ('npm', 'qmd'))
|
||||
timeout=timeout, shell=WINDOWS and arguments[0] == 'npm')
|
||||
if check and result.returncode != 0:
|
||||
raise ValueError(f'{" ".join(arguments[:3])} failed: {(result.stderr or result.stdout).strip()[-300:]}')
|
||||
return result.stdout
|
||||
@@ -94,6 +94,12 @@ class Setup:
|
||||
def node(self, script, *arguments, env=None, timeout=1800):
|
||||
return self.run(['node', str(self.scripts / script), *arguments], env=env, timeout=timeout)
|
||||
|
||||
def qmd_cli(self, *arguments, timeout=1800):
|
||||
# Run the CLI through node from the global package, as qmd-lib.mjs does, so it also works
|
||||
# when npm's global bin directory is not on PATH (common on Windows right after install).
|
||||
package = os.environ.get('QMD_PACKAGE_DIR') or str(Path(self.run(['npm', 'root', '--global']).strip()) / '@tobilu' / 'qmd')
|
||||
return self.run(['node', str(Path(package) / 'dist' / 'cli' / 'qmd.js'), *arguments], timeout=timeout)
|
||||
|
||||
def package_installed(self):
|
||||
# npm list exits non-zero on tree problems (ELSPROBLEMS) but still prints valid JSON.
|
||||
output = self.run(['npm', 'list', '--global', '--depth=0', '--json'], check=False)
|
||||
@@ -180,7 +186,7 @@ class Setup:
|
||||
state['models_block'] = True
|
||||
atomic_json(self.state_path, state)
|
||||
before = {p.name for p in self.models.iterdir()} if self.models.is_dir() else set()
|
||||
self.run(['qmd', 'pull'], timeout=3600)
|
||||
self.qmd_cli('pull', timeout=3600)
|
||||
after = {p.name for p in self.models.iterdir()} if self.models.is_dir() else set()
|
||||
state['owned_models'] = sorted(set(state['owned_models']) | (after - before))
|
||||
atomic_json(self.state_path, state)
|
||||
@@ -228,7 +234,7 @@ class Setup:
|
||||
for name in names:
|
||||
if re.fullmatch(r'repo-[0-9a-f]{12}', name):
|
||||
try:
|
||||
self.run(['qmd', 'collection', 'remove', name])
|
||||
self.qmd_cli('collection', 'remove', name)
|
||||
except (ValueError, subprocess.SubprocessError):
|
||||
pass
|
||||
if state['models_block'] and self.scripts.joinpath('qmd-config.mjs').exists():
|
||||
|
||||
Reference in new issue
Block a user