Skip to content

fix(package-resolver): return .py file for flat single-file packages instead of site-packages dir - #1586

Merged
Shashankss1205 merged 3 commits into
CodeGraphContext:mainfrom
AloysJehwin:fix/package-resolver-flat-module
Aug 8, 2026
Merged

Shashankss1205 merged 3 commits into
CodeGraphContext:mainfrom
AloysJehwin:fix/package-resolver-flat-module

Conversation

@AloysJehwin

Copy link
Copy Markdown
Contributor

Fixes #1528

_get_python_package_path was returning module_file.parent for every non-stdlib, non-__init__.py module. For flat single-file packages like six.py and typing_extensions.py, the parent is site-packages itself — so add_package_to_graph would launch build_graph_from_path_async on the entire dependency tree.

The fix adds a guard: if the parent directory is named site-packages or dist-packages, return the file directly instead of its parent. Normal namespace packages (with their own subdirectory) are unaffected.

Added two regression tests. Both pass.

…instead of site-packages dir

Signed-off-by: Aloys Jehwin <[email protected]>
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@AloysJehwin is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

sys.path.insert of an absolute /home/<user>/... path only works on the
machine it was written on, and shadows the package under test everywhere
else. The repo's own venv already puts src on the path.

@Shashankss1205 Shashankss1205 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally: trial-merged with #1580, #1583, #1590 and #1591 — full suite green (1153 passed, 7 skipped).

Correct fix for #1528, and the narrow guard is the right call: special-casing only site-packages/dist-packages fixes the dangerous case without changing how ordinary packages resolve.

six                  -> .../site-packages/six.py              # was site-packages/
typing_extensions    -> .../site-packages/typing_extensions.py
packaging            -> .../site-packages/packaging           # unchanged
neo4j                -> .../site-packages/neo4j               # unchanged

One change I pushed to your branch rather than bouncing it back: the test had

sys.path.insert(0, '/home/aloysjehwin/CodeGraphContext/src')

That only works on your machine, and on any other it shadows the package under test with whatever happens to be at that path. Removed — the repo's venv already puts src on the path, and the test passes without it. Everything else is yours. Thanks!

@Shashankss1205
Shashankss1205 merged commit fb52998 into CodeGraphContext:main Aug 8, 2026
16 of 17 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Aug 8, 2026
Shashankss1205 added a commit that referenced this pull request Aug 8, 2026
Ten PRs since 0.5.6 — mostly parser correctness, all with regression tests.

Parsers
- Ruby nested classes no longer delete their parent; method parameters
  extracted at all (#1523, #1527, #1581)
- C/C++ functions returning a pointer or reference are extracted, and
  registered in pre_scan so they resolve as call targets (#1524, #1582)
- C# fields and locals parsed, restoring receiver-type inference for
  `var x = new T(); x.M();` (#1525, #1584)
- JavaScript destructured, array and rest parameters extracted, recording
  the binding names rather than a placeholder (#1527, #1591)

Queries and analysis
- Five defects that returned wrong answers without erroring: inflated
  repository stats, misattributed callers, discarded graph_name,
  count(*) after OPTIONAL MATCH, an ignored tool argument (#1577)
- Dead-code detection made correct and self-consistent, including the
  JS module-level false positive (#600, #1559, #1578)

Indexing
- add_package_to_graph on a flat module no longer indexes the whole
  virtualenv (#1528, #1586)
- SCIP job progress no longer exceeds 100% (#1535, #1583)

Docs and tests
- Database Options table columns realigned (#1590)
- MCP tool definition contract validation (#1580)

Co-authored-by: Claude Fable 5 <[email protected]>
@Shashankss1205 Shashankss1205 added gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:clean GSSoC quality: x1.2 contributor / +5 mentor type:bug GSSoC type bonus: bug labels Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:clean GSSoC quality: x1.2 contributor / +5 mentor type:bug GSSoC type bonus: bug

Projects

Status: Done

2 participants