Skip to content

Commit e16fddc

Browse files
committed
fix: update ui to support pulling interpreter from local dir
We had been pointing to a remote git branch. To fix this required passing through `cwd` to the pty spawn, because it defaults to using the user's home directory. If we want to use a relative path to the interpreter in our requirements.txt, we need to inherit cwd. Signed-off-by: Nick Mitchell <[email protected]>
1 parent af4400e commit e16fddc

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

pdl-live-react/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#-e git+https://github.com/IBM/prompt-declaration-language.git#egg=prompt_declaration_language
2-
prompt-declaration-language==0.5.0
1+
-e ../..
2+
#prompt-declaration-language==0.5.0

pdl-live-react/src-tauri/src/commands/replay_prep.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
use ::std::env::args;
2+
use ::std::env::current_dir;
23
use ::std::io::Write;
34
use ::std::path::absolute;
45

56
use tempfile::Builder;
67

78
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
89
#[tauri::command]
9-
pub async fn replay_prep(trace: String, name: String) -> Result<(String, String, String), String> {
10+
pub async fn replay_prep(
11+
trace: String,
12+
name: String,
13+
) -> Result<(String, String, String, String), String> {
1014
let mut input = Builder::new()
1115
.prefix(&format!("{}-", name))
1216
.suffix(".pdl")
@@ -30,6 +34,10 @@ pub async fn replay_prep(trace: String, name: String) -> Result<(String, String,
3034
match (input_path.to_str(), output_path.to_str()) {
3135
(Some(inny), Some(outty)) => Ok((
3236
arg0.display().to_string(),
37+
current_dir()
38+
.map_err(|e| e.to_string())?
39+
.display()
40+
.to_string(),
3341
inny.to_string(),
3442
outty.to_string(),
3543
)),

pdl-live-react/src/view/masonry/MasonryCombo.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default function MasonryCombo({ value, setValue }: Props) {
8484
const [modalContent, setModalContent] = useState<null | {
8585
header: string
8686
cmd: string
87+
cwd: string
8788
args?: string[]
8889
onExit?: (exitCode: number) => void
8990
cancelCondVar?: ConditionVariable
@@ -124,12 +125,12 @@ export default function MasonryCombo({ value, setValue }: Props) {
124125
return
125126
}
126127

127-
const [cmd, input, output] = (await invoke("replay_prep", {
128+
const [cmd, cwd, input, output] = (await invoke("replay_prep", {
128129
trace: JSON.stringify(runThisBlock, (k, v) =>
129130
/^pdl__/.test(k) ? undefined : v,
130131
),
131132
name: block.description?.slice(0, 30).replace(/\s/g, "-") ?? "trace",
132-
})) as [string, string, string]
133+
})) as [string, string, string, string]
133134
console.error(`Replaying with cmd=${cmd} input=${input} output=${output}`)
134135

135136
// We need to pass tothe re-execution the original input context
@@ -141,6 +142,7 @@ export default function MasonryCombo({ value, setValue }: Props) {
141142
setModalContent({
142143
header: "Running Program",
143144
cmd,
145+
cwd,
144146
args: [
145147
"run",
146148
...(async ? ["--stream", "none"] : []),
@@ -252,6 +254,7 @@ export default function MasonryCombo({ value, setValue }: Props) {
252254
<Suspense fallback={<div />}>
253255
<RunTerminal
254256
cmd={modalContent?.cmd ?? ""}
257+
cwd={modalContent?.cwd ?? ""}
255258
args={modalContent?.args}
256259
cancel={modalContent?.cancelCondVar}
257260
onExit={onExit}

pdl-live-react/src/view/term/RunTerminal.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ type Props = {
1111
/** The cmd part of `cmd ...args` */
1212
cmd: string
1313

14+
/** The current working directory in which to run `cmd` */
15+
cwd: string
16+
1417
/** The args part of `cmd ...args */
1518
args?: string[]
1619

@@ -21,7 +24,13 @@ type Props = {
2124
cancel?: import("../masonry/condvar").default
2225
}
2326

24-
export default function RunTerminal({ cmd, args = [], onExit, cancel }: Props) {
27+
export default function RunTerminal({
28+
cmd,
29+
cwd,
30+
args = [],
31+
onExit,
32+
cancel,
33+
}: Props) {
2534
const ref = createRef<HTMLDivElement>()
2635
const [term, setTerm] = useState<null | Terminal>(null)
2736
const [exitCode, setExitCode] = useState(-1)
@@ -73,6 +82,7 @@ export default function RunTerminal({ cmd, args = [], onExit, cancel }: Props) {
7382

7483
// spawn shell
7584
const pty = spawn(cmd, args, {
85+
cwd,
7686
cols: term.cols,
7787
rows: term.rows,
7888
})

0 commit comments

Comments
 (0)