From 1cc60074808fb2bce1282247a95e95b2db2ec005 Mon Sep 17 00:00:00 2001 From: Kenneth Belitzky Date: Tue, 5 Nov 2024 13:00:32 -0300 Subject: [PATCH] Add `skip` property to `file_item.py` to support conditional file creation (#20) ### Overview This PR introduces a `skip` property to the `file_item.py` module, enabling the option to bypass file creation based on conditional settings. ### Changes - **Added `skip` property**: The constructor now initializes the `skip` property based on input properties, defaulting to `False` if not specified. - **Conditional file creation**: Modified the `create` method to check the `skip` property. When set to `True`, the process logs that file creation is skipped and exits early. ### Justification The ability to conditionally skip file creation is essential for workflows that require selective file management. This update allows greater control over file generation without altering existing logic. ### Impact This enhancement reduces unnecessary file creation, optimizing resource use, especially in large projects or in cases where specific files are conditionally excluded. No breaking changes are introduced, ensuring compatibility with existing workflows. --- example/structure.yaml | 1 + struct_module/commands/validate.py | 5 +++-- struct_module/file_item.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/example/structure.yaml b/example/structure.yaml index c5c29a6..f1ef33c 100644 --- a/example/structure.yaml +++ b/example/structure.yaml @@ -1,5 +1,6 @@ structure: - README.md: + skip: true content: | # {{@ project_name @}} This is a template repository. diff --git a/struct_module/commands/validate.py b/struct_module/commands/validate.py index c4e0cf8..24de1fa 100644 --- a/struct_module/commands/validate.py +++ b/struct_module/commands/validate.py @@ -46,7 +46,7 @@ def _validate_folders_config(self, folders): raise ValueError(f"The content of '{name}' must be a dictionary.") if 'struct' not in content: raise ValueError(f"Dictionary item '{name}' must contain a 'struct' key.") - if not isinstance(content['struct'], str): + if not isinstance(content['struct'], str) and not isinstance(content['struct'], list): raise ValueError(f"The 'struct' value for '{name}' must be a string.") @@ -104,7 +104,8 @@ def _validate_structure_config(self, structure): # Check if 'prompt' key is present and its value is a string if 'prompt' in content and not isinstance(content['prompt'], str): raise ValueError(f"The 'prompt' value for '{name}' must be a string.") - # Check if 'prompt' key is present but no OpenAI API key is found + if 'skip' in content and not isinstance(content['skip'], bool): + raise ValueError(f"The 'skip' value for '{name}' must be a string.") elif not isinstance(content, str): raise ValueError(f"The content of '{name}' must be a string or dictionary.") self.logger.info("Configuration validation passed.") diff --git a/struct_module/file_item.py b/struct_module/file_item.py index 811a8e6..6ff7b2d 100644 --- a/struct_module/file_item.py +++ b/struct_module/file_item.py @@ -23,6 +23,7 @@ def __init__(self, properties): self.content_location = properties.get("file") self.permissions = properties.get("permissions") self.input_store = properties.get("input_store") + self.skip = properties.get("skip", False) self.system_prompt = properties.get("system_prompt") or properties.get("global_system_prompt") self.user_prompt = properties.get("user_prompt") @@ -118,6 +119,11 @@ def apply_template_variables(self, template_vars): def create(self, base_path, dry_run=False, backup_path=None, file_strategy='overwrite'): file_path = os.path.join(base_path, self.name) + + if self.skip: + self.logger.info(f"Skipping file creation: {file_path}") + return + if dry_run: self.logger.info(f"[DRY RUN] Would create file: {file_path} with content: \n\n{self.content}") return