|
1 | 1 | # Maintainers Guide |
2 | 2 |
|
3 | | -See the [Makefile](./Makefile) if you need to install and test locally. Just type `make` to get the help. |
| 3 | +See the [Makefile](./Makefile) if you need to install and test locally. Just type `make` to get the help. |
| 4 | + |
| 5 | +## 🔧 Build Pipeline and File Preservation |
| 6 | + |
| 7 | +### OpenAPI Client Generation |
| 8 | + |
| 9 | +The field-manager-python-client is automatically generated from OpenAPI specifications using `openapi-python-client`. To ensure custom code is preserved during regeneration: |
| 10 | + |
| 11 | +#### ✅ Files That Are Preserved |
| 12 | +- `field_manager_python_client/auth.py` - **Custom authentication module** |
| 13 | +- `field_manager_python_client/__init__.py` - **Preserved through custom template** |
| 14 | + |
| 15 | +#### ⚠️ Files That Are Regenerated |
| 16 | +- All files in `field_manager_python_client/api/` |
| 17 | +- All files in `field_manager_python_client/models/` |
| 18 | +- `field_manager_python_client/client.py` |
| 19 | +- `field_manager_python_client/errors.py` |
| 20 | +- `field_manager_python_client/types.py` |
| 21 | + |
| 22 | +### Custom Template System |
| 23 | + |
| 24 | +The build system uses custom templates in the `templates/` directory: |
| 25 | + |
| 26 | +- `templates/package_init.py.jinja` - **Ensures auth imports are preserved in __init__.py** |
| 27 | +- `templates/pyproject.toml.jinja` - Package metadata template |
| 28 | +- `templates/README.md.jinja` - Package README template |
| 29 | + |
| 30 | +### Generation Process |
| 31 | + |
| 32 | +```bash |
| 33 | +# Full regeneration process |
| 34 | +make generate |
| 35 | + |
| 36 | +# This runs: |
| 37 | +# 1. Download latest OpenAPI spec |
| 38 | +# 2. Extract version info |
| 39 | +# 3. Generate client code with custom templates |
| 40 | +# 4. Preserve auth.py and custom __init__.py imports |
| 41 | +``` |
| 42 | + |
| 43 | +### ✅ Verification After Generation |
| 44 | + |
| 45 | +After running `make generate`, verify these files are preserved: |
| 46 | + |
| 47 | +```bash |
| 48 | +# Check auth module exists |
| 49 | +ls -la field-manager-python-client/field_manager_python_client/auth.py |
| 50 | + |
| 51 | +# Check __init__.py includes auth imports |
| 52 | +grep -n "from .auth import" field-manager-python-client/field_manager_python_client/__init__.py |
| 53 | + |
| 54 | +# Should show lines like: |
| 55 | +# from .auth import authenticate, get_test_client, get_prod_client, TokenManager |
| 56 | +``` |
| 57 | + |
| 58 | +## 📚 Examples Directory Management |
| 59 | + |
| 60 | +### Structure |
| 61 | +``` |
| 62 | +examples/ |
| 63 | +├── setup.py # Automated setup script |
| 64 | +├── requirements.txt # Dependencies with version switching |
| 65 | +├── README.md # Comprehensive documentation |
| 66 | +├── QUICKSTART.md # 5-minute setup guide |
| 67 | +├── output/ # Git-ignored output directory |
| 68 | +├── examples/ # Example scripts |
| 69 | +└── venv/ # Git-ignored virtual environment |
| 70 | +``` |
| 71 | + |
| 72 | +### Key Features |
| 73 | +- **Virtual environment based**: No more Poetry complexity |
| 74 | +- **Version switching**: Easy toggle between published/local package |
| 75 | +- **Output management**: All outputs go to `output/` directory (git-ignored) |
| 76 | +- **Automated setup**: `python setup.py` handles everything |
| 77 | + |
| 78 | +### Adding New Examples |
| 79 | + |
| 80 | +1. **Create the example** in `examples/examples/` |
| 81 | +2. **Use new authentication**: `from field_manager_python_client import get_test_client` |
| 82 | +3. **Save outputs** to `output/` directory using `Path("output")` |
| 83 | +4. **Document clearly** with comments and error handling |
| 84 | +5. **Test with both** published and local package versions |
| 85 | + |
| 86 | +## 🚀 Release Process |
| 87 | + |
| 88 | +### 1. Pre-Release Checks |
| 89 | +```bash |
| 90 | +# Ensure auth.py is preserved |
| 91 | +make generate |
| 92 | +git status # auth.py should be unchanged |
| 93 | + |
| 94 | +# Test examples work |
| 95 | +cd examples |
| 96 | +python setup.py --local |
| 97 | +source venv/bin/activate |
| 98 | +python examples/ex_organizations_new_auth.py |
| 99 | +``` |
| 100 | + |
| 101 | +### 2. Version Update |
| 102 | +- OpenAPI client version is auto-extracted from `openapi.json` |
| 103 | +- Update package version if needed in `config.yaml` |
| 104 | + |
| 105 | +### 3. Examples Testing |
| 106 | +```bash |
| 107 | +cd examples |
| 108 | +# Test with published version |
| 109 | +python setup.py |
| 110 | +source venv/bin/activate |
| 111 | +python examples/ex_organizations_new_auth.py |
| 112 | + |
| 113 | +# Test with local version |
| 114 | +python setup.py --local |
| 115 | +python examples/ex_organizations_new_auth.py |
| 116 | +``` |
| 117 | + |
| 118 | +## 🔐 Authentication System |
| 119 | + |
| 120 | +### Architecture |
| 121 | +The authentication is now integrated into the main package: |
| 122 | + |
| 123 | +- **Module**: `field_manager_python_client/auth.py` |
| 124 | +- **Exports**: `authenticate`, `get_test_client`, `get_prod_client`, `TokenManager` |
| 125 | +- **Environment configs**: Built-in for test/prod |
| 126 | +- **Token management**: Automatic caching and refresh |
| 127 | + |
| 128 | +### Preservation Strategy |
| 129 | +The `auth.py` file is **NOT** generated by openapi-python-client, so it's naturally preserved. The `__init__.py` imports are preserved through the custom template `templates/package_init.py.jinja`. |
| 130 | + |
| 131 | +## 🐛 Troubleshooting |
| 132 | + |
| 133 | +### Auth Module Missing After Generation |
| 134 | +```bash |
| 135 | +# Check if auth.py exists |
| 136 | +ls field-manager-python-client/field_manager_python_client/auth.py |
| 137 | + |
| 138 | +# If missing, restore from git |
| 139 | +git checkout field-manager-python-client/field_manager_python_client/auth.py |
| 140 | +``` |
| 141 | + |
| 142 | +### Missing Auth Imports in __init__.py |
| 143 | +```bash |
| 144 | +# Check custom template |
| 145 | +cat templates/package_init.py.jinja |
| 146 | + |
| 147 | +# Regenerate with custom template |
| 148 | +make generate |
| 149 | +``` |
| 150 | + |
| 151 | +### Examples Not Working |
| 152 | +```bash |
| 153 | +cd examples |
| 154 | +# Clean reinstall |
| 155 | +rm -rf venv |
| 156 | +python setup.py |
| 157 | +``` |
| 158 | + |
| 159 | +## 🔄 Continuous Integration |
| 160 | + |
| 161 | +### Pipeline Considerations |
| 162 | +1. **Test auth preservation**: Verify `auth.py` unchanged after generation |
| 163 | +2. **Test examples**: Run examples with both published and local packages |
| 164 | +3. **Version compatibility**: Ensure examples work with current package version |
| 165 | + |
| 166 | +### Recommended CI Steps |
| 167 | +```bash |
| 168 | +# 1. Generate and verify preservation |
| 169 | +make generate |
| 170 | +git diff --exit-code field-manager-python-client/field_manager_python_client/auth.py |
| 171 | + |
| 172 | +# 2. Test examples setup |
| 173 | +cd examples && python setup.py --skip-test |
| 174 | + |
| 175 | +# 3. Test auth imports |
| 176 | +python -c "from field_manager_python_client import authenticate; print('OK')" |
| 177 | +``` |
0 commit comments