-
Notifications
You must be signed in to change notification settings - Fork 32
✨ allows ooil to escape legacy format in y*ml files inside .osparc folder
#8085
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7aa74e0
added legacy-escape command
985dfe1
Merge remote-tracking branch 'upstream/master' into pr-osparc-upgrade…
d1a62b0
added proper escaping
c67f1ea
adding more debug details
86dc2f0
using rglob
62091dd
removed extra prints
c2f61c9
fixed typo
1aebae6
Merge remote-tracking branch 'upstream/master' into pr-osparc-upgrade…
101d827
refactor comments
1ea02c9
added some reference for the change
9278014
refactor registration
fe507d4
Merge remote-tracking branch 'upstream/master' into pr-osparc-upgrade…
f18b60d
Merge branch 'master' into pr-osparc-upgrade-ooil
mergify[bot] 8e3c0ef
Merge branch 'master' into pr-osparc-upgrade-ooil
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/service-integration/src/service_integration/cli/_escaping.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import re | ||
| from pathlib import Path | ||
| from typing import Annotated | ||
|
|
||
| import typer | ||
|
|
||
| from ..osparc_config import OSPARC_CONFIG_DIRNAME | ||
|
|
||
|
|
||
| def escape_dollar_brace(text: str) -> str: | ||
| # the pattern finds '$${' that is not preceded by another '$'. | ||
| pattern = r"(?<!\$)\$\${" | ||
| replacement = "$$$${" | ||
| return re.sub(pattern, replacement, text) | ||
|
|
||
|
|
||
| def legacy_escape( | ||
| osparc_config_dirname: Annotated[ | ||
| Path, | ||
| typer.Option( | ||
| "--osparc-config-dirname", | ||
| help="Path to where the .osparc configuration directory is located", | ||
| ), | ||
| ] = Path(OSPARC_CONFIG_DIRNAME), | ||
| ): | ||
| """ | ||
| Replaces all '$${' sequences with '$$$${' unless they are part of an | ||
| existing '$$$${' sequence. | ||
| """ | ||
|
|
||
| # NOTE: since https://github.com/docker/compose/releases/tag/v2.35.0 | ||
| # docker-compose was fixed/changed to escape `${}` | ||
| # SEE https://github.com/docker/compose/pull/12664 | ||
|
|
||
| if not osparc_config_dirname.exists(): | ||
| msg = "Invalid path to metadata file or folder" | ||
| raise typer.BadParameter(msg) | ||
|
|
||
| for file in osparc_config_dirname.rglob("*.y*ml"): | ||
| read_text = file.read_text() | ||
| replaced_text = escape_dollar_brace(read_text) | ||
| if read_text != replaced_text: | ||
| print(f"Escaped sequence in {file}") | ||
| file.write_text(replaced_text) | ||
GitHK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,56 @@ | ||
| # pylint:disable=redefined-outer-name | ||
|
|
||
| import os | ||
| import shutil | ||
| import traceback | ||
| from collections.abc import Callable | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from click.testing import Result | ||
| from service_integration import __version__ | ||
|
|
||
|
|
||
| def _format_cli_error(result: Result) -> str: | ||
| assert result.exception | ||
| tb_message = "\n".join(traceback.format_tb(result.exception.__traceback__)) | ||
| return f"Below exception was raised by the cli:\n{tb_message}" | ||
|
|
||
|
|
||
| def test_cli_help(run_program_with_args: Callable): | ||
| result = run_program_with_args( | ||
| "--help", | ||
| ) | ||
| assert result.exit_code == 0 | ||
| assert result.exit_code == os.EX_OK, _format_cli_error(result) | ||
|
|
||
|
|
||
| def test_cli_version(run_program_with_args: Callable): | ||
| result = run_program_with_args( | ||
| "--version", | ||
| ) | ||
| assert result.exit_code == 0 | ||
| assert result.exit_code == os.EX_OK, _format_cli_error(result) | ||
| assert __version__ == result.output.strip() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def copy_tests_data_dir(tests_data_dir: Path, tmp_path: Path) -> Path: | ||
| new_dir_path = tmp_path / "copy_tests_data_dir" | ||
| new_dir_path.mkdir(exist_ok=True, parents=True) | ||
|
|
||
| for item in tests_data_dir.glob("*"): | ||
| print(f"Copying {item} to {new_dir_path / item.name}") | ||
| shutil.copy2(item, new_dir_path / item.name) | ||
|
|
||
| return new_dir_path | ||
|
|
||
|
|
||
| def test_cli_legacy_escape(copy_tests_data_dir: Path, run_program_with_args: Callable): | ||
| result = run_program_with_args( | ||
| "legacy-escape", "--osparc-config-dirname", copy_tests_data_dir | ||
| ) | ||
| assert result.exit_code == os.EX_OK, _format_cli_error(result) | ||
| # NOTE only 1 file will have a sequence that will be escaped | ||
| assert ( | ||
| f"Escaped sequence in {copy_tests_data_dir}/docker-compose-meta.yml" | ||
| in result.output.strip() | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import pytest | ||
| from service_integration.cli._escaping import escape_dollar_brace | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "to_escape, escaped", | ||
| [ | ||
| ("some text", "some text"), | ||
| ("$${escapes}", "$$$${escapes}"), | ||
| ("$$${preserves}", "$$${preserves}"), | ||
| ("$$$${preserves}", "$$$${preserves}"), | ||
| ("$$$$${preserves}", "$$$$${preserves}"), | ||
| ( | ||
| "$${escapes} & $$${preserves},$$$${preserves}, $$$$${preserves}", | ||
| "$$$${escapes} & $$${preserves},$$$${preserves}, $$$$${preserves}", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_escape_dollar_brace(to_escape: str, escaped: str): | ||
| assert escape_dollar_brace(to_escape) == escaped |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.