Skip to content

Commit

Permalink
Merge branch 'master' into fix-pypi-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BugDiver authored Jul 2, 2024
2 parents c15ffd8 + 32e9662 commit fbb9912
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion getgauge/impl_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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)


Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "python",
"version": "0.4.3",
"version": "0.4.4",
"description": "Python support for gauge",
"run": {
"windows": [
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.1
urllib3==2.2.2
Expand Down

0 comments on commit fbb9912

Please sign in to comment.