Skip to content

Poetry: Environment name regex pattern could be more precise #334

@karthiknadig

Description

@karthiknadig

Problem

The regex pattern used to identify Poetry environments by name is slightly permissive and could potentially match non-Poetry environments.

Current Code

// pet-poetry/src/lib.rs L32
static ref POETRY_ENV_NAME_PATTERN: Regex = Regex::new(r"^.+-[A-Za-z0-9_-]{8}-py.*$")

Issue

Poetry uses a specific naming convention: {name}-{8-char-hash}-py{major}.{minor}

The current pattern:

  1. Uses py.*$ which would match py, pyxyz, py3, etc.
  2. Should be more specific to match py{major}.{minor} format

Expected Pattern

Poetry's actual naming pattern creates names like:

  • myproject-AbCdEf12-py3.10
  • demo-project-XyZ78901-py3.11

A more precise pattern would be:

r"^.+-[A-Za-z0-9_-]{8}-py\d+\.\d+$"

Impact

Low - but could cause false positives in edge cases where a non-Poetry virtualenv happens to have a name matching the loose pattern.

Affected File

crates/pet-poetry/src/lib.rs

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugneeds PR

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions