SarahAsad23 commented on code in PR #5901:
URL: https://github.com/apache/texera/pull/5901#discussion_r3486858224
##########
frontend/src/app/workspace/component/power-button/computing-unit-selection.component.ts:
##########
@@ -755,23 +764,115 @@ export class ComputingUnitSelectionComponent implements
OnInit {
}
}
- addEnvironment(): void {
+ showPVEmodalVisible(): void {
+ this.pveModalVisible = true;
+ this.getPVEs();
+ this.refreshAvailableDbPves();
+ }
+
+ isSavedPveInstalledInCu(name: string): boolean {
+ const trimmed = name.trim();
+ return this.pves.some(p => p.isLocked && p.name.trim() === trimmed);
+ }
+
+ private refreshAvailableDbPves(): void {
+ this.workflowPveService
+ .listUserPves()
+ .pipe(untilDestroyed(this))
+ .subscribe({
+ next: records => {
+ this.availableDbPves = records;
+ },
+ error: (err: unknown) => {
+ console.error("Failed to fetch saved Python environments", err);
+ this.availableDbPves = [];
+ },
+ });
+ }
+
+ // Triggered when the user picks a saved PVE in the picker. Builds a new
+ // env card from its name + packages and starts CU install flow
+ // (createVirtualEnvironment), so pip output streams into the same panel.
+ installFromSavedPve(veid: number): void {
+ const saved = this.availableDbPves.find(p => p.veid === veid);
+ if (!saved) return;
+
+ const trimmedName = saved.name.trim();
+ const dbRows = this.parseDbPackages(saved.packages);
+
+ const existingIndex = this.pves.findIndex(p => p.isLocked && p.name.trim()
=== trimmedName);
+ if (existingIndex !== -1) {
+ this.applySavedPveAsUpdate(existingIndex, saved.name, dbRows);
+ return;
+ }
+
this.pves.push({
- name: "",
+ name: saved.name,
userPackages: [],
- newPackages: [],
+ newPackages: dbRows,
deletingPackages: [],
pipOutput: "",
prettyPipOutput: "",
expanded: true,
isInstalling: false,
isLocked: false,
});
+
+ const newIndex = this.pves.length - 1;
+
+ setTimeout(() => this.createVirtualEnvironment(newIndex), 0);
}
- showPVEmodalVisible(): void {
- this.pveModalVisible = true;
- this.getPVEs();
+ private parseDbPackages(packages: Record<string, string> | null |
undefined): PveUserPackageRow[] {
+ return Object.entries(packages ?? {}).map(([name, raw]) => {
+ const match = raw?.match?.(/^(==|>=|<=)(.*)$/);
+ return {
+ name,
+ versionOp: (match ? match[1] : "==") as "==" | ">=" | "<=",
+ version: match ? match[2] : raw ?? "",
+ };
+ });
+ }
+
+ // Computes the diff between the saved DB record and the locked card's
+ // current user packages, then triggers the existing update path
+ private applySavedPveAsUpdate(index: number, displayName: string, dbRows:
PveUserPackageRow[]): void {
+ const existing = this.pves[index];
+
+ const dbByName = new Map(dbRows.map(p => [p.name.trim().toLowerCase(),
p]));
+ const existingByName = new Map(existing.userPackages.map(p =>
[p.name.trim().toLowerCase(), p]));
+
+ const toInstall: PveUserPackageRow[] = [];
+ const toDelete: { name: string; version: string }[] = [];
+
+ dbByName.forEach((db, key) => {
+ const cur = existingByName.get(key);
+ if (!cur) {
+ toInstall.push({ name: db.name, versionOp: db.versionOp, version:
db.version });
+ } else if ((cur.version ?? "").trim() !== (db.version ?? "").trim()) {
+ toDelete.push({ name: cur.name, version: (cur.version ?? "").trim() });
+ toInstall.push({ name: db.name, versionOp: db.versionOp, version:
db.version });
+ }
Review Comment:
The logic is based on whether the currently installed version satisfies the
updated constraint. For example, if the requirement changes from ==1.26.0 to
>=1.26.0 and 1.26.0 is already installed, the new constraint is already
satisfied, so no reinstallation is needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]