-
Notifications
You must be signed in to change notification settings - Fork 5
feat!: Migrate imports from glean to glean.api_client
#23
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
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Restructuring Script | ||
|
|
||
| This directory contains a script to restructure the glean package from: | ||
|
|
||
| ``` | ||
| src/glean/ # All implementation files | ||
| ``` | ||
|
|
||
| To: | ||
|
|
||
| ``` | ||
| src/glean/ # Implicit namespace package (no __init__.py) | ||
| src/glean/api_client/ # All implementation files moved here | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Analyze what would change (recommended first step) | ||
|
|
||
| ```bash | ||
| python scripts/restructure_to_namespace.py --dry-run | ||
| ``` | ||
|
|
||
| This shows you: | ||
|
|
||
| - Which files would be moved | ||
| - Which import statements would be updated | ||
| - Current state of the transformation | ||
|
|
||
| ### Perform the restructuring | ||
|
|
||
| ```bash | ||
| python scripts/restructure_to_namespace.py | ||
| ``` | ||
|
|
||
| This script: | ||
|
|
||
| - **Detects Speakeasy regeneration** and automatically handles it | ||
| - Creates a backup and moves all files | ||
| - Uses implicit namespace packages (no `__init__.py` needed) | ||
| - Can be run multiple times safely | ||
| - Updates all import statements throughout the codebase | ||
|
|
||
| ## Smart Speakeasy Integration | ||
|
|
||
| The script automatically detects when Speakeasy has regenerated files: | ||
|
|
||
| 1. **First run**: Moves everything to `api_client/` | ||
| 2. **After Speakeasy regeneration**: Detects new files in `src/glean/`, removes old `api_client/`, and re-runs the transformation | ||
| 3. **Subsequent runs**: Detects already-transformed structure and skips | ||
|
|
||
| This means you can safely run the script as part of your build process! | ||
|
|
||
| ## Examples | ||
|
|
||
| ```bash | ||
| # First, see what would be changed | ||
| python scripts/restructure_to_namespace.py --dry-run | ||
|
|
||
| # If it looks good, perform the restructuring | ||
| python scripts/restructure_to_namespace.py | ||
|
|
||
| # Safe to run multiple times - it will detect and handle various states | ||
| python scripts/restructure_to_namespace.py # Skips if already done | ||
| python scripts/restructure_to_namespace.py # Auto-detects Speakeasy regeneration | ||
| ``` | ||
|
|
||
| ## What the restructuring does | ||
|
|
||
| 1. **Creates a backup** of the current `src/glean` directory | ||
| 2. **Moves all files** from `src/glean/` to `src/glean/api_client/` | ||
| 3. **Creates an implicit namespace package** (no `__init__.py` - Python 3.3+ feature) | ||
| 4. **Updates all import statements** in tests, examples, and internal files | ||
| 5. **Handles Speakeasy regeneration** automatically | ||
|
|
||
| ## After restructuring | ||
|
|
||
| Users will need to update their imports: | ||
|
|
||
| ### Before | ||
|
|
||
| ```python | ||
| from glean import Glean, models, errors | ||
| from glean.utils import parse_datetime | ||
| ``` | ||
|
|
||
| ### After | ||
|
|
||
| ```python | ||
| from glean.api_client import Glean, models, errors | ||
| from glean.api_client.utils import parse_datetime | ||
| ``` | ||
|
|
||
| ## Workflow Integration | ||
|
|
||
| You can integrate this into your build process: | ||
|
|
||
| ```bash | ||
| # In your build script or CI | ||
| speakeasy generate # Regenerates files to src/glean/ | ||
| python scripts/restructure_to_namespace.py # Automatically detects and re-transforms | ||
| ``` | ||
|
|
||
| ## Recovery | ||
|
|
||
| If something goes wrong, the script provides the path to the backup directory: | ||
|
|
||
| ```bash | ||
| rm -rf src/glean | ||
| cp -r /path/to/backup/glean src/glean | ||
| ``` | ||
|
|
||
| ## Testing after restructuring | ||
|
|
||
| ```bash | ||
| # Run tests | ||
| python -m pytest | ||
|
|
||
| # Try importing | ||
| python -c "from glean.api_client import Glean; print('Success!')" | ||
| ``` | ||
|
|
||
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.