Add module-level exports via __all__ in package __init__.py files#165
Open
abelmilash-msft wants to merge 28 commits into
Open
Add module-level exports via __all__ in package __init__.py files#165abelmilash-msft wants to merge 28 commits into
abelmilash-msft wants to merge 28 commits into
Conversation
Populate __all__ in models, core, and operations package __init__.py files so public symbols are importable directly from the package namespace. Update all user-facing examples, README, and skill docs to use the new shorter import paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
RelationshipInfo is a dataclass — use attribute access (.relationship_schema_name, .lookup_schema_name, .relationship_id) instead of dict subscript. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace all remaining .get('Key') dict-style calls with proper
attribute access on RelationshipInfo dataclass fields.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR flattens the public import surface of the Dataverse SDK by adding package-level re-exports via __all__ in models/, core/, and operations/, and updates docs/examples to use the shorter import paths. It also fixes the RelationshipInfo usage in the relationships example to use attribute access instead of dict-style access.
Changes:
- Populate re-export key symbols in
src/PowerPlatform/Dataverse/{models,core,operations}/__init__.py. - Update README and skill/example docs to use package-level imports (e.g.,
from ...models import Record). - Fix
RelationshipInfoexample code to use typed attributes (result.relationship_id, etc.).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/PowerPlatform/Dataverse/operations/init.py | Re-export operation namespaces/classes from the package root. |
| src/PowerPlatform/Dataverse/models/init.py | Re-export key model types/helpers (filters, record, query builder, relationship metadata, etc.). |
| src/PowerPlatform/Dataverse/core/init.py | Re-export config/logging/errors at PowerPlatform.Dataverse.core. |
| src/PowerPlatform/Dataverse/claude_skill/dataverse-sdk-use/SKILL.md | Update documentation examples to use new package-level imports. |
| examples/basic/installation_example.py | Update example imports to use PowerPlatform.Dataverse.operations and PowerPlatform.Dataverse.core. |
| examples/basic/functional_testing.py | Update example imports to use PowerPlatform.Dataverse.models and PowerPlatform.Dataverse.core. |
| examples/advanced/walkthrough.py | Update example imports to use PowerPlatform.Dataverse.models and PowerPlatform.Dataverse.core. |
| examples/advanced/relationships.py | Update imports and fix RelationshipInfo attribute access usage. |
| examples/advanced/alternate_keys_upsert.py | Update example imports to use PowerPlatform.Dataverse.models. |
| docs/spec-module-level-exports.md | Add a spec describing the module-level export goal and rationale. |
| README.md | Update user-facing snippets to use the new package-level imports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/microsoft/PowerPlatform-DataverseClient-Python/sessions/2358d075-c005-43e4-a521-290267f8a424 Co-authored-by: abelmilash-msft <258686066+abelmilash-msft@users.noreply.github.com>
Add test_package_exports.py: 3 tests verifying every symbol in __all__
is importable from PowerPlatform.Dataverse.{core,models,operations}.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Merge Copilot's assertIs identity checks into test_package_exports.py - Add equivalent identity tests for core and models - Remove test_operations_package_exports.py (Copilot's file) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…le-level-exports # Conflicts: # README.md # examples/advanced/walkthrough.py # src/PowerPlatform/Dataverse/models/__init__.py
The inline comments (# batch, # filters, etc.) restate what the import statements above already show. Per repo convention, comments should explain why, not what. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Most build-time tools use pyproject.toml directly, but some legacy documentation generators look for setup.py. The shim reads version from VERSION.txt or PackageVersion env var for build pipelines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Add __all__ to core/config.py for explicit public API - Re-export OperationContext from core package (matches public usage) - Fill identity-check gaps in test_package_exports: covers all 8 core symbols and all 24 models symbols (was 7 and 15) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The doc generator (autoapi/docfx) was creating duplicate documentation pages for every re-exported symbol — one at the original submodule path (e.g. models.record.QueryResult) and one at the package root path (e.g. models.QueryResult). This caused ~17 cross-reference warnings in the Microsoft Learn doc build because xrefs in docstrings became ambiguous between the two paths. Emptying __all__ stops the doc tool from documenting the re-exports while keeping all package-root imports working (Python does not consult __all__ for regular 'from package import Symbol' imports). Tests updated to assert __all__ is empty and to verify each expected symbol is still importable from the package namespace. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cleans up ~17 doc-build warnings caused by short-form, wrong-path, or unresolvable references in docstrings: - operations/records.py: qualify :class:`QueryResult` and :class:`FilterExpression` - operations/batch.py: qualify :attr:`BatchResult.responses` and :class:`FilterExpression`; replace unresolvable :attr: refs to instance attributes with plain backticks - operations/tables.py: fully qualify :attr:`AlternateKeyInfo.status` - models/fetchxml_query.py: correct wrong path (models.fetchxml_query.QueryResult → models.record.QueryResult) - core/log_config.py: qualify :class:`LogConfig` self-reference - client.py: replace reference to private _ODataClient with plain text Combined with the empty __all__ change, expected to reduce Microsoft Learn doc-build warnings from 38 to ~4 (the remaining 4 are auto-generated :mod: references to models.record in toc.yml that need a doc-repo-side fix). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
These files were experimental scaffolding for doc-generation testing that is no longer needed for the PR's scope. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change :meth: cross-references to plain backtick formatting for the 'build' method. The doc tool was failing to resolve :meth:`build` and :meth:`QueryBuilder.build` because 'build' is defined on the private '_QueryBuilderBase' parent class — autoapi/docfx can't link to private classes. Plain backticks (``build()``) render the same in HTML but skip cross-reference resolution. Expected impact on Microsoft Learn doc build: 3 warnings -> 0 or 1 (the only potentially remaining warning is the auto-generated 'inherits from _QueryBuilderBase' reference in QueryBuilder's page, which can only be eliminated by renaming the private class). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nd examples Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reverts the over-flattening of error imports from commit 0146b6b. Error class names like MetadataError, HttpError, ValidationError are better imported from the .errors submodule because the namespace itself conveys semantic information (this is an exception class). This matches the convention of major Python SDKs: - azure.core.exceptions.HttpResponseError - requests.exceptions.HTTPError - aiohttp.web.HTTPException Non-error imports (DataverseConfig, LogConfig) remain at the package level since 'core' is the meaningful namespace for those. 8 locations updated across 7 files: examples/{basic,advanced}/*.py, README.md, and claude_skill/dataverse-sdk-use/SKILL.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous commit (4a9aacb) accidentally included 6 CSV files from examples/advanced/prodev_output/ and examples/advanced/risk_assessment_output/, which are generated outputs from running the example scripts — not source artifacts. Removing them and adding the output directories to .gitignore to prevent recurrence. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Keep the CSV file removal but drop the .gitignore additions per user preference. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Re-exports are now declared in each package's __all__ list: - top-level: DataverseClient, __version__, col, raw, DataverseModel, QueryResult (added DataverseClient; the 4 GA convenience symbols remain) - core: 8 symbols (DataverseConfig, OperationContext, all 5 errors, LogConfig) - models: 24 symbols - operations: 13 symbols Why: analysis of the original 60-warning doc-build report showed warnings were caused by three independent root causes: 1. External pandas refs (~22) - fixed by doc-repo xrefmap_custom.yml 2. Docstring bugs (~17) - fixed by earlier commits qualifying :class: refs 3. Re-export amplification (~21) - doubled the docstring bugs above Now that root causes 1 and 2 are resolved, restoring __all__ no longer amplifies any warnings. The latest docfx report shows 3 warnings (all since fixed) and no duplicate-target warnings. Top-level __init__.py also adds DataverseClient (the primary entry point, matching 'from openai import OpenAI' / 'from anthropic import Anthropic' SDK conventions). Tests updated to assert exact __all__ contents per package (catches accidental drift). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dundant noqa - models/filters.py + operations/query.py: revert docstring example imports back to '.models.filters import col' (no need to update docs to use the shorter form when both work) - __init__.py: remove '# noqa: E402' markers. Ruff has a built-in exemption for dunder assignments (__version__, __all__) appearing before imports, so E402 is never flagged. Verified with 'ruff check --select E402'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
User feedback: the import changes in README.md and SKILL.md are enough.
Example scripts can stay with their original (main) import style.
8 files reverted to main's content:
- examples/advanced/{alternate_keys_upsert,dataframe_operations,datascience_risk_assessment,
prodev_quick_start,relationships,walkthrough}.py
- examples/basic/{functional_testing,installation_example}.py
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Commit 1404b92 ("Revert example script import changes") was intended to only revert the 8 example files to main's content. But stale staged content from an earlier ruff investigation also got committed, silently reverting 12 src/ files back to main's state and removing our PR's: - __all__ lists in core/__init__.py, models/__init__.py, operations/__init__.py - DataverseClient at top-level Dataverse/__init__.py - Docstring xref qualifications in batch.py, records.py, query_builder.py, etc. - __version__ ordering / circular-import workaround - SKILL.md import path updates This commit restores all 12 src/ files to the state from 2a377b3 (the last good state before 1404b92). Net effect: PR's src/ changes are intact again. The 8 example reverts from 1404b92 remain (as intended). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
__all__inmodels/,core/, andoperations/package__init__.pyfiles so users can import directly from the top-level package instead of navigating submodule paths.RelationshipInfodict-style access bugs inrelationships.pyexampleBefore / After