agentleFS
MicrosoftKnown publishermicrosoft/python-environment-tools/.github/copilot-instructions.md

python-environment-tools

Copilot instructions207 starsChanged 10 months agoMITView on GitHub

This is a high-performance Rust-based tool for discovering Python environments and virtual environments. It operates as a JSONRPC server consumed by the VS Code Python extension to avoid spawning Python processes repeatedly. Tests use feature flags for different environments: When adding new environment types: Example structure: Tests validate discovered environments using 4 verification methods:

The file

Show its rules and text

We split this copilot-instructions.md into the rules it gives an agent

15 rules. About 0 are common, 2 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When adding new environment types:

    line 53
  2. Very specific:

    Add to locator chain: Update create_locators() in crates/pet/src/locators.rs - ORDER MATTERS

    line 57
  3. Very specific:

    Platform-specific: Use #[cfg(windows)], #[cfg(unix)], #[cfg(target_os = "macos")]

    line 58
  4. Distinctive:

    Report immediately: - Use Reporter pattern for async discovery

    line 76
  5. Very specific:

    Use try_from() with executable to get same info

    line 91
  6. Very specific:

    Use resolve method for consistency

    line 93
  7. Very specific:

    Use cargo fetch to download all dependencies

    line 132
  8. Very specific:

    Use rustup component add clippy to install Clippy linter

    line 133
  9. Very specific:

    Use cargo fmt --all to format code in all packages

    line 134
  10. Very specific:

    Use cargo build to build the project

    line 135
  11. Very specific:

    Use cargo test --all to test all packages (this can take a few seconds)

    line 136
  12. Very specific:

    Use cargo test [TESTNAME] to test a specific test

    line 137
  13. Very specific:

    Use cargo test -p [SPEC] to test a specific package

    line 138
  14. Very specific:

    Use cargo test --all to test all packages

    line 139
  15. Very specific:

    If clippy reports warnings, fix them before committing.

    line 153

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

Python Environment Tools (PET) - AI Coding Agent Instructions

Project Overview

This is a high-performance Rust-based tool for discovering Python environments and virtual environments. It operates as a JSONRPC server consumed by the VS Code Python extension to avoid spawning Python processes repeatedly.

Architecture

Core Concepts

  • Locators: Modular environment discovery components implementing the Locator trait (crates/pet-core/src/lib.rs)
  • JSONRPC Server: Main communication interface (crates/pet/src/jsonrpc.rs) with stdio/stdout protocol
  • Environment Types: 15+ supported Python installations (Conda, Poetry, PyEnv, Homebrew, Windows Store, etc.)
  • Reporter Pattern: Asynchronous environment discovery reporting via the Reporter trait

Key Architecture Files

  • crates/pet/src/locators.rs - Ordered locator creation and fallback identification logic
  • crates/pet/src/find.rs - Multi-threaded environment discovery coordination
  • crates/pet-core/src/lib.rs - Core traits and configuration structures
  • docs/JSONRPC.md - Complete API specification with TypeScript interfaces

Development Workflow

Building & Testing

# Standard build
cargo build

# Release build (optimized for performance)
cargo build --release

# Run tests with specific CI features
cargo test --features ci
cargo test --features ci-poetry-global

# Run JSONRPC server
./target/debug/pet server

Feature-Gated Testing

Tests use feature flags for different environments:

  • ci - General CI environment tests
  • ci-jupyter-container - Jupyter container-specific tests
  • ci-homebrew-container - Homebrew container tests
  • ci-poetry-* - Poetry-specific test variants

Locator Development Pattern

When adding new environment types:

  1. Create new crate: crates/pet-{name}/
  2. Implement Locator trait: Key methods are try_from() (identification) and find() (discovery)
  3. Add to locator chain: Update create_locators() in crates/pet/src/locators.rs - ORDER MATTERS
  4. Platform-specific: Use #[cfg(windows)], #[cfg(unix)], #[cfg(target_os = "macos")]

Example structure:

impl Locator for MyLocator {
    fn get_kind(&self) -> LocatorKind { LocatorKind::MyType }
    fn supported_categories(&self) -> Vec<PythonEnvironmentKind> { vec![PythonEnvironmentKind::MyType] }
    fn try_from(&self, env: &PythonEnv) -> Option<PythonEnvironment> { /* identification logic */ }
    fn find(&self, reporter: &dyn Reporter) { /* discovery logic */ }
}

Critical Patterns

Performance Principles (from crates/pet/README.md)

  1. Avoid spawning processes - Extract info from files/filesystem when possible
  2. Report immediately - Use Reporter pattern for async discovery
  3. Complete information - Gather all environment details in one pass, not incrementally

JSONRPC Communication Flow

  1. Client sends configure request (must be first)
  2. Client sends refresh request to discover environments
  3. Server sends environment notifications as discoveries happen
  4. Optional: resolve request for individual Python executables

Testing Verification Pattern

Tests validate discovered environments using 4 verification methods:

  1. Spawn Python to verify sys.prefix and sys.version
  2. Use try_from() with executable to get same info
  3. Test symlink identification
  4. Use resolve method for consistency

Environment-Specific Notes

Conda Environments

  • Supports detection from history files and conda-meta directories
  • Manager detection via spawning conda executable in background threads
  • Complex prefix/name relationships for base vs named environments

Poetry Environments

  • Hash-based environment naming: {project-name}-{hash}-py
  • Project-specific virtual environments in configured cache directories
  • Configuration hierarchy: local poetry.toml → global config

Platform Differences

  • Windows: Registry + Windows Store detection, different path separators
  • macOS: Xcode Command Line Tools, python.org, Homebrew paths
  • Linux: Global system paths (/usr/bin, /usr/local/bin)

Common Gotchas

  • Locator order matters in create_locators() - more specific before generic
  • Thread safety - Heavy use of Arc/Mutex for concurrent discovery
  • Feature flags - Many tests only run with specific CI features enabled
  • Path canonicalization - Symlink resolution varies by platform
  • Caching - Optional cache directory for expensive operations (conda spawning)

Files to Read First

  1. docs/JSONRPC.md - Understanding the external API
  2. crates/pet/src/locators.rs - Core architecture patterns
  3. crates/pet-core/src/lib.rs - Essential traits and types
  4. crates/pet/tests/ci_test.rs - Comprehensive testing patterns

Scripts

  • Use cargo fetch to download all dependencies
  • Use rustup component add clippy to install Clippy linter
  • Use cargo fmt --all to format code in all packages
  • Use cargo build to build the project
  • Use cargo test --all to test all packages (this can take a few seconds)
  • Use cargo test [TESTNAME] to test a specific test
  • Use cargo test -p [SPEC] to test a specific package
  • Use cargo test --all to test all packages

Required Before Committing

ALWAYS run these commands before committing any Rust code changes:

# Format all code (required)
cargo fmt --all

# Run clippy with warnings as errors (required)
cargo clippy --all -- -D warnings

If clippy reports warnings, fix them before committing. Do not use #[allow(...)] attributes to suppress warnings unless absolutely necessary and justified.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.