microsoft/python-environment-tools/rust-locator-patterns
Claude Code and agent skill by microsoft/python-environment-tools
- vendor
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
PET (Python Environment Tools) Rust coding conventions: locator ordering, thread safety, platform gating, JSONRPC rules, version detection, and path/symlink handling. Reference when writing or reviewing Rust code in this repo to avoid convention violations that cause review churn.
Install
npx vskill@latest install microsoft/python-environment-tools/rust-locator-patternsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as microsoft/python-environment-tools/rust-locator-patterns.
PET Rust Locator Patterns & Conventions
Domain knowledge for writing correct Rust code in the Python Environment Tools (PET) repository. Following these patterns prevents the most common review feedback and CI failures.
Locator Ordering (CRITICAL)
The order of locators in create_locators() in crates/pet/src/locators.rs determines identification priority. More specific locators MUST come before generic ones.
Priority Chain (required order):
- Windows-specific: Windows Store → Windows Registry → WinPython
- Managed environments: PyEnv → Pixi → Conda
- Virtual envs (specific → generic): Poetry → PipEnv → VirtualEnvWrapper → Venv → VirtualEnv
- macOS-specific: Homebrew → MacXCode → MacCmdLineTools → MacPythonOrg
- Linux fallback: LinuxGlobalPython (MUST BE LAST)
Why it matters: If Venv runs before Poetry, a Poetry environment (which IS a venv) gets misidentified as a plain venv. The first locator whose try_from() returns Some wins.
Environment Identification (try_from)
Each try_from() must be precise enough to avoid false positives:
- Poetry: Match
{project-name}-{8-char-hash}-py{major}.{minor}naming pattern AND verify location is in poetry cache dir - Pipenv: Look for
.projectfile in centralized dir with hash-based naming - Conda: Require
conda-meta/directory with history file - Pixi: Require
.pixi/envs/in path structure - venv: Check for
pyvenv.cfgfile (but many env types have this — venv is a fallback) - VirtualEnv: Activation scripts WITHOUT
pyvenv.cfg(most generic, last resort)
Red flag: A try_from() that only checks pyvenv.cfg existence — that matches ALL venvs, not just one type.
JSONRPC Protocol Rules
The server communicates via stdin/stdout. Any stdout pollution breaks the protocol.
- NEVER use `println!` — it writes to stdout and corrupts JSONRPC messages
- Use
logcrate macros:info!(),trace!(),warn!(),error!() - Log with elapsed time for diagnostic handlers (established pattern)
- All tracing/logging writes to stderr via subscriber configuration
Thread Safety Patterns
PET uses heavy concurrency for parallel discovery:
- Shared state requires
Arc<Mutex<T>>orArc<RwLock<T>> - Keep lock scopes minimal — clone data out, drop lock, then process
- Use
.expect("context")on mutex locks, not bare.unwrap() - No nested locks (deadlock risk)
- Consider
thread::scopefor structured concurrency
Platform-Specific Code
Use #[cfg(...)] attributes for conditional compilation:
Do NOT use `if cfg!(windows) { ... }` for code that imports platform-specific modules — the code inside still gets compiled on all platforms.
Platform Gotchas:
- Windows: Avoid
canonicalize()for directory junctions (breaks Scoop symlinks). Usenorm_case()instead. - macOS: Homebrew has complex symlink chains;
resolve_symlinkbeforecanonicalize - Linux:
/binmay symlink to/usr/bin— handle both
Version Detection (Prefer File-Based)
Order of preference (cheapest first):
pyvenv.cfg—versionorversion_infofieldconda-meta/python-*.json— package metadataInclude/patchlevel.h— CPython source header- Parse from executable path (e.g.,
python3.11) - Spawn Python
--version— LAST RESORT (expensive, defeats PET's purpose)
Path & Symlink Handling
- Use
pet_fs::path::resolve_symlink()— the project's own resolver - For comparison:
canonicalize().unwrap_or(original)thennorm_case()for Windows UNC prefix handling - Preserve original user-facing paths; resolve only for identification
Testing Conventions
- Feature-gated CI tests:
#[cfg_attr(feature = "ci", test)]with#[allow(dead_code)] - Feature flags:
ci,ci-poetry-global,ci-jupyter-container,ci-homebrew-container - Verification pattern: spawn Python, use
try_from(), test symlinks, useresolve - Use
cargo test --features cifor CI-gated tests
Serialization
- All JSON-serialized structs use
#[serde(rename_all = "camelCase")] - Matches the JSONRPC API conventions consumed by VS Code Python extension
Pre-Commit Requirements
Always run before committing:
Never suppress clippy warnings with #[allow(...)] without justification.
Conda-Specific Patterns
- Conda manager detection takes precedence over mamba:
get_conda_manager(path).or_else(|| get_mamba_manager(path)) - Managers reported separately (Conda, Mamba) but environments remain
PythonEnvironmentKind::Conda - Support detection from history files and conda-meta directories
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 29 Jun 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/rust-locator-patterns/SKILL.md
Popularity
- Repository stars
- 208
- Repository forks
- 41
- 7-day trend score
- 27
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 29 Jun 2026, 5 months ago.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/microsoft/python-environment-tools/rust-locator-patterns)