diff options
Diffstat (limited to 'extension/src/activation')
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 99 | 
1 files changed, 60 insertions, 39 deletions
| diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 7a0d24d4..928fe04b 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -53,6 +53,7 @@ async function retryThenFail(            break;        }      } finally { +      console.log("After retries, failed to set up Continue extension", msg);        vscode.window.showErrorMessage(msg);      } @@ -232,57 +233,77 @@ async function getLinuxAptInstallError(pythonCmd: string) {    return `[Important] Continue needs to create a Python virtual environment, but python3.${version}-venv is not installed. Please run this command in your terminal: \`${installVenvCommand}\`, reload VS Code, and then try again.`;  } -async function setupPythonEnv() { -  console.log("Setting up python env for Continue extension..."); - -  const [pythonCmd, pipCmd] = await getPythonPipCommands(); -  const [activateCmd, pipUpgradeCmd] = getActivateUpgradeCommands( -    pythonCmd, -    pipCmd -  ); +async function createPythonVenv(pythonCmd: string) { +  if (checkEnvExists()) { +    console.log("Python env already exists, skipping..."); +  } else { +    // Assemble the command to create the env +    const createEnvCommand = [ +      `cd "${serverPath()}"`, +      `${pythonCmd} -m venv env`, +    ].join(" ; "); -  await retryThenFail(async () => { -    // First, create the virtual environment -    if (checkEnvExists()) { -      console.log("Python env already exists, skipping..."); +    const [stdout, stderr] = await runCommand(createEnvCommand); +    if ( +      stderr && +      stderr.includes("running scripts is disabled on this system") +    ) { +      console.log("Scripts disabled error when trying to create env"); +      await vscode.window.showErrorMessage(WINDOWS_REMOTE_SIGNED_SCRIPTS_ERROR); +      throw new Error(stderr); +    } else if ( +      stderr?.includes("On Debian/Ubuntu systems") || +      stdout?.includes("On Debian/Ubuntu systems") +    ) { +      const msg = await getLinuxAptInstallError(pythonCmd); +      console.log(msg); +      await vscode.window.showErrorMessage(msg); +    } else if (checkEnvExists()) { +      console.log("Successfully set up python env at ", `${serverPath()}/env`);      } else { -      // Assemble the command to create the env -      const createEnvCommand = [ -        `cd "${serverPath()}"`, -        `${pythonCmd} -m venv env`, -      ].join(" ; "); - -      const [stdout, stderr] = await runCommand(createEnvCommand); -      if ( -        stderr && -        stderr.includes("running scripts is disabled on this system") -      ) { -        await vscode.window.showErrorMessage( -          WINDOWS_REMOTE_SIGNED_SCRIPTS_ERROR -        ); -        throw new Error(stderr); -      } else if ( -        stderr?.includes("On Debian/Ubuntu systems") || -        stdout?.includes("On Debian/Ubuntu systems") -      ) { -        const msg = await getLinuxAptInstallError(pythonCmd); -        console.log(msg); -        await vscode.window.showErrorMessage(msg); -      } else if (checkEnvExists()) { -        console.log( -          "Successfully set up python env at ", -          `${serverPath()}/env` +      try { +        // This might mean that another window is currently using the python.exe file to install requirements +        // So we want to wait and try again +        let i = 0; +        await new Promise((resolve, reject) => +          setInterval(() => { +            if (i > 5) { +              reject(); +            } +            if (checkEnvExists()) { +              resolve(null); +            } else { +              console.log("Waiting for other window to create env..."); +            } +            i++; +          }, 5000)          ); -      } else { +      } catch (e) {          const msg = [            "Python environment not successfully created. Trying again. Here was the stdout + stderr: ",            `stdout: ${stdout}`,            `stderr: ${stderr}`, +          `e: ${e}`,          ].join("\n\n");          console.log(msg);          throw new Error(msg);        }      } +  } +} + +async function setupPythonEnv() { +  console.log("Setting up python env for Continue extension..."); + +  const [pythonCmd, pipCmd] = await getPythonPipCommands(); +  const [activateCmd, pipUpgradeCmd] = getActivateUpgradeCommands( +    pythonCmd, +    pipCmd +  ); + +  await retryThenFail(async () => { +    // First, create the virtual environment +    await createPythonVenv(pythonCmd);      // Install the requirements      if (await checkRequirementsInstalled()) { | 
