Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CG-10889] fix: Nested package #611

Closed
wants to merge 2 commits into from

Conversation

tomcodgen
Copy link
Contributor

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

@tomcodgen tomcodgen requested review from codegen-team and a team as code owners February 21, 2025 23:09
@tomcodgen tomcodgen changed the title Nested package fix [CG-10889] fix: Nested package Feb 21, 2025
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

@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 (Allow custom overrites for package resolving and optional sys.path support #601, my preference)
  3. Set the base_path as needed (current solution)

Thoughts?

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

addressed in #601

@tomcodgen tomcodgen closed this Feb 24, 2025
@tomcodgen tomcodgen 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.

5 participants