Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UV mirror settings #713

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config/comfySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ export const DEFAULT_SETTINGS: ComfySettingsData = {
'Comfy.Workflow.WorkflowTabsPosition': 'Topbar',
'Comfy.Workflow.ShowMissingModelsWarning': true,
'Comfy.Server.LaunchArgs': {},
'Comfy-Desktop.PythonInstallMirror': '',
'Comfy-Desktop.PypiInstallMirror': '',
} as const;

export interface ComfySettingsData {
'Comfy-Desktop.AutoUpdate': boolean;
'Comfy-Desktop.SendStatistics': boolean;
'Comfy.Server.LaunchArgs': Record<string, string>;
'Comfy-Desktop.PythonInstallMirror': string;
'Comfy-Desktop.PypiInstallMirror': string;
[key: string]: unknown;
}

Expand Down
2 changes: 2 additions & 0 deletions src/install/installWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export class InstallWizard implements HasTelemetry {
...existingSettings,
'Comfy-Desktop.AutoUpdate': this.installOptions.autoUpdate,
'Comfy-Desktop.SendStatistics': this.installOptions.allowMetrics,
'Comfy-Desktop.PythonInstallMirror': this.installOptions.pythonMirror,
'Comfy-Desktop.PypiInstallMirror': this.installOptions.pypiMirror,
};

if (this.installOptions.device === 'cpu') {
Expand Down
8 changes: 4 additions & 4 deletions src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import path from 'node:path';
import { graphics } from 'systeminformation';

import { ComfyServerConfig } from '../config/comfyServerConfig';
import { ComfySettings } from '../config/comfySettings';
import { IPC_CHANNELS, ProgressStatus, ServerArgs } from '../constants';
import { InstallationManager } from '../install/installationManager';
import { DownloadManager } from '../models/DownloadManager';
Expand All @@ -23,14 +22,15 @@ import { ComfyServer } from './comfyServer';

export class ComfyDesktopApp implements HasTelemetry {
public comfyServer: ComfyServer | null = null;
public comfySettings: ComfySettings;
private terminal: Terminal | null = null; // Only created after server starts.
constructor(
public installation: ComfyInstallation,
public appWindow: AppWindow,
readonly telemetry: ITelemetry
) {
this.comfySettings = new ComfySettings(installation.basePath);
) {}

get comfySettings() {
return this.installation.comfySettings;
}

get basePath() {
Expand Down
18 changes: 15 additions & 3 deletions src/main-process/comfyInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import log from 'electron-log/main';
import { rm } from 'node:fs/promises';

import { ComfyServerConfig } from '../config/comfyServerConfig';
import { ComfySettings } from '../config/comfySettings';
import type { InstallValidation, TorchDeviceType } from '../preload';
import { type ITelemetry, getTelemetry } from '../services/telemetry';
import { useDesktopConfig } from '../store/desktopConfig';
Expand Down Expand Up @@ -32,6 +33,7 @@ export class ComfyInstallation {
}

virtualEnvironment: VirtualEnvironment;
comfySettings: ComfySettings;

_basePath: string;
/** The base path of the desktop app. Models, nodes, and configuration are saved here by default. */
Expand All @@ -41,7 +43,7 @@ export class ComfyInstallation {
set basePath(value: string) {
// Duplicated in constructor to avoid non-nullable type assertions.
this._basePath = value;
this.virtualEnvironment = new VirtualEnvironment(value, this.telemetry, this.device);
this.virtualEnvironment = this.createVirtualEnvironment(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we should remove side effect from setter, as it is very difficult to maintain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed: #715

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

}

/**
Expand All @@ -61,7 +63,17 @@ export class ComfyInstallation {
) {
// TypeScript workaround: duplication of basePath setter
this._basePath = basePath;
this.virtualEnvironment = new VirtualEnvironment(basePath, telemetry, device);
this.comfySettings = new ComfySettings(basePath);
this.virtualEnvironment = this.createVirtualEnvironment(basePath);
}

private createVirtualEnvironment(basePath: string) {
return new VirtualEnvironment(basePath, {
telemetry: this.telemetry,
selectedDevice: this.device,
pythonMirror: this.comfySettings.get('Comfy-Desktop.PythonInstallMirror'),
pypiMirror: this.comfySettings.get('Comfy-Desktop.PypiInstallMirror'),
});
}

/**
Expand Down Expand Up @@ -105,7 +117,7 @@ export class ComfyInstallation {
validation.basePath = 'OK';
this.onUpdate?.(validation);

const venv = new VirtualEnvironment(basePath, this.telemetry, this.device);
const venv = this.createVirtualEnvironment(basePath);
if (await venv.exists()) {
validation.venvDirectory = 'OK';
this.onUpdate?.(validation);
Expand Down
3 changes: 3 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface InstallOptions {
migrationItemIds?: string[];
/** Torch compute device */
device: TorchDeviceType;
/** UV python mirrors */
pythonMirror?: string; // UV_PYTHON_INSTALL_MIRROR
pypiMirror?: string; // UV_PYPI_INSTALL_MIRROR
}

export interface SystemPaths {
Expand Down
26 changes: 22 additions & 4 deletions src/virtualEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class VirtualEnvironment implements HasTelemetry {
readonly comfyUIRequirementsPath: string;
readonly comfyUIManagerRequirementsPath: string;
readonly selectedDevice?: string;
readonly telemetry: ITelemetry;
readonly pythonMirror?: string;
readonly pypiMirror?: string;
uvPty: pty.IPty | undefined;

/** @todo Refactor to `using` */
Expand All @@ -51,6 +54,8 @@ export class VirtualEnvironment implements HasTelemetry {
UV_TOOL_BIN_DIR: this.cacheDir,
UV_PYTHON_INSTALL_DIR: this.cacheDir,
VIRTUAL_ENV: this.venvPath,
UV_PYTHON_INSTALL_MIRROR: this.pythonMirror,
UV_PYPI_INSTALL_MIRROR: this.pypiMirror,
},
});
}
Expand All @@ -59,13 +64,26 @@ export class VirtualEnvironment implements HasTelemetry {

constructor(
venvPath: string,
readonly telemetry: ITelemetry,
selectedDevice: TorchDeviceType | undefined,
pythonVersion: string = '3.12.8'
{
telemetry,
selectedDevice,
pythonVersion,
pythonMirror,
pypiMirror,
}: {
telemetry: ITelemetry;
selectedDevice?: TorchDeviceType;
pythonVersion?: string;
pythonMirror?: string;
pypiMirror?: string;
}
) {
this.venvRootPath = venvPath;
this.pythonVersion = pythonVersion;
this.telemetry = telemetry;
this.pythonVersion = pythonVersion ?? '3.12';
this.selectedDevice = selectedDevice;
this.pythonMirror = pythonMirror;
this.pypiMirror = pypiMirror;

// uv defaults to .venv
this.venvPath = path.join(venvPath, '.venv');
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/comfySettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ describe('ComfySettings', () => {
'Comfy-Desktop.AutoUpdate': false,
'Comfy-Desktop.SendStatistics': false,
'Comfy.Server.LaunchArgs': { test: 'value' },
'Comfy-Desktop.PythonInstallMirror': '',
'Comfy-Desktop.PypiInstallMirror': '',
};

vi.mocked(fs.access).mockResolvedValue();
Expand Down
Loading