From 843ff31d121452a8d4033f8d20b415108b8b9414 Mon Sep 17 00:00:00 2001 From: David Esner Date: Thu, 15 Feb 2024 12:40:05 +0100 Subject: [PATCH 1/2] Fix legacy queue detection (hack( --- setup.py | 2 +- src/keboola/component/interface.py | 7 +++++-- tests/test_interface.py | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 6edf316..132daf6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setuptools.setup( name="keboola.component", - version="1.4.4", + version="1.5.0", author="Keboola KDS Team", project_urls=project_urls, setup_requires=['pytest-runner', 'flake8'], diff --git a/src/keboola/component/interface.py b/src/keboola/component/interface.py index 49b5fc2..3e45c4b 100644 --- a/src/keboola/component/interface.py +++ b/src/keboola/component/interface.py @@ -877,9 +877,12 @@ def is_legacy_queue(self) -> bool: Returns: """ - features = os.environ.get('KBC_PROJECT_FEATURE_GATES') + features = os.environ.get('KBC_PROJECT_FEATURE_GATES', '') is_legacy_queue = True - if not features or 'queuev2' in features: + # checking for runId which should always be present when run in the platform to determine + # if the project is running locally + # so the user does not have to set the feature gate + if 'queuev2' in features or (not features and not os.environ.get('KBC_RUNID')): is_legacy_queue = False return is_legacy_queue diff --git a/tests/test_interface.py b/tests/test_interface.py index cb06170..58541b0 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -12,7 +12,11 @@ def setUp(self): 'data_examples', 'data1') os.environ["KBC_DATADIR"] = path + # default to queue2 + os.environ['KBC_PROJECT_FEATURE_GATES'] = 'queuev2' + def test_all_env_variables_initialized(self): + env_copy = os.environ.copy() # set all variables os.environ['KBC_RUNID'] = 'KBC_RUNID' os.environ['KBC_PROJECTID'] = 'KBC_PROJECTID' @@ -42,6 +46,9 @@ def test_all_env_variables_initialized(self): self.assertEqual(ci.environment_variables.logger_addr, 'KBC_LOGGER_ADDR') self.assertEqual(ci.environment_variables.logger_port, 'KBC_LOGGER_PORT') + # return back environ + os.environ = env_copy + def test_empty_required_params_pass(self): c = CommonInterface return True @@ -110,10 +117,12 @@ def test_get_files_in_dir(self): self.assertEqual(tables_out, ci.tables_in_path) def test_legacy_queue(self): + env_copy = os.environ.copy() os.environ['KBC_PROJECT_FEATURE_GATES'] = '' + os.environ['KBC_RUNID'] = '3333' ci = CommonInterface() # with no env default to v2 - self.assertEqual(False, ci.is_legacy_queue) + self.assertEqual(True, ci.is_legacy_queue) # otherwise check for queuev2 os.environ['KBC_PROJECT_FEATURE_GATES'] = 'queuev2;someoterfeature' @@ -123,6 +132,14 @@ def test_legacy_queue(self): os.environ['KBC_PROJECT_FEATURE_GATES'] = 'feature1;someoterfeature' self.assertEqual(True, ci.is_legacy_queue) + # If run locally the env variables do not need to be set + run_id = os.environ.pop('KBC_RUNID', '') + os.environ['KBC_PROJECT_FEATURE_GATES'] = '' + self.assertEqual(False, ci.is_legacy_queue) + + # reset back + os.environ = env_copy + def test_create_and_write_table_manifest_deprecated(self): ci = CommonInterface() # create table def From 19d5cb84c0c9e90a32a346fa4de1da0abee99c94 Mon Sep 17 00:00:00 2001 From: KCF Date: Thu, 15 Feb 2024 11:40:35 +0000 Subject: [PATCH 2/2] Automated html docs build --- docs/interface.html | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/interface.html b/docs/interface.html index 7d1849a..f26e54e 100644 --- a/docs/interface.html +++ b/docs/interface.html @@ -905,9 +905,12 @@

Module keboola.component.interface

Returns: """ - features = os.environ.get('KBC_PROJECT_FEATURE_GATES') + features = os.environ.get('KBC_PROJECT_FEATURE_GATES', '') is_legacy_queue = True - if not features or 'queuev2' in features: + # checking for runId which should always be present when run in the platform to determine + # if the project is running locally + # so the user does not have to set the feature gate + if 'queuev2' in features or (not features and not os.environ.get('KBC_RUNID')): is_legacy_queue = False return is_legacy_queue @@ -2113,9 +2116,12 @@

Args

Returns: """ - features = os.environ.get('KBC_PROJECT_FEATURE_GATES') + features = os.environ.get('KBC_PROJECT_FEATURE_GATES', '') is_legacy_queue = True - if not features or 'queuev2' in features: + # checking for runId which should always be present when run in the platform to determine + # if the project is running locally + # so the user does not have to set the feature gate + if 'queuev2' in features or (not features and not os.environ.get('KBC_RUNID')): is_legacy_queue = False return is_legacy_queue @@ -2445,9 +2451,12 @@

Instance variables

Returns: """ - features = os.environ.get('KBC_PROJECT_FEATURE_GATES') + features = os.environ.get('KBC_PROJECT_FEATURE_GATES', '') is_legacy_queue = True - if not features or 'queuev2' in features: + # checking for runId which should always be present when run in the platform to determine + # if the project is running locally + # so the user does not have to set the feature gate + if 'queuev2' in features or (not features and not os.environ.get('KBC_RUNID')): is_legacy_queue = False return is_legacy_queue