Skip to content

Pyrefly 1.0.0 does not auto-detect project-root .venv when .venv is a symlink #3458

@iotakappa

Description

@iotakappa

Summary

Pyrefly finds the project root correctly, but does not auto-detect a local project .venv. It falls back to /usr/local/bin/python3 and the wrong site-packages unless VIRTUAL_ENV is set explicitly.

This was observed with a uv project, but the issue appears to be about .venv discovery rather than uv itself.

Environment

  • Pyrefly: 1.0.0
  • VS Code extension: meta.pyrefly-1.0.0-darwin-arm64
  • OS: macOS
  • Project uses a local .venv created by uv
  • Python in .venv: 3.13.2

Project layout

prestanda/
├─ pyproject.toml
├─ repricer.py
└─ .venv/
   ├─ bin/python
   ├─ bin/python3
   └─ pyvenv.cfg

pyproject.toml contains a normal [project] section and no [tool.pyrefly] override.

Reproduction

From the project root:

~/.vscode/extensions/meta.pyrefly-1.0.0-darwin-arm64/bin/pyrefly dump-config repricer.py

Actual result

Pyrefly reports the correct project root, but uses the system interpreter:

Default configuration for project root marked by `/Users/mb/workspace/Documents-python/prestanda/pyproject.toml`
  Using interpreter: /usr/local/bin/python3
  Resolving imports from:
    Import root (inferred from project layout): "/Users/mb/workspace/Documents-python/prestanda"
    Site package path queried from interpreter: ["/Users/mb/Library/Python/3.9/lib/python/site-packages", "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages"]

This causes missing import errors for packages that are installed only in .venv.

Control experiment

If VIRTUAL_ENV is set, Pyrefly uses the local .venv correctly:

cd /Users/mb/workspace/Documents-python/prestanda
VIRTUAL_ENV="$PWD/.venv" ~/.vscode/extensions/meta.pyrefly-1.0.0-darwin-arm64/bin/pyrefly dump-config repricer.py

Result:

Using interpreter: /Users/mb/workspace/Documents-python/prestanda/.venv/bin/python3
Site package path queried from interpreter: ["/Users/mb/workspace/Documents-python/prestanda/.venv/lib/python3.13/site-packages"]

Expected result

Pyrefly should auto-detect the project-root .venv without requiring:

  • VIRTUAL_ENV to be set, or
  • an explicit python-interpreter-path override

Additional notes

The project path is symlinked/canonicalized on this machine:

  • logical path: /Users/mb/workspace/Documents-python/prestanda
  • resolved path: /Users/mb/Documents/python/prestanda

The local virtual environment is also a symlink:

  • .venv -> ../../../venv/prestanda
  • resolved venv path: /Users/mb/venv/prestanda

However, .venv exists in both the logical and resolved project root, and Pyrefly still falls back to /usr/local/bin/python3 unless VIRTUAL_ENV is set.

Pyrefly also works when the interpreter is passed explicitly via the symlinked path:

~/.vscode/extensions/meta.pyrefly-1.0.0-darwin-arm64/bin/pyrefly dump-config --python-interpreter-path .venv/bin/python3 repricer.py

Result:

Using interpreter: .venv/bin/python3
Site package path queried from interpreter: ["/Users/mb/Documents/python/prestanda/.venv/lib/python3.13/site-packages"]

That suggests the interpreter itself is usable through the symlink, and the failure is specifically in auto-discovery of the project-root .venv.

Minimal control experiment

I also reproduced this outside the project with two minimal throwaway projects that differed only in whether .venv was a real directory or a symlink.

Real .venv project:

/tmp/pyrefly-venv-check-real/
├─ pyproject.toml
├─ app.py
└─ .venv/                  # real directory created with python3 -m venv

Symlinked .venv project:

/tmp/pyrefly-venv-check-link/
├─ pyproject.toml
├─ app.py
└─ .venv -> /tmp/pyrefly-venv-check-real/.venv

Running Pyrefly against the real .venv project:

cd /tmp/pyrefly-venv-check-real
~/.vscode/extensions/meta.pyrefly-1.0.0-darwin-arm64/bin/pyrefly dump-config app.py

Result:

Using interpreter: /private/tmp/pyrefly-venv-check-real/.venv/bin/python3
Site package path queried from interpreter: ["/private/tmp/pyrefly-venv-check-real/.venv/lib/python3.9/site-packages"]

Running Pyrefly against the symlinked .venv project:

cd /tmp/pyrefly-venv-check-link
~/.vscode/extensions/meta.pyrefly-1.0.0-darwin-arm64/bin/pyrefly dump-config app.py

Result:

Using interpreter: /usr/local/bin/python3
Site package path queried from interpreter: ["/Users/mb/Library/Python/3.9/lib/python/site-packages", "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages"]

This makes the issue reproducible without uv, without the VS Code workspace path symlink, and without any project-specific dependencies. The deciding factor appears to be whether .venv itself is a symlink.

That may or may not be relevant, but it could help narrow down the root cause.

Metadata

Metadata

Assignees

Labels

configurationhelp wantedLarger than "good first issue", but still well-defined and ready for someone to pick up

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions