Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAML runner config support #571

Merged
merged 3 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/config/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from model import script_config
from model.model_helper import InvalidFileException
from model.script_config import get_sorted_config
from utils import os_utils, file_utils, process_utils, custom_json
from utils import os_utils, file_utils, process_utils, custom_json, custom_yaml
from utils.file_utils import to_filename
from utils.string_utils import is_blank, strip

Expand Down Expand Up @@ -170,7 +170,10 @@ def list_configs(self, user, mode=None):

def load_script(path, content):
try:
json_object = custom_json.loads(content)
if path.endswith('.yaml'):
json_object = custom_yaml.loads(content)
else:
json_object = custom_json.loads(content)
short_config = script_config.read_short(path, json_object)

if short_config is None:
Expand Down Expand Up @@ -205,7 +208,7 @@ def _visit_script_configs(self, visitor):
configs_dir = self._script_configs_folder
files = os.listdir(configs_dir)

configs = [file for file in files if file.lower().endswith(".json")]
configs = [file for file in files if file.lower().endswith(".json") or file.lower().endswith(".yaml")]

result = []

Expand All @@ -231,7 +234,10 @@ def _visit_script_configs(self, visitor):
def _find_config(self, name) -> Union[ConfigSearchResult, None]:
def find_and_load(path, content):
try:
json_object = custom_json.loads(content)
if path.endswith('.yaml'):
json_object = custom_yaml.loads(content)
else:
json_object = custom_json.loads(content)
bugy marked this conversation as resolved.
Show resolved Hide resolved
short_config = script_config.read_short(path, json_object)

if short_config is None:
Expand Down
10 changes: 10 additions & 0 deletions src/utils/custom_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import json
import re
import yaml
bugy marked this conversation as resolved.
Show resolved Hide resolved

def loads (content, **args):
contents=''
for line in content.split('\n'):
if not re.match (r'\s*//.*', line):
contents += line + "\n"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is not needed. Yaml supports comments by default (in the specification and in the library)

return yaml.safe_load(contents, **args)