Skip to content

Commit 547796b

Browse files
Merge pull request #27 from gleanwork/rwjblue/push-krzsqyxxzmyq
docs(restructuring): Update the README for restructuring script
2 parents 895c640 + bfa1881 commit 547796b

File tree

1 file changed

+10
-78
lines changed

1 file changed

+10
-78
lines changed

.github/scripts/README.md

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,120 +3,52 @@
33
This directory contains a script to restructure the glean package from:
44

55
```
6-
src/glean/ # All implementation files
6+
src/glean/ # All implementation files
77
```
88

99
To:
1010

1111
```
12-
src/glean/ # Implicit namespace package (no __init__.py)
12+
src/glean/ # Implicit namespace package (no __init__.py)
1313
src/glean/api_client/ # All implementation files moved here
1414
```
1515

1616
## Usage
1717

18-
### Analyze what would change (recommended first step)
19-
20-
```bash
21-
python scripts/restructure_to_namespace.py --dry-run
22-
```
23-
24-
This shows you:
25-
26-
- Which files would be moved
27-
- Which import statements would be updated
28-
- Current state of the transformation
29-
30-
### Perform the restructuring
31-
3218
```bash
3319
python scripts/restructure_to_namespace.py
3420
```
3521

3622
This script:
3723

38-
- **Detects Speakeasy regeneration** and automatically handles it
24+
- Detects Speakeasy regeneration and automatically handles it
3925
- Creates a backup and moves all files
4026
- Uses implicit namespace packages (no `__init__.py` needed)
4127
- Can be run multiple times safely
4228
- Updates all import statements throughout the codebase
4329

44-
## Smart Speakeasy Integration
30+
## Speakeasy Integration
4531

4632
The script automatically detects when Speakeasy has regenerated files:
4733

4834
1. **First run**: Moves everything to `api_client/`
4935
2. **After Speakeasy regeneration**: Detects new files in `src/glean/`, removes old `api_client/`, and re-runs the transformation
5036
3. **Subsequent runs**: Detects already-transformed structure and skips
5137

52-
This means you can safely run the script as part of your build process!
53-
54-
## Examples
55-
56-
```bash
57-
# First, see what would be changed
58-
python scripts/restructure_to_namespace.py --dry-run
59-
60-
# If it looks good, perform the restructuring
61-
python scripts/restructure_to_namespace.py
62-
63-
# Safe to run multiple times - it will detect and handle various states
64-
python scripts/restructure_to_namespace.py # Skips if already done
65-
python scripts/restructure_to_namespace.py # Auto-detects Speakeasy regeneration
66-
```
67-
6838
## What the restructuring does
6939

7040
1. **Creates a backup** of the current `src/glean` directory
7141
2. **Moves all files** from `src/glean/` to `src/glean/api_client/`
7242
3. **Creates an implicit namespace package** (no `__init__.py` - Python 3.3+ feature)
7343
4. **Updates all import statements** in tests, examples, and internal files
74-
5. **Handles Speakeasy regeneration** automatically
75-
76-
## After restructuring
77-
78-
Users will need to update their imports:
79-
80-
### Before
81-
82-
```python
83-
from glean import Glean, models, errors
84-
from glean.utils import parse_datetime
85-
```
86-
87-
### After
88-
89-
```python
90-
from glean.api_client import Glean, models, errors
91-
from glean.api_client.utils import parse_datetime
92-
```
9344

9445
## Workflow Integration
9546

96-
You can integrate this into your build process:
97-
98-
```bash
99-
# In your build script or CI
100-
speakeasy generate # Regenerates files to src/glean/
101-
python scripts/restructure_to_namespace.py # Automatically detects and re-transforms
102-
```
103-
104-
## Recovery
47+
The repository includes a GitHub Actions workflow (`.github/workflows/patch-speakeasy-pr.yml`) that automatically runs the restructuring script.
10548

106-
If something goes wrong, the script provides the path to the backup directory:
107-
108-
```bash
109-
rm -rf src/glean
110-
cp -r /path/to/backup/glean src/glean
111-
```
112-
113-
## Testing after restructuring
114-
115-
```bash
116-
# Run tests
117-
python -m pytest
118-
119-
# Try importing
120-
python -c "from glean.api_client import Glean; print('Success!')"
121-
```
49+
- **Triggers**: Runs on PRs with "Update SDK - Generate" in the title (Speakeasy PRs) or manual dispatch
50+
- **Process**: Automatically runs the restructuring script when Speakeasy regenerates the SDK
51+
- **Auto-commit**: Commits and pushes the restructured files back to the same PR branch
12252

53+
This means Speakeasy PRs are automatically transformed to the namespace
54+
structure without manual intervention.

0 commit comments

Comments
 (0)