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:
In this repository3 other files it gives its agents.
- rust-coding-skillSkill
- rust-locator-patternsSkill
- rust-precommitSkill
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
- Distinctive: line 53
When adding new environment types:
- Very specific: line 57
Add to locator chain: Update create_locators() in crates/pet/src/locators.rs - ORDER MATTERS
- Very specific: line 58
Platform-specific: Use #[cfg(windows)], #[cfg(unix)], #[cfg(target_os = "macos")]
- Distinctive: line 76
Report immediately: - Use Reporter pattern for async discovery
- Very specific: line 91
Use try_from() with executable to get same info
- Very specific: line 93
Use resolve method for consistency
- Very specific: line 132
Use cargo fetch to download all dependencies
- Very specific: line 133
Use rustup component add clippy to install Clippy linter
- Very specific: line 134
Use cargo fmt --all to format code in all packages
- Very specific: line 135
Use cargo build to build the project
- Very specific: line 136
Use cargo test --all to test all packages (this can take a few seconds)
- Very specific: line 137
Use cargo test [TESTNAME] to test a specific test
- Very specific: line 138
Use cargo test -p [SPEC] to test a specific package
- Very specific: line 139
Use cargo test --all to test all packages
- Very specific: line 153
If clippy reports warnings, fix them before committing.
≈ “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.
Files
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
Locatortrait (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
Reportertrait
Key Architecture Files
crates/pet/src/locators.rs- Ordered locator creation and fallback identification logiccrates/pet/src/find.rs- Multi-threaded environment discovery coordinationcrates/pet-core/src/lib.rs- Core traits and configuration structuresdocs/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 serverFeature-Gated Testing
Tests use feature flags for different environments:
ci- General CI environment testsci-jupyter-container- Jupyter container-specific testsci-homebrew-container- Homebrew container testsci-poetry-*- Poetry-specific test variants
Locator Development Pattern
When adding new environment types:
- Create new crate:
crates/pet-{name}/ - Implement Locator trait: Key methods are
try_from()(identification) andfind()(discovery) - Add to locator chain: Update
create_locators()incrates/pet/src/locators.rs- ORDER MATTERS - 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)
- Avoid spawning processes - Extract info from files/filesystem when possible
- Report immediately - Use Reporter pattern for async discovery
- Complete information - Gather all environment details in one pass, not incrementally
JSONRPC Communication Flow
- Client sends
configurerequest (must be first) - Client sends
refreshrequest to discover environments - Server sends
environmentnotifications as discoveries happen - Optional:
resolverequest for individual Python executables
Testing Verification Pattern
Tests validate discovered environments using 4 verification methods:
- Spawn Python to verify
sys.prefixandsys.version - Use
try_from()with executable to get same info - Test symlink identification
- Use
resolvemethod 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
docs/JSONRPC.md- Understanding the external APIcrates/pet/src/locators.rs- Core architecture patternscrates/pet-core/src/lib.rs- Essential traits and typescrates/pet/tests/ci_test.rs- Comprehensive testing patterns
Scripts
- Use
cargo fetchto download all dependencies - Use
rustup component add clippyto install Clippy linter - Use
cargo fmt --allto format code in all packages - Use
cargo buildto build the project - Use
cargo test --allto 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 --allto 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 warningsIf clippy reports warnings, fix them before committing. Do not use #[allow(...)] attributes to suppress warnings unless absolutely necessary and justified.
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
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.

