11import importlib
22import inspect
33import json
4+ import os
45import re
56import shutil
67import sys
78import traceback
8- from os import path
99from contextlib import contextmanager
10+ from os import path
1011
1112from getgauge import logger
1213from getgauge .registry import registry
13- from getgauge .util import *
14+ from getgauge .util import get_project_root , get_step_impl_dirs
1415
1516project_root = get_project_root ()
1617impl_dirs = get_step_impl_dirs ()
@@ -50,9 +51,8 @@ def copy_skel_files():
5051 shutil .copytree (os .path .join (SKEL ,path .basename (impl_dirs [0 ]) ), impl_dirs [0 ])
5152 logger .info ('create {}' .format (os .path .join (env_dir , PYTHON_PROPERTIES )))
5253 shutil .copy (os .path .join (SKEL , PYTHON_PROPERTIES ), env_dir )
53- f = open (requirements_file , 'w' )
54- f .write ('getgauge==' + _get_version ())
55- f .close ()
54+ with open (requirements_file , 'w' , encoding = "utf-8" ) as f :
55+ f .write ('getgauge==' + _get_version ())
5656 except :
5757 logger .fatal ('Exception occurred while copying skel files.\n {}.' .format (traceback .format_exc ()))
5858
@@ -95,10 +95,10 @@ def _import_file(base_dir, file_path):
9595 except :
9696 logger .fatal ('Exception occurred while loading step implementations from file: {}.\n {}' .format (rel_path , traceback .format_exc ()))
9797
98- # Inject instace in each class method (hook/step)
98+ # Inject instance in each class method (hook/step)
9999def update_step_registry_with_class (instance , file_path ):
100100 # Resolve the absolute path from relative path
101- file_path = os .path .abspath (file_path ) if '..' in file_path else file_path
101+ file_path = os .path .abspath (file_path ) if str ( file_path ). startswith ( ".." ) else file_path
102102 method_list = registry .get_all_methods_in (file_path )
103103 for info in method_list :
104104 class_methods = [x [0 ] for x in inspect .getmembers (instance , inspect .ismethod )]
@@ -107,13 +107,14 @@ def update_step_registry_with_class(instance, file_path):
107107 return method_list
108108
109109def _get_version ():
110- json_data = open (PLUGIN_JSON ). read ()
111- data = json .loads (json_data )
110+ with open (PLUGIN_JSON , "r" , encoding = "utf-8" ) as json_data :
111+ data = json .loads (json_data . read () )
112112 return data [VERSION ]
113113
114- def _has_methods_with_gauge_decoratores (klass ):
115- foo = r"@(step|before_suite|after_suite|before_scenario|after_scenario|before_spec|after_spec|before_step|after_step|screenshot|custom_screen_grabber)"
114+ def _has_methods_with_gauge_decoratores (klass ) -> bool :
115+ gauge_decorator_pattern = r"@(step|before_suite|after_suite|before_scenario|after_scenario|before_spec|after_spec|before_step|after_step|screenshot|custom_screen_grabber)"
116116 sourcelines = inspect .getsourcelines (klass )[0 ]
117- for i , line in enumerate ( sourcelines ) :
118- if re .match (foo , line .strip ()) != None :
117+ for line in sourcelines :
118+ if re .match (gauge_decorator_pattern , line .strip ()) is not None :
119119 return True
120+ return False
0 commit comments