Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

The _get_default_schema_path() method used hardcoded parent.parent.parent traversal to find the project root, breaking when directory structure changes.

Changes

Robust project root detection:

  • Search upward for pyproject.toml marker file (primary method)
  • Fallback to D4D_PROJECT_ROOT environment variable
  • Max depth limit (30 levels) prevents runaway searches

Improved error handling:

  • List both attempted schema paths (data_sheets_schema_all.yaml and data_sheets_schema.yaml)
  • Include starting directory in error messages
  • Clear guidance on using environment variable fallback

Code quality:

  • Module-level imports (os moved from method scope)
  • Use os.getenv() per Python conventions
  • Clarifying comments for filesystem root detection

Example

# Before: Fragile and breaks if structure changes
project_root = self.prompts_dir.parent.parent.parent

# After: Robust marker-based search
project_root = self._find_project_root(self.prompts_dir, marker_file="pyproject.toml")
if project_root is None:
    env_root = os.getenv('D4D_PROJECT_ROOT')
    # ... fallback logic

The new _find_project_root() method walks up the directory tree until finding pyproject.toml, working from any nesting depth.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 9, 2025 20:47
…r search

- Implement _find_project_root() to search upward for pyproject.toml
- Add D4D_PROJECT_ROOT environment variable fallback
- Improve error messages with actionable guidance
- Works from any directory nesting depth
- All tests pass (marker search, env var, error handling, depth independence)

Co-authored-by: realmarcin <[email protected]>
… messages

- Move os import to module level (better Python convention)
- Prioritize marker file search over env var (env var is true fallback)
- Improve error message to list both schema paths attempted
- All validation tests still pass

Co-authored-by: realmarcin <[email protected]>
- Use os.getenv() instead of os.environ.get() (Python convention)
- Include starting path in error message for better debugging
- Add max_depth parameter (default 30) to prevent infinite loops
- All tests pass with improvements

Co-authored-by: realmarcin <[email protected]>
Copilot AI changed the title [WIP] Update prompt explore PR based on review feedback Replace fragile parent traversal with marker-based project root detection Dec 9, 2025
Copilot AI requested a review from realmarcin December 9, 2025 20:55
@realmarcin realmarcin marked this pull request as ready for review December 10, 2025 07:58
Base automatically changed from prompt-explore to main December 10, 2025 07:59
@realmarcin realmarcin merged commit 947e363 into main Dec 10, 2025
9 checks passed
@realmarcin realmarcin deleted the copilot/sub-pr-99 branch December 10, 2025 08:00
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.

2 participants