Skip to content

Commit

Permalink
Add skip property to file_item.py to support conditional file cre…
Browse files Browse the repository at this point in the history
…ation (#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.
  • Loading branch information
httpdss authored Nov 5, 2024
1 parent 8579e59 commit 1cc6007
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/structure.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
structure:
- README.md:
skip: true
content: |
# {{@ project_name @}}
This is a template repository.
Expand Down
5 changes: 3 additions & 2 deletions struct_module/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")


Expand Down Expand Up @@ -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.")
6 changes: 6 additions & 0 deletions struct_module/file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1cc6007

Please sign in to comment.