-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use subdirectory environments when present - When running or debugging a task, use any discovered environments in subdirectories when present. - Introduce setting to disable this (on by default). * Update extension version --------- Co-authored-by: jjallaire-aisi <[email protected]>
- Loading branch information
1 parent
7fb578b
commit b0517d7
Showing
6 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as fs from "fs"; | ||
import * as os from "os"; | ||
import { existsSync } from "node:fs"; | ||
import path, { join } from "path"; | ||
import { AbsolutePath, toAbsolutePath } from "../path"; | ||
|
||
|
||
export function findEnvPythonPath(startDir: AbsolutePath, baseDir: AbsolutePath): AbsolutePath | null { | ||
let currentDir = startDir; | ||
while (currentDir.path !== baseDir.path) { | ||
|
||
// Look for a pythong environment | ||
const pythonPath = findEnvPython(currentDir); | ||
if (pythonPath) { | ||
return toAbsolutePath(pythonPath); | ||
} | ||
|
||
// Move to the parent directory | ||
currentDir = currentDir.dirname(); | ||
} | ||
|
||
// No Python environment found | ||
return null; | ||
} | ||
|
||
// Helper function to search for Python environment in a given directory | ||
function findEnvPython(directory: AbsolutePath): string | null { | ||
const items = fs.readdirSync(directory.path); | ||
|
||
// Filter only directories and check if any is an environment directory | ||
const envDir = items | ||
.map((item) => path.join(directory.path, item)) | ||
.filter((filePath) => fs.statSync(filePath).isDirectory()) | ||
.find(isEnvDir); | ||
|
||
if (envDir) { | ||
return getPythonPath(envDir); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function getPythonPath(dir: string): string | null { | ||
const pythonSuffixes = os.platform() === "win32" ? ["Scripts/python.exe", "python.exe"] : ["bin/python3", "bin/python"]; | ||
for (const suffix of pythonSuffixes) { | ||
const fullPath = path.join(dir, suffix); | ||
if (fs.existsSync(fullPath)) { | ||
return fullPath; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function isEnvDir(dir: string) { | ||
return existsSync(join(dir, "pyvenv.cfg")) || | ||
existsSync(join(dir, "conda-meta")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
export * from './code'; | ||
export * from './exec'; | ||
export * from './interpreter'; | ||
export * from './interpreter'; | ||
export * from "./env"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters