python-manager-discovery

द्वारा microsoft

पर्यावरण प्रबंधक-विशिष्ट खोज पैटर्न और ज्ञात समस्याएँ। conda, poetry, pipenv, pyenv,… के लिए पर्यावरण खोज कोड पर काम करते या समीक्षा करते समय उपयोग करें।

npx skills add https://github.com/microsoft/vscode-python-environments --skill python-manager-discovery

Environment Manager Discovery Patterns

This skill documents manager-specific discovery patterns, environment variable precedence, and known issues.

Manager Quick Reference

ManagerConfig FilesCache LocationKey Env Vars
Poetrypoetry.toml, pyproject.toml, config.tomlPlatform-specificPOETRY_VIRTUALENVS_IN_PROJECT, POETRY_CACHE_DIR
PipenvPipfile, Pipfile.lockXDG or WORKON_HOMEWORKON_HOME, XDG_DATA_HOME
Pyenv.python-version, versions/~/.pyenv/ or pyenv-winPYENV_ROOT, PYENV_VERSION
Condaenvironment.yml, conda-meta/Registries + pathsCONDA_PREFIX, CONDA_DEFAULT_ENV
venvpyvenv.cfgIn-projectNone

Poetry

Discovery Locations

Virtualenvs cache (default):

  • Windows: %LOCALAPPDATA%\pypoetry\Cache\virtualenvs
  • macOS: ~/Library/Caches/pypoetry/virtualenvs
  • Linux: ~/.cache/pypoetry/virtualenvs

In-project (when enabled):

  • .venv/ in project root

Config Precedence (highest to lowest)

  1. Local config: poetry.toml in project root
  2. Environment variables: POETRY_VIRTUALENVS_*
  3. Global config: ~/.config/pypoetry/config.toml

Known Issues

IssueDescriptionFix
{cache-dir} placeholderNot resolved in paths from configResolve placeholder before use
Wrong default pathWindows/macOS differ from LinuxUse platform-specific defaults
In-project detectionPOETRY_VIRTUALENVS_IN_PROJECT must be checkedCheck env var first, then config

Code Pattern

async function getPoetryVirtualenvsPath(): Promise<string> {
    // 1. Check environment variable first
    const envVar = process.env.POETRY_VIRTUALENVS_PATH;
    if (envVar) return envVar;

    // 2. Check local poetry.toml
    const localConfig = await readPoetryToml(projectRoot);
    if (localConfig?.virtualenvs?.path) {
        return resolvePoetryPath(localConfig.virtualenvs.path);
    }

    // 3. Use platform-specific default
    return getDefaultPoetryCache();
}

function resolvePoetryPath(configPath: string): string {
    // Handle {cache-dir} placeholder
    if (configPath.includes('{cache-dir}')) {
        const cacheDir = getDefaultPoetryCache();
        return configPath.replace('{cache-dir}', cacheDir);
    }
    return configPath;
}

Pipenv

Discovery Locations

Default:

  • Linux: ~/.local/share/virtualenvs/ (XDG_DATA_HOME)
  • macOS: ~/.local/share/virtualenvs/
  • Windows: ~\.virtualenvs\

When WORKON_HOME is set:

  • Use $WORKON_HOME/ directly

Environment Variables

VarPurpose
WORKON_HOMEOverride virtualenv location
XDG_DATA_HOMEBase for Linux default
PIPENV_VENV_IN_PROJECTCreate .venv/ in project

Known Issues

IssueDescriptionFix
Missing WORKON_HOME supportEnv var not checkedRead env var before defaults
Missing XDG_DATA_HOME supportNot used on LinuxCheck XDG spec

Code Pattern

function getPipenvVirtualenvsPath(): string {
    // Check WORKON_HOME first
    if (process.env.WORKON_HOME) {
        return process.env.WORKON_HOME;
    }

    // Check XDG_DATA_HOME on Linux
    if (process.platform === 'linux') {
        const xdgData = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');
        return path.join(xdgData, 'virtualenvs');
    }

    // Windows/macOS defaults
    return path.join(os.homedir(), '.virtualenvs');
}

PyEnv

Discovery Locations

Unix:

  • ~/.pyenv/versions/ (default)
  • $PYENV_ROOT/versions/ (if PYENV_ROOT set)

Windows (pyenv-win):

  • %USERPROFILE%\.pyenv\pyenv-win\versions\
  • Different directory structure than Unix!

Key Differences: Unix vs Windows

AspectUnixWindows (pyenv-win)
Commandpyenvpyenv.bat
Root~/.pyenv/%USERPROFILE%\.pyenv\pyenv-win\
Shims~/.pyenv/shims/%USERPROFILE%\.pyenv\pyenv-win\shims\

Known Issues

IssueDescriptionFix
path.normalize() vs path.resolve()Windows drive letter missingUse path.resolve() on both sides
Wrong command on WindowsLooking for pyenv instead of pyenv.batCheck for .bat extension

Code Pattern

function getPyenvRoot(): string {
    if (process.env.PYENV_ROOT) {
        return process.env.PYENV_ROOT;
    }

    if (process.platform === 'win32') {
        // pyenv-win uses different structure
        return path.join(os.homedir(), '.pyenv', 'pyenv-win');
    }

    return path.join(os.homedir(), '.pyenv');
}

function getPyenvVersionsPath(): string {
    const root = getPyenvRoot();
    return path.join(root, 'versions');
}

// Use path.resolve() for comparisons!
function comparePyenvPaths(pathA: string, pathB: string): boolean {
    return path.resolve(pathA) === path.resolve(pathB);
}

Conda

Discovery Locations

Environment locations:

  • Base install envs/ directory
  • ~/.conda/envs/
  • Paths in ~/.condarc envs_dirs

Windows Registry:

  • HKCU\Software\Python\ContinuumAnalytics\
  • HKLM\SOFTWARE\Python\ContinuumAnalytics\

Shell Activation

ShellActivation Command
bash, zshsource activate envname
fishconda activate envname (NOT source!)
PowerShellconda activate envname
cmdactivate.bat envname

Known Issues

IssueDescriptionFix
Fish shell activationUses bash-style commandUse fish-compatible syntax
Registry pathsMay be stale/invalidVerify paths exist
Base vs named envsDifferent activationCheck if activating base

Code Pattern

function getCondaActivationCommand(shell: ShellType, envName: string): string {
    switch (shell) {
        case 'fish':
            // Fish uses different syntax!
            return `conda activate ${envName}`;
        case 'cmd':
            return `activate.bat ${envName}`;
        case 'powershell':
            return `conda activate ${envName}`;
        default:
            // bash, zsh
            return `source activate ${envName}`;
    }
}

venv

Discovery

Identification:

  • Look for pyvenv.cfg file in directory
  • Contains home and optionally version keys

Version Extraction Priority

  1. version field in pyvenv.cfg
  2. Parse from home path (e.g., Python311)
  3. Spawn Python executable (last resort)

Code Pattern

async function getVenvVersion(venvPath: string): Promise<string | undefined> {
    const cfgPath = path.join(venvPath, 'pyvenv.cfg');

    try {
        const content = await fs.readFile(cfgPath, 'utf-8');
        const lines = content.split('\n');

        for (const line of lines) {
            const [key, value] = line.split('=').map((s) => s.trim());
            if (key === 'version') {
                return value;
            }
        }

        // Fall back to parsing home path
        const homeLine = lines.find((l) => l.startsWith('home'));
        if (homeLine) {
            const home = homeLine.split('=')[1].trim();
            const match = home.match(/(\d+)\.(\d+)/);
            if (match) {
                return `${match[1]}.${match[2]}`;
            }
        }
    } catch {
        // Config file not found or unreadable
    }

    return undefined;
}

PET Server (Native Finder)

JSON-RPC Communication

The PET server is a Rust-based locator that communicates via JSON-RPC over stdio.

Known Issues

IssueDescriptionFix
No timeoutJSON-RPC can hang foreverAdd Promise.race with timeout
Silent spawn errorsExtension continues without envsSurface spawn errors to user
Resource leaksWorker pool not cleaned upDispose on deactivation
Type guard missingResponse types not validatedAdd runtime type checks
Cache key collisionPaths normalize to same keyUse consistent normalization

Code Pattern

async function fetchFromPET<T>(method: string, params: unknown): Promise<T> {
    const timeout = 30000; // 30 seconds

    const result = await Promise.race([
        this.client.request(method, params),
        new Promise<never>((_, reject) => setTimeout(() => reject(new Error('PET server timeout')), timeout)),
    ]);

    // Validate response type
    if (!isValidResponse<T>(result)) {
        throw new Error(`Invalid response from PET: ${JSON.stringify(result)}`);
    }

    return result;
}

microsoft की और Skills

oss-growth
microsoft
OSS ग्रोथ हैकर व्यक्तित्व
agent-framework-azure-ai-py
microsoft
Microsoft Agent Framework Python SDK (agent-framework-azure-ai) का उपयोग करके Azure AI Foundry एजेंट बनाएं। AzureAIAgentsProvider के साथ स्थायी एजेंट बनाते समय, होस्टेड टूल्स (कोड इंटरप्रेटर, फ़ाइल खोज, वेब खोज) का उपयोग करते समय, MCP सर्वर एकीकृत करते समय, वार्तालाप थ्रेड प्रबंधित करते समय, या स्ट्रीमिंग प्रतिक्रियाएँ लागू करते समय उपयोग करें। फ़ंक्शन टूल्स, संरचित आउटपुट और मल्टी-टूल एजेंट शामिल हैं।
development
airunway-aks-setup
microsoft
AI Runway को AKS पर सेट करें — बेयर क्लस्टर से चल रहे मॉडल तक। इसमें क्लस्टर सत्यापन, कंट्रोलर इंस्टॉल, GPU मूल्यांकन, प्रोवाइडर सेटअप, और पहली डिप्लॉयमेंट शामिल है। कब: "setup AI Runway", "onboard AKS cluster", "install AI Runway", "airunway setup", "deploy model to AKS", "GPU inference on AKS", "KAITO setup on AKS", "run LLM on AKS", "vLLM on AKS", "set up model serving on AKS", "AI Runway controller"।
devops
appinsights-instrumentation
microsoft
Azure Application Insights के साथ वेबऐप्स को इंस्ट्रूमेंट करने के लिए मार्गदर्शन। टेलीमेट्री पैटर्न, SDK सेटअप, और कॉन्फ़िगरेशन संदर्भ प्रदान करता है। WHEN: ऐप को कैसे इंस्ट्रूमेंट करें, App Insights SDK, टेलीमेट्री पैटर्न, App Insights क्या है, Application Insights मार्गदर्शन, इंस्ट्रूमेंटेशन उदाहरण, APM सर्वोत्तम अभ्यास।
devops
applicationinsights-web-ts
microsoft
ब्राउज़र/वेब ऐप्स को Application Insights JavaScript SDK (@microsoft/applicationinsights-web) से इंस्ट्रूमेंट करें। Real User Monitoring (RUM) के लिए उपयोग करें — पेज व्यू, क्लिक, AJAX/fetch निर्भरताएँ, अपवाद, कस्टम इवेंट, और बैकएंड OpenTelemetry ट्रेस से सहसंबंधित ब्राउज़र-साइड GenAI एजेंट ट्रेस। SDK Loader Script और npm सेटअप, फ्रेमवर्क एक्सटेंशन (React, React Native, Angular), Click Analytics, टेलीमेट्री इनिशियलाइज़र, और ब्राउज़र से उत्सर्जित एजेंट/टूल/मॉडल स्पैन के लिए OTel GenAI सिमेंटिक कन्वेंशन शामिल हैं।
devops
azure-ai-anomalydetector-java
microsoft
Azure AI Anomaly Detector SDK for Java के साथ एनोमली डिटेक्शन एप्लिकेशन बनाएं। यूनीवेरिएट/मल्टीवेरिएट एनोमली डिटेक्शन, टाइम-सीरीज़ विश्लेषण, या AI-संचालित मॉनिटरिंग लागू करते समय उपयोग करें।
development
azure-ai-language-conversations-py
microsoft
<text> azure-ai-language-conversations Python SDK का उपयोग करके संवादात्मक भाषा समझ (CLU) लागू करें। ConversationAnalysisClient के साथ काम करते समय उपयोग करें ताकि वार्तालाप के इरादे और संस्थाओं का विश्लेषण किया जा सके, NLP सुविधाएँ बनाई जा सकें, या अनुप्रयोगों में भाषा समझ को एकीकृत किया जा सके। </text>
development
azure-ai-ml-py
microsoft
Azure Machine Learning SDK v2 for Python। ML वर्कस्पेस, जॉब्स, मॉडल, डेटासेट, कंप्यूट और पाइपलाइन के लिए उपयोग करें। ट्रिगर्स: "azure-ai-ml", "MLClient", "workspace", "model registry", "training jobs", "datasets"।
development