Skip to content

Fix namespace parsing to correctly discover package namespaces instead of simple string replacement #41942

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

Merged
merged 5 commits into from
Jul 9, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 8, 2025

The namespace parsing in parse_pyproject and parse_setup_py functions was using a naive approach of simply replacing - with . in package names to determine namespaces. This approach fails for packages with complex namespace structures.

For example, the package azure-eventhub-checkpointstoreblob has:

  • Package name: azure-eventhub-checkpointstoreblob
  • Actual namespace: azure.eventhub.extensions.checkpointstoreblob
  • Incorrect simple replacement: azure.eventhub.checkpointstoreblob

Changes Made

  1. Added discover_namespace() function - Walks through the package directory structure to find __init__.py files and discovers the actual namespace by examining the module hierarchy
  2. Added _set_root_namespace() helper - Determines if an __init__.py file contains substantial content vs just namespace extension calls (like extend_path)
  3. Updated parse_pyproject() - Now uses namespace discovery before falling back to simple string replacement
  4. Updated parse_setup_py() - Enhanced metapackage handling to also use namespace discovery
  5. Comprehensive test coverage - Added tests for the specific issue case, edge cases, and fallback scenarios

Validation Results

  • azure-eventhub-checkpointstoreblob now correctly resolves to azure.eventhub.extensions.checkpointstoreblob
  • ✅ Backward compatibility maintained for packages where simple replacement was already correct
  • ✅ All existing tests pass (14/14 tests passing)
  • ✅ Both setup.py and pyproject.toml parsing paths work correctly
  • ✅ Graceful fallback when namespace discovery fails

The implementation follows the logic provided in the issue description and ensures robust namespace discovery while maintaining backward compatibility.

Fixes #41941.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] mime api-view-parser namespace parsing in azure-sdk-tools Fix namespace parsing to correctly discover package namespaces instead of simple string replacement Jul 8, 2025
@Copilot Copilot AI requested a review from scbedd July 8, 2025 18:19
Copilot finished work on behalf of scbedd July 8, 2025 18:19
Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
@Copilot Copilot AI requested a review from scbedd July 8, 2025 18:31
Copilot finished work on behalf of scbedd July 8, 2025 18:31
…n review

Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
Copilot finished work on behalf of scbedd July 8, 2025 18:38
Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
@Copilot Copilot AI requested a review from scbedd July 8, 2025 20:54
Copilot finished work on behalf of scbedd July 8, 2025 20:54
@scbedd scbedd marked this pull request as ready for review July 8, 2025 20:58
@scbedd scbedd requested a review from mccoyp as a code owner July 8, 2025 20:58
Copy link
Member

@scbedd scbedd left a comment

Choose a reason for hiding this comment

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

LGTM now.

@scbedd scbedd merged commit fb1ac9e into main Jul 9, 2025
27 checks passed
@scbedd scbedd deleted the copilot/fix-41941 branch July 9, 2025 23:18
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.

mime api-view-parser namespace parsing in azure-sdk-tools
3 participants