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

[BUG] [VSCode Extension] Can't run with powershell & whitespace in project name #3839

Open
gukoff opened this issue Nov 1, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@gukoff
Copy link

gukoff commented Nov 1, 2024

Describe the bug

Fails to run when:

  • default shell on both Windows and VSCode is powershell
  • directory with Python virtualenv contains a whitespace in hte path

How To Reproduce the bug

  1. Set powershell as the default shell
  2. Create a new project in the directory with name a b c. Create virtualenv in that directory, install promptflot tooling in this venv.
  3. Try to open PF extension and do anything: create a connection or run a flow. It will fail with the following error:
(base) PS C:\Users\username\a b c\flows\tagging> cd "c:\Users\username\a b c\flows\tagging"
(base) PS C:\Users\username\a b c\flows\tagging> "c:\Users\username\a b c\.venv\Scripts\python.exe" -m promptflow._cli._pf.entry flow test --flow "c:\Users\username\a b c\flows\tagging" --user-agent "prompt-flow-extension/1.20.2 (win32; x64) VSCode/1.95.0"
At line:1 char:69
+ ... \username\a b c\.venv\Scripts\python.exe" -m promptf ...
+                                                                ~~
Unexpected token '-m' in expression or statement.
At line:1 char:72
+ ... a b c\.venv\Scripts\python.exe" -m promptflow._cli._pf.entry flow te ...
+                                         ~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'promptflow._cli._pf.entry' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Additional context

When the path to the Python interpreter contains a whitespace, the extension encloses the whole path in double quotes.

Unlike in the other shells, powershell can't properly parse it when the full path to the executable is passed as a string.

Unminified extension code (see below) suggests that the double quotes aren't added by the extension itself. Either child_process.spawn adds them before calling the child process, or pythonExtensionApi.environments.getActiveEnvironmentPath().path already returns a path with the double quotes.

Either way, to call Python in powershell, one must not enclose the full path to the executable in double quotes. More precisely, you can't start the path to the executable with a double quote.


function getPythonPath () {
  if (!this.pythonExtensionApi)
    throw new Error('Python extension is not activated')
  return vZ(
    this.pythonExtensionApi.environments.getActiveEnvironmentPath().path
  )
}
function getPfutilCommand (e) {
  return `${this.getPythonPath()} ${this.pfutilPyPath} ${e.map(vZ).join(' ')}`
}
function getPfCommand (e, r = !1, i = !0) {
  let s = [...e, ...(i ? ['--user-agent', Far] : [])]
  return r
    ? [this.getPythonPath(), '-m', 'promptflow._cli._pf.entry', ...s.map(vZ)]
    : `${this.getPythonPath()} -m promptflow._cli._pf.entry ${s
        .map(vZ)
        .join(' ')}`
}


async function runTest (e, r) {
  let i = new Date().getTime(),
    s = (await Promise.resolve().then(() => hi(fb()))).stringify({
      ...this.flowTestData,
      name: `${this.flowTestData.name}_${i}`
    }),
    c = `${i}_batch_run_create.yaml`,
    h = ZN.Uri.joinPath(ZN.Uri.file(aOn.default.tmpdir()), 'bulkTest', c)
  await ZN.workspace.fs.writeFile(h, Buffer.from(s))
  let v = Xm.getPfCommand(
      ['run', 'create', '--stream', '--file', h.fsPath],
      !0
    ),
    S = this.getTestFileType(e)
  return await new Promise((M, j) => {
    let G = (0, iOn.spawn)(v[0], v.slice(1), { cwd: this.getTestCwd(S) }),
    ...
@gukoff gukoff added the bug Something isn't working label Nov 1, 2024
@gukoff gukoff changed the title [BUG] [VSCode Extension] [BUG] [VSCode Extension] Can't run when powershell is default shell, and there's a whitespace in project name Nov 1, 2024
@gukoff gukoff changed the title [BUG] [VSCode Extension] Can't run when powershell is default shell, and there's a whitespace in project name [BUG] [VSCode Extension] Can't run with powershell & whitespace in project name Nov 4, 2024
Copy link

github-actions bot commented Dec 4, 2024

Hi, we're sending this friendly reminder because we haven't heard back from you in 30 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 7 days of this comment, the issue will be automatically closed. Thank you!

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue/pull request label Dec 4, 2024
@gukoff
Copy link
Author

gukoff commented Dec 4, 2024

Ping?

@github-actions github-actions bot removed the no-recent-activity There has been no recent activity on this issue/pull request label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant