-
Notifications
You must be signed in to change notification settings - Fork 14
Add module-level exports via __all__ in package __init__.py files #165
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
Open
abelmilash-msft
wants to merge
7
commits into
main
Choose a base branch
from
users/abelmilash/module-level-exports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5cb9a7a
Add module-level exports via __all__ in package __init__.py files
8b4f454
Fix RelationshipInfo subscript access in relationships example
36da289
Fix remaining RelationshipInfo attribute access in relationships example
01562a2
Add unit tests for operations package-level exports
Copilot 49a27a3
Add export tests for package-level __all__ symbols
691a4e0
Consolidate export tests into single file
5b37c2f
Improve docstrings in test_package_exports.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Spec: Support Module-Level Exports via `__all__` | ||
|
|
||
| ## Goal | ||
|
|
||
| Populate the `__all__` lists in each package-level `__init__.py` so that public symbols | ||
| are re-exported at the package level. Users will be able to import from the package | ||
| namespace directly rather than reaching into submodules. | ||
|
|
||
| **Before:** | ||
| ```python | ||
| from PowerPlatform.Dataverse.models.record import Record | ||
| from PowerPlatform.Dataverse.core.errors import DataverseError | ||
| ``` | ||
|
|
||
| **After:** | ||
| ```python | ||
| from PowerPlatform.Dataverse.models import Record | ||
| from PowerPlatform.Dataverse.core import DataverseError | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Current Status | ||
|
|
||
| `__all__` is already defined in every individual module (e.g. `models/filters.py`, | ||
| `core/errors.py`, `operations/records.py`), but all package-level `__init__.py` files | ||
| have empty exports: | ||
|
|
||
| | Package `__init__.py` | Current `__all__` | | ||
| |---|---| | ||
| | `PowerPlatform.Dataverse.models` | `[]` | | ||
| | `PowerPlatform.Dataverse.operations` | `[]` | | ||
| | `PowerPlatform.Dataverse.core` | `[]` | | ||
| | `PowerPlatform.Dataverse.data` | `[]` | | ||
|
|
||
| --- | ||
|
|
||
| ## The Challenge: Documentation Duplication Risk | ||
|
|
||
| The public API docs on Microsoft Learn are auto-generated from the installed package. | ||
| The concern is that re-exporting a class in `__init__.py` could cause it to appear | ||
| twice in the docs — once at its definition location (e.g. `operations.records.RecordOperations`) | ||
| and again at the package level (e.g. `operations.RecordOperations`). | ||
|
|
||
| **What we need to verify before merging:** | ||
| - [ ] Confirm with the team how the doc pipeline works and run a test build to check | ||
| for duplicate entries. | ||
|
|
||
| --- | ||
|
|
||
| ## What Needs to Change | ||
|
|
||
| ### `models/__init__.py` | ||
| Re-export from: | ||
| - `models.query_builder` → `QueryBuilder`, `QueryParams`, `ExpandOption` | ||
| - `models.filters` → `eq`, `ne`, `gt`, `lt`, `ge`, `le`, `contains`, `startswith`, `endswith`, `filter_in`, `between`, `and_`, `or_`, `not_` | ||
| - `models.batch` → `BatchItemResponse`, `BatchResult` | ||
| - `models.record` → `Record` | ||
| - `models.table_info` → `TableInfo`, `ColumnInfo`, `AlternateKeyInfo` | ||
| - `models.relationship` → `OneToManyRelationship`, `ManyToManyRelationship`, `RelationshipInfo` (etc.) | ||
| - `models.upsert` → `UpsertItem` | ||
| - `models.labels` → `LocalizedLabel`, `Label` | ||
|
|
||
| ### `core/__init__.py` | ||
| Re-export from: | ||
| - `core.errors` → `DataverseError`, `HttpError`, `ValidationError`, `MetadataError`, `SQLParseError` | ||
| - `core.log_config` → `LogConfig` | ||
|
|
||
| ### `operations/__init__.py` | ||
| Re-export from: | ||
| - `operations.records` → `RecordOperations` | ||
| - `operations.tables` → `TableOperations` | ||
| - `operations.query` → `QueryOperations` | ||
| - `operations.batch` → `BatchOperations`, `BatchRecordOperations`, `BatchTableOperations` | ||
| - `operations.dataframe` → `DataFrameOperations` | ||
| - `operations.files` → `FileOperations` | ||
|
|
||
| ### `data/__init__.py` | ||
| No change — all submodules are internal (`_`-prefixed); `__all__` stays empty. | ||
|
|
||
| --- | ||
|
|
||
| ## Benefits | ||
|
|
||
| 1. **Cleaner import paths** — users write `from PowerPlatform.Dataverse.models import Record` | ||
| instead of navigating submodule paths. | ||
|
|
||
| 2. **IDE discoverability** — autocompletion on `PowerPlatform.Dataverse.models.` surfaces | ||
| all public types immediately; users do not need to know submodule names. | ||
|
|
||
| 3. **No broken imports during refactoring** — if we ever rename or reorganise an internal | ||
| submodule, users' import paths stay the same as long as the `__init__.py` re-exports | ||
| are kept. Without this, any internal restructuring is a breaking change for users. | ||
|
|
||
| 4. **Wildcard imports work correctly** — currently `from PowerPlatform.Dataverse.models import *` | ||
| imports nothing, because `__all__ = []`. Once populated, wildcard imports pick up all | ||
| intended public symbols as defined by Python's module documentation. | ||
|
|
||
| 5. **Follows industry convention** — NumPy, pandas, and requests all expose their public | ||
| API at the package level via `__all__` in `__init__.py`. Aligning with this pattern | ||
| makes the SDK feel familiar to experienced Python users. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec lists exports that don't match the current implementation:
models.filtersdoes not defineand_/or_/not_helpers (composition is via&,|,~), and relationship classes are namedOneToManyRelationshipMetadata/ManyToManyRelationshipMetadata(notOneToManyRelationship/ManyToManyRelationship). To avoid confusion for contributors, update this spec section to reflect the actual public symbols (or add the missing helpers/types if they are intended).