parameters: (top_level_path)
docstring: Starting from the `top_level_path`, discover python files which contains
      benchmark functions. It looks for files with a specific prefix, which
      defaults to "benchmark_"
docstring_summary: Starting from the `top_level_path`, discover python files which contains
      benchmark functions. It looks for files with a specific prefix, which
      defaults to "benchmark_"
docstring_tokens: Starting from the top_level_path discover python files which contains benchmark functions . It looks for files with a specific prefix which defaults to benchmark_
function: def discover_benchmark_modules(top_level_path):
      """Starting from the `top_level_path`, discover python files which contains
      benchmark functions. It looks for files with a specific prefix, which
      defaults to "benchmark_"
      """
      config = configparser.ConfigParser()
      config.read(
          os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.ini")
      )
      if "discovery" in config.sections():
          filename_prefix = config["discovery"]["filename_prefix"]
      else:
          filename_prefix = "benchmark_"
      if re.search(fr"{filename_prefix}.*.py$", top_level_path):
          # A specific python file so just include that.
          benchmark_files = [top_level_path]
      else:
          # A directory so recursively search for all python files.
          benchmark_files = pathlib.Path(
              top_level_path
          ).rglob(f"{filename_prefix}*.py")
      for benchmark_filename in benchmark_files:
          benchmark_abs_dir = os.path.abspath(os.path.dirname(benchmark_filename))
          sys.path.append(benchmark_abs_dir)
          module_file_name = os.path.basename(benchmark_filename)
          module_name = module_file_name.replace(".py", "")
          module = importlib.import_module(module_name)
          yield module
          sys.path.pop()
function_tokens: def discover_benchmark_modules ( top_level_path ) : config = configparser . ConfigParser ( ) config . read ( os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , "config.ini" ) ) if "discovery" in config . sections ( ) : filename_prefix = config [ "discovery" ] [ "filename_prefix" ] else : filename_prefix = "benchmark_" if re . search ( fr"{filename_prefix}.*.py$" , top_level_path ) : # A specific python file so just include that. benchmark_files = [ top_level_path ] else : # A directory so recursively search for all python files. benchmark_files = pathlib . Path ( top_level_path ) . rglob ( f"{filename_prefix}*.py" ) for benchmark_filename in benchmark_files : benchmark_abs_dir = os . path . abspath ( os . path . dirname ( benchmark_filename ) ) sys . path . append ( benchmark_abs_dir ) module_file_name = os . path . basename ( benchmark_filename ) module_name = module_file_name . replace ( ".py" , "" ) module = importlib . import_module ( module_name ) yield module sys . path . pop ( )