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

Added schema definition for yaml files in .neuro #699

Merged
merged 9 commits into from
Nov 28, 2024
6 changes: 6 additions & 0 deletions CHANGELOG.D/699.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This version includes changes to the workflow and project configuration files to enable code completion and validation by adding schema references to Apolo's config yaml files. These changes will improve the development experience by providing better code completion and validation.

Changes:

{{cookiecutter.flow_dir}}/.neuro/live.yml: Added schema reference for code completion support in the live workflow configuration file.
{{cookiecutter.flow_dir}}/.neuro/project.yml: Added schema reference for code completion support in the project configuration file.
4 changes: 2 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async def get_project_name() -> str:

# >>> Optionally clearing comments
COMMENTS_STRUCTURE = {
"./.neuro/live.yml": r"(\s*#.*)",
"./.neuro/project.yml": r"(\s*#.*)",
"./.neuro/live.yml": r"(\s*#(?! yaml-language-server).*)",
"./.neuro/project.yml": r"(\s*#(?! yaml-language-server).*)",
}
PRESERVE_HINTS_VARIANS = {
"yes": True,
Expand Down
18 changes: 15 additions & 3 deletions tests/unit/test_bake_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import sys
from pathlib import Path

Expand Down Expand Up @@ -82,12 +83,23 @@ def test_flow_config_with_comments(cookies: Cookies, preserve_comments: str) ->
}
)
assert result.exit_code == 0
comment_sign = "#"
comment_regex = re.compile(r"(\s*#(?! yaml-language-server).*)")
with inside_dir(str(result.project_path)):
live_file_content = Path(".neuro/live.yml").read_text()
project_file_content = Path(".neuro/project.yml").read_text()
l_com_exists = comment_sign in live_file_content
p_com_exists = comment_sign in project_file_content

l_com_exists = any(
[
comment_regex.match(line) is not None
for line in live_file_content.splitlines()
]
)
p_com_exists = any(
[
comment_regex.match(line) is not None
for line in project_file_content.splitlines()
]
)
if preserve_comments == "yes":
assert l_com_exists, ".neuro/live.yml file does not contain comments"
assert p_com_exists, ".neuro/project.yml file does not contain comments"
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.flow_dir}}/.neuro/live.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/neuro-inc/neuro-flow/refs/heads/master/src/apolo_flow/flow-schema.json
## Keep the preceding line to enable code completion for the workflow configuration file.
kind: live
## Required. Type of workflow, might be one of the following:
## - 'live' -- full reference at https://docs.apolo.us/apolo-flow-reference/workflow-syntax/live-workflow-syntax
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.flow_dir}}/.neuro/project.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/neuro-inc/neuro-flow/refs/heads/master/src/apolo_flow/project-schema.json
## Keep the preceding line to enable code completion for the project configuration file.
## Check our full reference documentation at https://docs.apolo.us/apolo-flow-reference/workflow-syntax/project-configuration-syntax
id: {{ cookiecutter.flow_id }}
## Could be referenced as $[[ project.id ]] or $[[ flow.project_id ]] contexts.
Expand Down