Skip to content

fix: use correct Python executable for workspace operations#375

Merged
bigcat88 merged 2 commits intomainfrom
fix/resolve-workspace-python
Mar 13, 2026
Merged

fix: use correct Python executable for workspace operations#375
bigcat88 merged 2 commits intomainfrom
fix/resolve-workspace-python

Conversation

@bigcat88
Copy link
Contributor

When comfy-cli is installed via pipx or uv tool, sys.executable points to their isolated venv rather than the environment where ComfyUI dependencies should go. This means comfy install puts torch into comfy-cli's own venv, comfy launch runs main.py with the wrong Python, and comfy node install targets the wrong pip.

The fix adds a small resolve_python module that checks, in order: VIRTUAL_ENV, CONDA_PREFIX, workspace .venv or venv directory, then falls back to sys.executable. During comfy install, if no active environment is detected, a .venv is created inside the workspace automatically. All ~20 sys.executable callsites across install.py, launch.py, command.py, cm_cli_util.py, cmdline.py, and models.py now go through this resolution instead of using sys.executable directly.

The validate_node_for_publishing ruff check intentionally stays on sys.executable since ruff is comfy-cli's own dev dependency, not a workspace dep.

Backward compatibility is preserved: if you pip install comfy-cli into an activated venv, that venv's python is used (via VIRTUAL_ENV). If you use conda, CONDA_PREFIX is respected. Existing installs that already have a workspace .venv or venv will find it. The sys.executable fallback means nothing changes for direct pip installs in a shared environment.

Fixes #263, fixes #272. Supersedes community PR #282 which took a similar approach but eagerly created venvs in more situations.

When comfy-cli is installed via pipx or uv tool, sys.executable points
to their isolated venv, not the environment where ComfyUI deps belong.
This caused install, launch, node, and update commands to target the
wrong Python.

Add comfy_cli/resolve_python.py with centralized resolution:
VIRTUAL_ENV -> CONDA_PREFIX -> workspace .venv/venv -> sys.executable.
During comfy install, a workspace .venv is created when no active env
is detected. All ~20 sys.executable callsites across 6 files now use
the resolved python instead.

Fixes #263, fixes #272. Supersedes #282.
@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 94.93671% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
comfy_cli/command/install.py 75.00% 3 Missing ⚠️
comfy_cli/resolve_python.py 97.77% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #375      +/-   ##
==========================================
+ Coverage   54.89%   60.49%   +5.60%     
==========================================
  Files          32       33       +1     
  Lines        3618     3678      +60     
==========================================
+ Hits         1986     2225     +239     
+ Misses       1632     1453     -179     
Files with missing lines Coverage Δ
comfy_cli/cmdline.py 58.00% <100.00%> (+5.77%) ⬆️
comfy_cli/command/custom_nodes/cm_cli_util.py 67.79% <100.00%> (+44.98%) ⬆️
comfy_cli/command/custom_nodes/command.py 55.81% <100.00%> (+12.62%) ⬆️
comfy_cli/command/launch.py 35.17% <100.00%> (+19.78%) ⬆️
comfy_cli/command/models/models.py 68.63% <ø> (+12.07%) ⬆️
comfy_cli/resolve_python.py 97.77% <97.77%> (ø)
comfy_cli/command/install.py 70.47% <75.00%> (+8.56%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Verify that each callsite (install, launch, cm_cli, custom_nodes,
cmdline, models) actually wires the resolved python into subprocess
calls rather than falling back to sys.executable.
@bigcat88 bigcat88 force-pushed the fix/resolve-workspace-python branch from f53311c to 07cb00e Compare March 13, 2026 13:28
@bigcat88 bigcat88 marked this pull request as ready for review March 13, 2026 13:56
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Mar 13, 2026
@bigcat88 bigcat88 merged commit fade810 into main Mar 13, 2026
14 checks passed
@bigcat88 bigcat88 deleted the fix/resolve-workspace-python branch March 13, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

1 participant