Skip to content

Conversation

@tkfoss
Copy link
Contributor

@tkfoss tkfoss commented Feb 21, 2025

Motivation

Content

Testing

Please check the following before marking your PR as ready for review

  • I have added tests for my changes
  • I have updated the documentation or added new documentation as needed

@tkfoss tkfoss requested review from a team and codegen-team as code owners February 21, 2025 23:09
@tkfoss tkfoss changed the title Nested package fix [CG-10889] fix: Nested package Feb 21, 2025
@codecov
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files

@tkfoss tkfoss added the Codegen label Feb 21, 2025
@codegen-team
Copy link
Contributor

Overall, this is a solid improvement to the import resolution system. The changes are focused and the test coverage demonstrates the functionality well. A few suggestions for consideration:

  1. Documentation: Consider adding a comment explaining the purpose of the new fallback path (see inline comment)
  2. Test Coverage: Adding a negative test case would help ensure the exclusion logic works as intended (see inline comment)
  3. Performance: The current implementation creates a new string for each split operation. While likely not a performance bottleneck, consider using module_source.partition(".") if you only need the first component.

The changes look good to merge after addressing the documentation suggestion. The test coverage suggestion would be a nice-to-have but isn't blocking.

Copy link
Contributor

@bagel897 bagel897 left a comment

Choose a reason for hiding this comment

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

TLDR

Hmm I feel like this entails us supporting reading pyproject.toml the way we do with tsconfig.json?
IMO #601 is a better approach for that than us hacking it together?

Full comment

For context, python supports resolving imports the following way:

  1. You get a list of paths that comprise PYTHONPATH/sys.path. This generally includes the project root/cwd (as "")
  2. For each path, we do to resolve this import in a given path

We have some implementations for 1:

  1. base_path (our current method to override this manually)
  2. src/test detection (which I believe is standard for packages?)

For this case, we can

  1. Add hacks for individual cases like this PR
  2. Support reading sys.path/PYTHONPATH (#601, my preference)
  3. Set the base_path as needed (current solution)

Thoughts?

EdwardJXLi
EdwardJXLi previously approved these changes Feb 22, 2025
@tkfoss
Copy link
Contributor Author

tkfoss commented Feb 24, 2025

addressed in #601

@tkfoss tkfoss closed this Feb 24, 2025
@tkfoss tkfoss deleted the tom-cg-10889-nested-package-fix branch February 25, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants