|
33 | 33 | TYPESPEC_TEST_DIR = Path("packages/http-client-python/tests") |
34 | 34 | AUTOREST_TEST_DIR = Path("packages/typespec-python/tests") |
35 | 35 |
|
| 36 | +TYPESPEC_DEV_REQUIREMENTS = Path("packages/http-client-python/eng/scripts/ci/dev_requirements.txt") |
| 37 | +AUTOREST_DEV_REQUIREMENTS = Path("packages/typespec-python/dev_requirements.txt") |
| 38 | + |
| 39 | +# Marker indicating where repo-specific content begins in dev_requirements.txt. |
| 40 | +# Everything from this line onward in the autorest file is preserved; everything |
| 41 | +# above is replaced with the upstream content (prefixed by a header comment). |
| 42 | +_DEV_REQUIREMENTS_HEADER = "# shall keep aligned with dev_requirements.txt of @typespec/http-client-python" |
| 43 | +_DEV_REQUIREMENTS_TAIL_MARKER = "# additional dependency needed for development" |
| 44 | + |
36 | 45 | # --- Marker patterns for requirements sync --- |
37 | 46 | # |
38 | 47 | # Convention in requirements files (e.g. azure.txt, unbranded.txt): |
@@ -154,6 +163,46 @@ def sync_requirements(source_dir: Path, target_dir: Path) -> None: |
154 | 163 | print(f" Copied: requirements/{filename}") |
155 | 164 |
|
156 | 165 |
|
| 166 | +# --------------------------------------------------------------------------- |
| 167 | +# dev_requirements.txt sync |
| 168 | +# --------------------------------------------------------------------------- |
| 169 | + |
| 170 | + |
| 171 | +def sync_dev_requirements(source_file: Path, target_file: Path) -> None: |
| 172 | + """Sync upstream dev_requirements.txt, preserving repo-specific tail. |
| 173 | +
|
| 174 | + The target file layout is: |
| 175 | + <header> |
| 176 | + <upstream content> |
| 177 | +
|
| 178 | + # additional dependency needed for development |
| 179 | + <repo-specific deps> <-- preserved from existing target |
| 180 | +
|
| 181 | + Content from the tail marker onward in the existing target is kept; |
| 182 | + everything above is replaced with header + upstream. |
| 183 | + """ |
| 184 | + if not source_file.is_file(): |
| 185 | + print(f" WARNING: {source_file} not found, skipping") |
| 186 | + return |
| 187 | + |
| 188 | + upstream = source_file.read_text(encoding="utf-8").strip() |
| 189 | + |
| 190 | + tail = "" |
| 191 | + if target_file.is_file(): |
| 192 | + existing = target_file.read_text(encoding="utf-8") |
| 193 | + idx = existing.find(_DEV_REQUIREMENTS_TAIL_MARKER) |
| 194 | + if idx >= 0: |
| 195 | + tail = existing[idx:].strip() |
| 196 | + |
| 197 | + content = f"{_DEV_REQUIREMENTS_HEADER}\n{upstream}\n" |
| 198 | + if tail: |
| 199 | + content += f"\n{tail}\n" |
| 200 | + |
| 201 | + target_file.parent.mkdir(parents=True, exist_ok=True) |
| 202 | + target_file.write_text(content, encoding="utf-8", newline="\n") |
| 203 | + print(f" Synced: {target_file.name}") |
| 204 | + |
| 205 | + |
157 | 206 | # --------------------------------------------------------------------------- |
158 | 207 | # Test file sync |
159 | 208 | # --------------------------------------------------------------------------- |
@@ -246,14 +295,21 @@ def main() -> int: |
246 | 295 | autorest_repo / AUTOREST_TEST_DIR / "requirements", |
247 | 296 | ) |
248 | 297 |
|
249 | | - # 3. Sync test files |
| 298 | + # 3. Sync dev_requirements.txt |
| 299 | + print("Syncing dev_requirements.txt...") |
| 300 | + sync_dev_requirements( |
| 301 | + typespec_repo / TYPESPEC_DEV_REQUIREMENTS, |
| 302 | + autorest_repo / AUTOREST_DEV_REQUIREMENTS, |
| 303 | + ) |
| 304 | + |
| 305 | + # 4. Sync test files |
250 | 306 | print("Syncing test files...") |
251 | 307 | sync_test_files( |
252 | 308 | typespec_repo / TYPESPEC_TEST_DIR, |
253 | 309 | autorest_repo / AUTOREST_TEST_DIR, |
254 | 310 | ) |
255 | 311 |
|
256 | | - # 4. Format TypeScript files |
| 312 | + # 5. Format TypeScript files |
257 | 313 | ts_python_dir = autorest_repo / "packages" / "typespec-python" |
258 | 314 | print("Running pnpm format...") |
259 | 315 | result = subprocess.run( |
|
0 commit comments