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 5e6b2b9ed88..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,15 +716,31 @@ 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-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