From 87cb7454bb0478c5b5c8b7a5cae19c1ee902223e Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 3 Jun 2026 03:57:47 +0000 Subject: [PATCH 1/2] only keep legacy code path for some folders instead of all --- .../eng/scripts/ci/regenerate-common.ts | 20 +++++++++++++++---- .../generator/pygen/preprocess/__init__.py | 15 ++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts index 5e6b2b9ed88..0822ab16aa8 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts @@ -716,15 +716,27 @@ export async function prepareBaselineOfGeneratedCode(generatedFolder: string): P run(`git fetch --depth 1 origin ${branch}`); run(`git checkout FETCH_HEAD`); + const legacyCodePathNeededForTests = [ + "azure/authentication/api-key", + "unbranded/authentication/api-key", + "azure/authentication-union", + "azure/generation-subdir", + "azure/generation-subdir2", + "unbranded/generation-subdir", + "unbranded/generation-subdir2", + ]; + const sourceRoot = join(tempDir, ...sourceSubdir.split("/")); - for (const flavor of ["azure", "unbranded"]) { - const src = join(sourceRoot, flavor); - const dest = join(testsGeneratedDir, flavor); + for (const subPath of legacyCodePathNeededForTests) { + const segments = subPath.split("/"); + const src = join(sourceRoot, ...segments); + const dest = join(testsGeneratedDir, ...segments); if (!existsSync(src)) { console.warn(pc.yellow(`Baseline folder not found: ${src}`)); continue; } - console.log(pc.dim(`Copying ${flavor}/ -> ${dest}`)); + console.log(pc.dim(`Copying ${subPath} -> ${dest}`)); + await mkdir(dirname(dest), { recursive: true }); await cp(src, dest, { recursive: true }); } diff --git a/packages/http-client-python/generator/pygen/preprocess/__init__.py b/packages/http-client-python/generator/pygen/preprocess/__init__.py index 1c1e575f44b..b2a90c78c47 100644 --- a/packages/http-client-python/generator/pygen/preprocess/__init__.py +++ b/packages/http-client-python/generator/pygen/preprocess/__init__.py @@ -171,9 +171,7 @@ def _get_etag_role(parameter: dict[str, Any]) -> Optional[str]: return parameter.get("etagRole") -def _pick_etag_slot( - candidates: list[dict[str, Any]], standard_wire_name: str -) -> Optional[dict[str, Any]]: +def _pick_etag_slot(candidates: list[dict[str, Any]], standard_wire_name: str) -> Optional[dict[str, Any]]: """Choose which etag-typed header should be promoted to the etag/match_condition slot. When more than one etag-typed header is present in an operation, prefer the @@ -258,15 +256,14 @@ def _process_operation_etag_headers( elif role == "ifNoneMatch": if_none_match_candidates.append(p) - property_if_match, property_if_none_match = _resolve_etag_pair( - if_match_candidates, if_none_match_candidates - ) + property_if_match, property_if_none_match = _resolve_etag_pair(if_match_candidates, if_none_match_candidates) if property_if_match and property_if_none_match: etag_params = {id(property_if_match), id(property_if_none_match)} - operation["parameters"] = [ - item for item in operation["parameters"] if id(item) not in etag_params - ] + [property_if_match, property_if_none_match] + operation["parameters"] = [item for item in operation["parameters"] if id(item) not in etag_params] + [ + property_if_match, + property_if_none_match, + ] operation["hasEtag"] = True client["hasEtag"] = True From 77274f856b90b09d11862ad097c6e3a12c97f2cf Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 3 Jun 2026 04:59:40 +0000 Subject: [PATCH 2/2] update changelog --- ...python-regen-narrow-legacy-baseline-2026-6-3-12-0-0.md | 7 +++++++ .../eng/scripts/ci/regenerate-common.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .chronus/changes/python-regen-narrow-legacy-baseline-2026-6-3-12-0-0.md diff --git a/.chronus/changes/python-regen-narrow-legacy-baseline-2026-6-3-12-0-0.md b/.chronus/changes/python-regen-narrow-legacy-baseline-2026-6-3-12-0-0.md new file mode 100644 index 00000000000..8f22c76b273 --- /dev/null +++ b/.chronus/changes/python-regen-narrow-legacy-baseline-2026-6-3-12-0-0.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Only copy the legacy code paths required for tests from the baseline sparse-checkout instead of copying the entire `azure/` and `unbranded/` baseline trees. diff --git a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts index 0822ab16aa8..1fe6f17d63c 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts @@ -716,9 +716,13 @@ export async function prepareBaselineOfGeneratedCode(generatedFolder: string): P run(`git fetch --depth 1 origin ${branch}`); run(`git checkout FETCH_HEAD`); + // we don't copy whole generated folder, just the specific subfolders needed for tests + // to verify correct preservation/deletion of files and folders during regeneration, + // to avoid accidentally including any manually edited code that might be in the repo + // and cause confusion when it doesn't get updated during regeneration const legacyCodePathNeededForTests = [ - "azure/authentication/api-key", - "unbranded/authentication/api-key", + "azure/authentication-api-key", + "unbranded/authentication-api-key", "azure/authentication-union", "azure/generation-subdir", "azure/generation-subdir2",