From 34a87232c7c9b538eeb63c018e9ed7e7d16d37ec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 15:19:14 +0000 Subject: [PATCH 01/12] Bump the pip-dependencies group with 2 updates (#358) Bumps the pip-dependencies group with 2 updates: [importlib-metadata](https://github.com/python/importlib_metadata) and [setuptools](https://github.com/pypa/setuptools). Updates `importlib-metadata` from 7.1.0 to 7.2.1 - [Release notes](https://github.com/python/importlib_metadata/releases) - [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst) - [Commits](https://github.com/python/importlib_metadata/compare/v7.1.0...v7.2.1) Updates `setuptools` from 70.0.0 to 70.1.0 - [Release notes](https://github.com/pypa/setuptools/releases) - [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst) - [Commits](https://github.com/pypa/setuptools/compare/v70.0.0...v70.1.0) --- updated-dependencies: - dependency-name: importlib-metadata dependency-type: direct:production update-type: version-update:semver-minor dependency-group: pip-dependencies - dependency-name: setuptools dependency-type: direct:production update-type: version-update:semver-minor dependency-group: pip-dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Kunal Vishwasrao --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 463bb14..90a5274 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ docutils==0.20.1 grpcio==1.62.2 grpcio-tools==1.62.2 idna==3.7 -importlib-metadata==7.1.0 +importlib-metadata==7.2.1 jaraco.classes==3.4.0 keyring==25.2.1 markdown-it-py==3.0.0 @@ -25,7 +25,7 @@ requests-toolbelt==1.0.0 rfc3986==2.0.0 rich==13.7.1 rply==0.7.8 -setuptools==70.0.0 +setuptools==70.1.0 six==1.16.0 twine==5.1.0 urllib3==2.2.2 From ea689d67ae915b18747763b3d0db8d1c917c67f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 00:28:09 +0800 Subject: [PATCH 02/12] Bump the pip-dependencies group across 1 directory with 3 updates (#362) Bumps the pip-dependencies group with 3 updates in the / directory: [debugpy](https://github.com/microsoft/debugpy), [importlib-metadata](https://github.com/python/importlib_metadata) and [setuptools](https://github.com/pypa/setuptools). Updates `debugpy` from 1.8.1 to 1.8.2 - [Release notes](https://github.com/microsoft/debugpy/releases) - [Commits](https://github.com/microsoft/debugpy/compare/v1.8.1...v1.8.2) Updates `importlib-metadata` from 7.2.1 to 8.0.0 - [Release notes](https://github.com/python/importlib_metadata/releases) - [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst) - [Commits](https://github.com/python/importlib_metadata/compare/v7.2.1...v8.0.0) Updates `setuptools` from 70.1.0 to 70.1.1 - [Release notes](https://github.com/pypa/setuptools/releases) - [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst) - [Commits](https://github.com/pypa/setuptools/compare/v70.1.0...v70.1.1) --- updated-dependencies: - dependency-name: debugpy dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pip-dependencies - dependency-name: importlib-metadata dependency-type: direct:production update-type: version-update:semver-major dependency-group: pip-dependencies - dependency-name: setuptools dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pip-dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Kunal Vishwasrao --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 90a5274..944703d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,12 +3,12 @@ baron==0.10.1 bleach==6.1.0 certifi==2024.6.2 charset-normalizer==3.3.2 -debugpy==1.8.1 +debugpy==1.8.2 docutils==0.20.1 grpcio==1.62.2 grpcio-tools==1.62.2 idna==3.7 -importlib-metadata==7.2.1 +importlib-metadata==8.0.0 jaraco.classes==3.4.0 keyring==25.2.1 markdown-it-py==3.0.0 @@ -25,7 +25,7 @@ requests-toolbelt==1.0.0 rfc3986==2.0.0 rich==13.7.1 rply==0.7.8 -setuptools==70.1.0 +setuptools==70.1.1 six==1.16.0 twine==5.1.0 urllib3==2.2.2 From 821ea8679a59f45f00f078544efdc6b36c6834ce Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao <36107786+kunalvishwasrao@users.noreply.github.com> Date: Tue, 2 Jul 2024 07:28:31 +0530 Subject: [PATCH 03/12] Support for relative imports to reuse step impls Signed-off-by: Kunal Vishwasrao --- getgauge/impl_loader.py | 23 ++++++++++++++++++++++- python.json | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/getgauge/impl_loader.py b/getgauge/impl_loader.py index 9b1e4b3..30f39bb 100644 --- a/getgauge/impl_loader.py +++ b/getgauge/impl_loader.py @@ -6,6 +6,7 @@ import sys import traceback from os import path +from contextlib import contextmanager from getgauge import logger from getgauge.registry import registry @@ -16,6 +17,7 @@ env_dir = os.path.join(project_root, 'env', 'default') requirements_file = os.path.join(project_root, 'requirements.txt') sys.path.append(project_root) +temporary_sys_path = [] PLUGIN_JSON = 'python.json' VERSION = 'version' PYTHON_PROPERTIES = 'python.properties' @@ -30,6 +32,12 @@ def load_impls(step_impl_dirs=impl_dirs): logger.error('Make sure `STEP_IMPL_DIR` env var is set to a valid directory path.') return base_dir = project_root if impl_dir.startswith(project_root) else os.path.dirname(impl_dir) + # Handle multi-level relative imports + for _ in range(impl_dir.count('..')): + base_dir = os.path.dirname(base_dir).replace("/", os.path.sep).replace("\\", os.path.sep) + # Add temporary sys path for relative imports that is not already added + if '..' in impl_dir and base_dir not in temporary_sys_path: + temporary_sys_path.append(base_dir) _import_impl(base_dir, impl_dir) @@ -57,12 +65,25 @@ def _import_impl(base_dir, step_impl_dir): elif path.isdir(file_path): _import_impl(base_dir, file_path) +@contextmanager +def use_temporary_sys_path(): + original_sys_path = sys.path[:] + sys.path.extend(temporary_sys_path) + try: + yield + finally: + sys.path = original_sys_path def _import_file(base_dir, file_path): rel_path = os.path.normpath(file_path.replace(base_dir + os.path.sep, '')) try: module_name = os.path.splitext(rel_path.replace(os.path.sep, '.'))[0] - m = importlib.import_module(module_name) + # Use temporary sys path for relative imports + if '..' in file_path: + with use_temporary_sys_path(): + m = importlib.import_module(module_name) + else: + m = importlib.import_module(module_name) # Get all classes in the imported module classes = inspect.getmembers(m, lambda member: inspect.isclass(member) and member.__module__ == module_name) if len(classes) > 0: diff --git a/python.json b/python.json index 2ae61b3..b42e11f 100644 --- a/python.json +++ b/python.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "0.4.3", + "version": "0.4.4", "description": "Python support for gauge", "run": { "windows": [ From 0aa4247b622375208b4e1df6f60cc7222810b862 Mon Sep 17 00:00:00 2001 From: Vinay Shukla Date: Tue, 2 Jul 2024 07:53:14 +0530 Subject: [PATCH 04/12] Update release dependencies Signed-off-by: BugDiver Signed-off-by: Kunal Vishwasrao --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 944703d..7de3d60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ keyring==25.2.1 markdown-it-py==3.0.0 mdurl==0.1.2 more-itertools==10.3.0 -pkginfo==1.11.1 +pkginfo>=1.8.1 protobuf==4.25.3 pyfakefs==5.5.0 Pygments==2.18.0 @@ -27,7 +27,7 @@ rich==13.7.1 rply==0.7.8 setuptools==70.1.1 six==1.16.0 -twine==5.1.0 +twine==5.1.1 urllib3==2.2.2 webencodings==0.5.1 zipp==3.19.2 From ae4b50ed11393e38748179ba97714cbebcc1aa9f Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Wed, 3 Jul 2024 00:53:07 +0530 Subject: [PATCH 05/12] Correctly loading the methods from relatively imported classs (addition to #360) Signed-off-by: Kunal Vishwasrao --- getgauge/impl_loader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/getgauge/impl_loader.py b/getgauge/impl_loader.py index 30f39bb..310035b 100644 --- a/getgauge/impl_loader.py +++ b/getgauge/impl_loader.py @@ -97,6 +97,8 @@ def _import_file(base_dir, file_path): # Inject instace in each class method (hook/step) def update_step_resgistry_with_class(instance, file_path): + # Resole the absolute path from relative path + file_path = os.path.abspath(file_path) if '..' in file_path else file_path for info in registry.get_all_methods_in(file_path): class_methods = [x[0] for x in inspect.getmembers(instance, inspect.ismethod)] if info.impl.__name__ in class_methods: From bf770bffd17430b2c0fae421bb932e7f2241e9e9 Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao <36107786+kunalvishwasrao@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:44:46 +0530 Subject: [PATCH 06/12] Update getgauge/impl_loader.py Correctly loading the methods from relatively imported classes (#365) Signed-off-by: Kunal Vishwasrao Co-authored-by: Zabil Cheriya Maliackal Signed-off-by: Kunal Vishwasrao --- getgauge/impl_loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getgauge/impl_loader.py b/getgauge/impl_loader.py index 310035b..a4f7819 100644 --- a/getgauge/impl_loader.py +++ b/getgauge/impl_loader.py @@ -97,7 +97,7 @@ def _import_file(base_dir, file_path): # Inject instace in each class method (hook/step) def update_step_resgistry_with_class(instance, file_path): - # Resole the absolute path from relative path + # Resolve the absolute path from relative path file_path = os.path.abspath(file_path) if '..' in file_path else file_path for info in registry.get_all_methods_in(file_path): class_methods = [x[0] for x in inspect.getmembers(instance, inspect.ismethod)] From 6a016629a59e6bdb725390b72bcb5c1e789a65f1 Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Thu, 4 Jul 2024 21:27:03 +0530 Subject: [PATCH 07/12] Returning method_list in update_step_resgistry_with_class method (#365) Signed-off-by: Kunal Vishwasrao --- getgauge/impl_loader.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/getgauge/impl_loader.py b/getgauge/impl_loader.py index a4f7819..a1b77af 100644 --- a/getgauge/impl_loader.py +++ b/getgauge/impl_loader.py @@ -99,11 +99,12 @@ def _import_file(base_dir, file_path): def update_step_resgistry_with_class(instance, file_path): # Resolve the absolute path from relative path file_path = os.path.abspath(file_path) if '..' in file_path else file_path - for info in registry.get_all_methods_in(file_path): + method_list = registry.get_all_methods_in(file_path) + for info in method_list: class_methods = [x[0] for x in inspect.getmembers(instance, inspect.ismethod)] if info.impl.__name__ in class_methods: info.instance = instance - + return method_list def _get_version(): json_data = open(PLUGIN_JSON).read() From 2e0c37a8c9d918765757da721a15e9075ae4fe1c Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Thu, 4 Jul 2024 21:29:03 +0530 Subject: [PATCH 08/12] Adding test class for relative import unittest (#365) Signed-off-by: Kunal Vishwasrao --- test_relative_import/__init__.py | 0 test_relative_import/relative_import_class.py | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test_relative_import/__init__.py create mode 100644 test_relative_import/relative_import_class.py diff --git a/test_relative_import/__init__.py b/test_relative_import/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_relative_import/relative_import_class.py b/test_relative_import/relative_import_class.py new file mode 100644 index 0000000..35662f5 --- /dev/null +++ b/test_relative_import/relative_import_class.py @@ -0,0 +1,21 @@ +from getgauge.python import step, Messages + + +class BaseSample: + def __init__(self) -> None: + pass + +class Sample(BaseSample): + def __init__(self) -> None: + pass + + # Gauge step implementation in a class + @step('Greet from inside the class') + def greetings_from_class(self, name): + Messages.write_message("Hello from inside the class, {0}".format(name)) + + +# Gauge step implementation outside class +@step('Greet from outside the class') +def greetings_from_outside_the_class(name): + Messages.write_message("Hello from outside the class, {0}".format(name)) \ No newline at end of file From b5ea2aa089f23837e5075673c16b37c587254fda Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Thu, 4 Jul 2024 21:30:30 +0530 Subject: [PATCH 09/12] Adding unittest for relative import (#365) Signed-off-by: Kunal Vishwasrao --- tests/test_impl_loader.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_impl_loader.py diff --git a/tests/test_impl_loader.py b/tests/test_impl_loader.py new file mode 100644 index 0000000..85ef2c8 --- /dev/null +++ b/tests/test_impl_loader.py @@ -0,0 +1,21 @@ +import os +import unittest + +from test_relative_import.relative_import_class import Sample +from getgauge.impl_loader import update_step_resgistry_with_class + + +class ImplLoaderTest(unittest.TestCase): + def setUp(self): + self.relative_file_path = os.path.join('..', 'test_relative_import', 'relative_import_class.py') + + def test_update_step_resgistry_with_class(self): + curr_dir = os.getcwd() + os.chdir('tests') + method_list = update_step_resgistry_with_class(Sample(), self.relative_file_path) + os.chdir(curr_dir) + self.assertEqual(2, len(method_list)) + + +if __name__ == '__main__': + unittest.main() From d322292820b76424cc8fdf69474de62f6ae2bc5d Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Fri, 5 Jul 2024 00:14:49 +0530 Subject: [PATCH 10/12] Renaming method to update_step_registry_with_class (#365) Signed-off-by: Kunal Vishwasrao --- getgauge/impl_loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getgauge/impl_loader.py b/getgauge/impl_loader.py index a1b77af..07b04cf 100644 --- a/getgauge/impl_loader.py +++ b/getgauge/impl_loader.py @@ -91,12 +91,12 @@ def _import_file(base_dir, file_path): file = inspect.getfile(c[1]) # Create instance of step implementation class. if _has_methods_with_gauge_decoratores(c[1]): - update_step_resgistry_with_class(c[1](), file_path) # c[1]() will create a new instance of the class + update_step_registry_with_class(c[1](), file_path) # c[1]() will create a new instance of the class except: logger.fatal('Exception occurred while loading step implementations from file: {}.\n{}'.format(rel_path, traceback.format_exc())) # Inject instace in each class method (hook/step) -def update_step_resgistry_with_class(instance, file_path): +def update_step_registry_with_class(instance, file_path): # Resolve the absolute path from relative path file_path = os.path.abspath(file_path) if '..' in file_path else file_path method_list = registry.get_all_methods_in(file_path) From ec73984665836bbfa010fd7c0f719425737ce7e8 Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Fri, 5 Jul 2024 00:16:03 +0530 Subject: [PATCH 11/12] Updating unittest for impl loader (#365) Signed-off-by: Kunal Vishwasrao --- tests/test_impl_loader.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_impl_loader.py b/tests/test_impl_loader.py index 85ef2c8..8d82d32 100644 --- a/tests/test_impl_loader.py +++ b/tests/test_impl_loader.py @@ -2,7 +2,7 @@ import unittest from test_relative_import.relative_import_class import Sample -from getgauge.impl_loader import update_step_resgistry_with_class +from getgauge.impl_loader import update_step_registry_with_class class ImplLoaderTest(unittest.TestCase): @@ -12,9 +12,11 @@ def setUp(self): def test_update_step_resgistry_with_class(self): curr_dir = os.getcwd() os.chdir('tests') - method_list = update_step_resgistry_with_class(Sample(), self.relative_file_path) + method_list = update_step_registry_with_class(Sample(), self.relative_file_path) os.chdir(curr_dir) - self.assertEqual(2, len(method_list)) + self.assertEqual(["Greet from inside the class", + "Greet from outside the class"], + [method.step_text for method in method_list]) if __name__ == '__main__': From 92347680ec78d24efb14f159e4906ff097a72f59 Mon Sep 17 00:00:00 2001 From: Kunal Vishwasrao Date: Fri, 5 Jul 2024 19:46:00 +0530 Subject: [PATCH 12/12] Bumping up python package version (#365) Signed-off-by: Kunal Vishwasrao --- python.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python.json b/python.json index b42e11f..7d143cc 100644 --- a/python.json +++ b/python.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "0.4.4", + "version": "0.4.5", "description": "Python support for gauge", "run": { "windows": [