Skip to content

Commit 1bd0039

Browse files
qgeromeyolanfery
andauthored
fix: Users are warned when pushing a pipeline with a code and a name or 'code='
* Use warnings (as print) instead of errors * fix tests * fix: test and typo * fix: lint --------- Co-authored-by: YolanFery <yolan@codethefuture.be>
1 parent 5b2f991 commit 1bd0039

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

examples/pipelines/logistic_stats/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from openhexa.sdk import parameter, pipeline, workspace
1414

1515

16-
@pipeline("Logistic stats")
16+
@pipeline("Logistic stats", "Test")
1717
@parameter(
1818
"deg",
1919
name="Data element group",

openhexa/sdk/pipelines/runtime.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,22 @@ def get_pipeline(pipeline_path: Path) -> Pipeline:
237237
# Handle deprecated 'code' argument
238238
if code_arg["value"] is not None:
239239
if code_arg["is_keyword"]:
240-
raise DeprecationWarning(
241-
f"The 'code' argument is deprecated and should not be used as a keyword."
242-
f"Replace 'code=\"{code_arg['value']}\"' by 'name=\"{code_arg['value']}\"'"
240+
print(
241+
"\n\033[93m",
242+
f"The 'code' argument is deprecated and should not be used as a keyword. "
243+
f"Replace 'code=\"{code_arg['value']}\"' by 'name=\"{code_arg['value']}\"'\033[0m",
244+
"\n",
245+
flush=True,
243246
)
244247

245248
if name_arg["value"] is not None:
246-
raise DeprecationWarning(
249+
print(
250+
"\n\033[93m",
247251
f"Providing both 'code' and 'name' is deprecated. "
248252
f"Please remove 'code' and only use 'name' when decorating the pipeline: "
249-
f'@pipeline(name="{name_arg["value"]}")'
253+
f'@pipeline(name="{name_arg["value"]}")\033[0m',
254+
"\n",
255+
flush=True,
250256
)
251257

252258
# Determine the pipeline name (prefer 'name', fall back to 'code')

tests/test_ast.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Tests related to the parsing of the pipeline code."""
2-
2+
import io
33
import tempfile
44
from unittest import TestCase
5+
from unittest.mock import patch
56

67
from openhexa.sdk.pipelines.exceptions import InvalidParameterError, PipelineNotFound
78
from openhexa.sdk.pipelines.runtime import get_pipeline
@@ -560,8 +561,12 @@ def test_pipeline_with_deprecated_code_argument_with_name(self):
560561
]
561562
)
562563
)
563-
with self.assertRaises(DeprecationWarning):
564-
get_pipeline(tmpdirname)
564+
with patch("sys.stdout", new=io.StringIO()) as fake_stdout:
565+
pipeline = get_pipeline(tmpdirname)
566+
self.assertEqual(pipeline.to_dict()["name"], "Test pipeline")
567+
self.assertIn(
568+
"The 'code' argument is deprecated and should not be used as a keyword.", fake_stdout.getvalue()
569+
)
565570

566571
def test_pipeline_with_deprecated_code_as_arg(self):
567572
"""The file contains a @pipeline decorator with the deprecated 'code' argument."""
@@ -579,5 +584,7 @@ def test_pipeline_with_deprecated_code_as_arg(self):
579584
]
580585
)
581586
)
582-
with self.assertRaises(DeprecationWarning):
583-
get_pipeline(tmpdirname)
587+
with patch("sys.stdout", new=io.StringIO()) as fake_stdout:
588+
pipeline = get_pipeline(tmpdirname)
589+
self.assertEqual(pipeline.to_dict()["name"], "Test pipeline")
590+
self.assertIn("Providing both 'code' and 'name' is deprecated.", fake_stdout.getvalue())

0 commit comments

Comments
 (0)