Bug/curly_braces_yaml

Added parser to help users on yaml syntax
This commit is contained in:
GabeKoga
2024-05-07 18:19:52 -03:00
parent b862e464f8
commit ca08865384
3 changed files with 16 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import inspect
import os
from pathlib import Path
from crewai.utilities.parser import YamlParser
import yaml
from dotenv import load_dotenv
@@ -40,6 +41,7 @@ def CrewBase(cls):
@staticmethod
def load_yaml(config_path: str):
with open(config_path, "r") as file:
return yaml.safe_load(file)
parsedContent = YamlParser.parse(file)
return yaml.safe_load(parsedContent)
return WrappedClass

View File

@@ -6,3 +6,4 @@ from .printer import Printer
from .prompts import Prompts
from .rpm_controller import RPMController
from .fileHandler import FileHandler
from .parser import YamlParser

View File

@@ -0,0 +1,12 @@
import re
class YamlParser:
def parse(file):
content = file.read()
# Replace single { and } with doubled ones, while leaving already doubled ones intact and the other special characters {# and {%
modified_content = re.sub(r"(?<!\{){(?!\{)(?!\#)(?!\%)", "{{", content)
modified_content = re.sub(
r"(?<!\})(?<!\%)(?<!\#)\}(?!})", "}}", modified_content
)
return modified_content