MCPcopy Index your code
hub / github.com/deepnote/deepnote / detectVenvRoot

Function detectVenvRoot

packages/runtime-core/src/python-env.ts:153–164  ·  view source on GitHub ↗

* Detects the virtual environment root for a given Python executable path. * * Checks for `pyvenv.cfg` which is the standard marker for Python venvs. * Handles both `/path/to/venv/bin/python` and `/path/to/venv/Scripts/python.exe`. * * @returns The venv root directory, or null if the Python is

(pythonExecutable: string)

Source from the content-addressed store, hash-verified

151 * @returns The venv root directory, or null if the Python is not in a venv
152 */
153async function detectVenvRoot(pythonExecutable: string): Promise<string | null> {
154 const binDir = dirname(pythonExecutable)
155 const possibleVenvRoot = dirname(binDir)
156
157 const pyvenvCfg = join(possibleVenvRoot, 'pyvenv.cfg')
158 const cfgStat = await stat(pyvenvCfg).catch(() => null)
159 if (cfgStat?.isFile()) {
160 return possibleVenvRoot
161 }
162
163 return null
164}
165
166/**
167 * Builds environment variables appropriate for the resolved Python executable.

Callers 1

buildPythonEnvFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected