diff --git a/conda_recipe_v2_schema/model.py b/conda_recipe_v2_schema/model.py index 7fc56c4..404cdd6 100644 --- a/conda_recipe_v2_schema/model.py +++ b/conda_recipe_v2_schema/model.py @@ -192,6 +192,21 @@ class ScriptEnv(StrictBaseModel): ) +class PostProcess(StrictBaseModel): + files: list[NonEmptyStr] = Field( + ..., + description="List of glob patterns selecting files to process. Files must be valid UTF-8 text.", + ) + regex: NonEmptyStr = Field( + ..., + description="Regular expression pattern to match (uses Rust `regex` crate semantics).", + ) + replacement: str = Field( + ..., + description="Replacement string applied using `replace_all` behavior.", + ) + + class Build(StrictBaseModel): number: UnsignedInt | JinjaExpr | None = Field( 0, @@ -251,6 +266,11 @@ class Build(StrictBaseModel): None, description="Glob patterns to include or exclude files from the package." ) + post_process: list[PostProcess] | None = Field( + None, + description="A list of post-processing steps. Each entry applies a regex replacement on the selected files. Files must be valid UTF-8 text. Regex uses Rust `regex` crate semantics and `replace_all` behavior.", + ) + class BaseScript(StrictBaseModel): interpreter: NonEmptyStr | None = Field( diff --git a/examples/valid/post-process/recipe.yaml b/examples/valid/post-process/recipe.yaml new file mode 100644 index 0000000..8c40d9f --- /dev/null +++ b/examples/valid/post-process/recipe.yaml @@ -0,0 +1,23 @@ +# yaml-language-server: $schema=../../../schema.json + +# Example recipe demonstrating the build.post_process feature. +# post_process applies regex replacements on files in the package +# after the build step. Files must be valid UTF-8 text. +# Regex uses Rust `regex` crate semantics with `replace_all` behavior. + +package: + name: post-process-example + version: "1.0.0" + +build: + number: 0 + post_process: + - files: + - "bin/*" + regex: "/old/path" + replacement: "/new/path" + - files: + - "**/*.cmake" + - "**/*.pc" + regex: "/home/builder" + replacement: "$PREFIX" diff --git a/schema.json b/schema.json index bc26dc4..d6c3792 100644 --- a/schema.json +++ b/schema.json @@ -541,6 +541,22 @@ "default": null, "description": "Glob patterns to include or exclude files from the package.", "title": "Files" + }, + "post_process": { + "anyOf": [ + { + "items": { + "$ref": "#/$defs/PostProcess" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "description": "A list of post-processing steps. Each entry applies a regex replacement on the selected files. Files must be valid UTF-8 text. Regex uses Rust `regex` crate semantics and `replace_all` behavior.", + "title": "Post Process" } }, "title": "Build", @@ -2960,6 +2976,22 @@ "description": "Glob patterns to include or exclude files from the package.", "title": "Files" }, + "post_process": { + "anyOf": [ + { + "items": { + "$ref": "#/$defs/PostProcess" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "description": "A list of post-processing steps. Each entry applies a regex replacement on the selected files. Files must be valid UTF-8 text. Regex uses Rust `regex` crate semantics and `replace_all` behavior.", + "title": "Post Process" + }, "cache_only": { "default": false, "deprecated": true, @@ -3256,6 +3288,38 @@ "title": "PerlTestElementInner", "type": "object" }, + "PostProcess": { + "additionalProperties": false, + "properties": { + "files": { + "description": "List of glob patterns selecting files to process. Files must be valid UTF-8 text.", + "items": { + "minLength": 1, + "type": "string" + }, + "title": "Files", + "type": "array" + }, + "regex": { + "description": "Regular expression pattern to match (uses Rust `regex` crate semantics).", + "minLength": 1, + "title": "Regex", + "type": "string" + }, + "replacement": { + "description": "Replacement string applied using `replace_all` behavior.", + "title": "Replacement", + "type": "string" + } + }, + "required": [ + "files", + "regex", + "replacement" + ], + "title": "PostProcess", + "type": "object" + }, "PrefixDetection": { "additionalProperties": false, "properties": { diff --git a/tests/test_recipe.py b/tests/test_recipe.py index bda3896..51c0c54 100644 --- a/tests/test_recipe.py +++ b/tests/test_recipe.py @@ -11,7 +11,7 @@ @pytest.fixture( scope="module", - params=["mamba", "xtensor", "single-output", "zlib", "staging"], + params=["mamba", "xtensor", "single-output", "zlib", "staging", "post-process"], ) def valid_recipe(request) -> str: recipe_name = request.param