import importlib
import pkgutil

ignore_packages = set(['test'])

def import_submodules(package, recursive=True):
    """ Import all submodules of a module, recursively, including subpackages

    :param package: package (name or actual module)
    :type package: str | module
    :rtype: dict[str, types.ModuleType]
    """
    if isinstance(package, str):
        package = importlib.import_module(package)
    results = {}
    for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
        if(name not in ignore_packages):
            full_name = package.__name__ + '.' + name
            results[full_name] = importlib.import_module(full_name)
            if recursive and is_pkg:
                results.update(import_submodules(full_name))
    return results

# import submodules recursively
import_submodules(__name__)

import importlib
import pkgutil

ignore_packages = set(['test'])

def import_submodules(package, recursive=True):
    """ Import all submodules of a module, recursively, including subpackages

    :param package: package (name or actual module)
    :type package: str | module
    :rtype: dict[str, types.ModuleType]
    """
    if isinstance(package, str):
        package = importlib.import_module(package)
    results = {}
    for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
        # test submodule names are 'syft.test.*', so this matches the 'ignore_packages' above
        if name.split('.')[1] not in ignore_packages:
            full_name = package.__name__ + '.' + name
            results[full_name] = importlib.import_module(full_name)
            if recursive and is_pkg:
                results.update(import_submodules(full_name))
    return results

# import submodules recursively
import_submodules(__name__)

Check for the name of the submodule we'd like to ignore in a more general way.
Check for the name of the submodule we'd like to ignore in a more general way.

  import importlib
  import pkgutil
  
  ignore_packages = set(['test'])
  
  def import_submodules(package, recursive=True):
      """ Import all submodules of a module, recursively, including subpackages
  
      :param package: package (name or actual module)
      :type package: str | module
      :rtype: dict[str, types.ModuleType]
      """
      if isinstance(package, str):
          package = importlib.import_module(package)
      results = {}
      for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
+         # test submodule names are 'syft.test.*', so this matches the 'ignore_packages' above
-         if(name not in ignore_packages):
+         if name.split('.')[1] not in ignore_packages:
              full_name = package.__name__ + '.' + name
              results[full_name] = importlib.import_module(full_name)
              if recursive and is_pkg:
                  results.update(import_submodules(full_name))
      return results
  
  # import submodules recursively
  import_submodules(__name__)
  
Check for the name of the submodule we'd like to ignore in a more general way.
## Code Before:
import importlib
import pkgutil

ignore_packages = set(['test'])

def import_submodules(package, recursive=True):
    """ Import all submodules of a module, recursively, including subpackages

    :param package: package (name or actual module)
    :type package: str | module
    :rtype: dict[str, types.ModuleType]
    """
    if isinstance(package, str):
        package = importlib.import_module(package)
    results = {}
    for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
        if(name not in ignore_packages):
            full_name = package.__name__ + '.' + name
            results[full_name] = importlib.import_module(full_name)
            if recursive and is_pkg:
                results.update(import_submodules(full_name))
    return results

# import submodules recursively
import_submodules(__name__)

## Instruction:
Check for the name of the submodule we'd like to ignore in a more general way.
## Code After:
import importlib
import pkgutil

ignore_packages = set(['test'])

def import_submodules(package, recursive=True):
    """ Import all submodules of a module, recursively, including subpackages

    :param package: package (name or actual module)
    :type package: str | module
    :rtype: dict[str, types.ModuleType]
    """
    if isinstance(package, str):
        package = importlib.import_module(package)
    results = {}
    for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
        # test submodule names are 'syft.test.*', so this matches the 'ignore_packages' above
        if name.split('.')[1] not in ignore_packages:
            full_name = package.__name__ + '.' + name
            results[full_name] = importlib.import_module(full_name)
            if recursive and is_pkg:
                results.update(import_submodules(full_name))
    return results

# import submodules recursively
import_submodules(__name__)
