Skip to content

Commit

Permalink
feat: add library support for SASPy profile
Browse files Browse the repository at this point in the history
Signed-off-by: Shuguang Sun <[email protected]>
  • Loading branch information
ShuguangSun committed Apr 13, 2024
1 parent 08db8b2 commit d8d4012
Show file tree
Hide file tree
Showing 9 changed files with 471 additions and 69 deletions.
4 changes: 4 additions & 0 deletions client/src/commands/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const checkProfileAndAuthorize =
commands.executeCommand("setContext", "SAS.librariesDisplayed", true);
libraryNavigator.refresh();
return finishAuthorization(profileConfig);
case ConnectionType.SASPY:
commands.executeCommand("setContext", "SAS.librariesDisplayed", true);
libraryNavigator.refresh();
return finishAuthorization(profileConfig);
default:
return finishAuthorization(profileConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import ItcLibraryAdapter from "../../connection/itc/ItcLibraryAdapter";
import RestLibraryAdapter from "../../connection/rest/RestLibraryAdapter";
import SaspyLibraryAdapter from "../../connection/saspy/SaspyLibraryAdapter";
import { ConnectionType } from "../profile";
import { LibraryAdapter } from "./types";

Expand All @@ -11,6 +12,8 @@ class LibraryAdapterFactory {
case ConnectionType.IOM:
case ConnectionType.COM:
return new ItcLibraryAdapter();
case ConnectionType.SASPY:
return new SaspyLibraryAdapter();
case ConnectionType.Rest:
default:
return new RestLibraryAdapter();
Expand Down
30 changes: 9 additions & 21 deletions client/src/components/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum ConnectionOptions {
SAS9COM = "SAS 9.4 (local)",
SAS9IOM = "SAS 9.4 (remote - IOM)",
SAS9SSH = "SAS 9.4 (remote - SSH)",
SAS9SASPY = "SASPY",
SAS9SASPY = "SAS 9.4 (SASPy)",
SASViya = "SAS Viya",
}

Expand Down Expand Up @@ -95,7 +95,6 @@ export interface SSHProfile extends BaseProfile {

export interface SASPYProfile extends BaseProfile {
connectionType: ConnectionType.SASPY;
// saspath: string;
cfgname: string;
pythonpath: string;
}
Expand All @@ -112,7 +111,12 @@ export interface IOMProfile extends BaseProfile {
port: number;
}

export type Profile = ViyaProfile | SSHProfile | SASPYProfile | COMProfile | IOMProfile;
export type Profile =
| ViyaProfile
| SSHProfile
| SASPYProfile
| COMProfile
| IOMProfile;

export enum AutoExecType {
File = "file",
Expand Down Expand Up @@ -601,24 +605,8 @@ export class ProfileConfig {

await this.upsertProfile(name, profileClone);
} else if (profileClone.connectionType === ConnectionType.SASPY) {
// profileClone.pythonpath = await createInputTextBox(
// ProfilePromptType.PYTHONPath,
// profileClone.pythonpath,
// );
// if (profileClone.pythonpath === undefined) {
// return;
// }

// profileClone.cfgname = await createInputTextBox(
// ProfilePromptType.Cfgname,
// profileClone.cfgname,
// );
// if (profileClone.cfgname === undefined) {
// return;
// }

profileClone.cfgname = "";
// profileClone.sasOptions = [];
// profileClone.sasOptions = [];
await this.upsertProfile(name, profileClone);
} else if (profileClone.connectionType === ConnectionType.COM) {
profileClone.sasOptions = [];
Expand Down Expand Up @@ -697,7 +685,7 @@ export enum ProfilePromptType {
Port,
Username,
Cfgname,
PYTHONpath
PYTHONpath,
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
LogLine as ComputeLogLine,
LogLineTypeEnum as ComputeLogLineTypeEnum,
} from "./rest/api/compute";
import { getSession as getSASPYSession } from "./saspy";
import { Session } from "./session";
import { getSession as getSSHSession } from "./ssh";
import { getSession as getSASPYSession } from "./saspy";

let profileConfig: ProfileConfig;

Expand Down
72 changes: 72 additions & 0 deletions client/src/connection/saspy/CodeRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright © 2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { commands } from "vscode";

import { SASPYSession } from ".";
import { LogLine, getSession } from "..";
import { useRunStore } from "../../store";

class CodeRunner {
public async runCode(
code: string,
startTag: string = "",
endTag: string = "",
): Promise<string> {
// If we're already executing code, lets wait for it
// to finish up.
let unsubscribe;
if (useRunStore.getState().isExecutingCode) {
await new Promise((resolve) => {
unsubscribe = useRunStore.subscribe(
(state) => state.isExecutingCode,
(isExecutingCode) => !isExecutingCode && resolve(true),
);
});
}

const { setIsExecutingCode } = useRunStore.getState();
setIsExecutingCode(true);
commands.executeCommand("setContext", "SAS.running", true);
const session = getSession();

let logText = "";
const onExecutionLogFn = session.onExecutionLogFn;
const outputLines = [];
const addLine = (logLines: LogLine[]) =>
outputLines.push(...logLines.map(({ line }) => line));

try {
await session.setup(true);

// Lets capture output to use it on
session.onExecutionLogFn = addLine;

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
await (session as SASPYSession).run(code);

const logOutput = outputLines.filter((line) => line.trim()).join("");

logText =
startTag && endTag
? logOutput
.slice(
logOutput.lastIndexOf(startTag),
logOutput.lastIndexOf(endTag),
)
.replace(startTag, "")
.replace(endTag, "")
: logOutput;
} finally {
unsubscribe && unsubscribe();
// Lets update our session to write to the log
session.onExecutionLogFn = onExecutionLogFn;

setIsExecutingCode(false);
commands.executeCommand("setContext", "SAS.running", false);
}

return logText;
}
}

export default CodeRunner;
Loading

0 comments on commit d8d4012

Please sign in to comment.