Skip to content

Conversation

@peekxc
Copy link
Contributor

@peekxc peekxc commented Nov 13, 2024

This PR prioritizes the supplied source directory in the sys.path.

Currently, the source directory of the Builder instance, when supplied, is appended to sys.path:

def build(self, filter: str = "*"):
    ...
    if self.source_dir:
	import sys
        sys.path.append(self.source_dir)

I think the source directory should come first:

def build(self, filter: str = "*"):
    ...
    if self.source_dir:
	import sys
        if sys.path[0] != self.source_dir:
            sys.path.insert(0, self.source_dir)

By inserting itself into the first position in the path, module imports from the given source directory are prioritized over other modules. In particular, if one has a source file that happens to share the same name with another file also in the path (e.g. random, trace, collections, etc.), this change ensures quartodoc/griffe picks the package-level module over a base module.

For me, this fixes griffe-related resolution issues that arise from mixing relative imports with editable installs (#323).

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2024

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.68%. Comparing base (ee4fa3c) to head (d209710).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
quartodoc/autosummary.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
- Coverage   88.78%   88.68%   -0.10%     
==========================================
  Files          37       37              
  Lines        3004     3005       +1     
==========================================
- Hits         2667     2665       -2     
- Misses        337      340       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@machow
Copy link
Owner

machow commented Dec 8, 2025

Hey, sorry for taking so long to get back to this -- I think if source directory modules take precedence over base modules, this will produce a behavior that doesn't occur when people install e.g. via pip.

For example, if you have a warnings module in your source directory, then this would prioritize that over the built-in module. However, that behavior could screw up how packages importing base warnings operate, and be hard to debug.

I could be misunderstanding -- please don't hesitate to re-raise and flag anything I missed

@machow machow closed this Dec 8, 2025
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.

3 participants