Skip to content

fix: autodetect src layouts without overriding explicit search paths - #222

Merged
chrapkowski-sg merged 4 commits into
sourcegraph:scipfrom
dreddnafious:enable-auto-search-paths
Nov 2, 2026
Merged

chrapkowski-sg merged 4 commits into
sourcegraph:scipfrom
dreddnafious:enable-auto-search-paths

Conversation

@dreddnafious

@dreddnafious dreddnafious commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #221.

Enable automatic src search-path detection for projects without explicit search-path configuration. An unconfigured layout such as this must connect imports to their definitions:

demo/
├── pyproject.toml       # project name/version
├── src/demo/__init__.py
├── src/demo/core.py     # def handler(): ...
└── tests/test_core.py   # from demo.core import handler

Without the fallback, definitions can use src.demo.core while imports fail to resolve demo.core. With it, definitions and the two imported/runtime references share demo.core/handler()..

Configuration behavior

Apply autodetection after configuration initialization, only when both default extra paths and execution environments are absent. Preserve explicit extraPaths, including [], and execution-environment search order. Even a root-only execution environment conservatively suppresses this fallback. A src directory containing __init__.py remains a package rather than an automatic search root.

The original report compared newer upstream Pyright 1.1.411 with scip-python. This change uses the vendored API and deliberately does not copy newer CLI behavior unconditionally: prepending src can otherwise shadow explicitly configured environment paths.

Verification

  • Added real-indexing cases for absent/empty configuration, explicit custom paths, competing execution-environment paths, explicit empty paths, and src/__init__.py.
  • Assert imported/runtime references resolve to the expected definitions, not merely that indexing succeeds.
  • Regenerated the two existing snapshots whose module identities intentionally lose the src. prefix.
  • Production/development builds, all 21 snapshots, all 7 SCIP Jest tests, and formatting passed locally on Linux with Node 24.4.1 and Python 3.10.22. Native Windows/macOS execution was not performed locally.

dreddnafious and others added 2 commits July 26, 2026 22:48
pyright's own CLI sets `autoSearchPaths = true` unconditionally
("Always enable autoSearchPaths when using the command line",
pyright-internal/src/common/configOptions.ts consumer in pyright.ts).
scip-python replaces that entry point and never sets the field, so
`commandLineOptions.autoSearchPaths || false` is always false and
ensureDefaultExtraPaths() never adds ./src.

The effect is silent: for a src-layout project with no [tool.pyright]
section, definitions are emitted under `src.pkg.mod` while imports
resolve to `pkg.mod`, so every reference from outside src/ is dropped
from the index. The run exits 0 and the index is simply smaller.

An explicit extraPaths still takes precedence, so projects that already
configure pyright are unaffected.

Fixes sourcegraph#221

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chrapkowski-sg chrapkowski-sg changed the title Enable autoSearchPaths to match pyright's CLI fix: autodetect src layouts without overriding explicit search paths Nov 2, 2026
@chrapkowski-sg
chrapkowski-sg merged commit 77cace4 into sourcegraph:scip Nov 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-package references silently dropped in src-layout projects (autoSearchPaths is never enabled)

2 participants