
from ._base import IncorrectDatabaseSetup
from .postgres import PostgresEngine
from .sqlite3 import Sqlite3Engine

import importlib
import platform


SUPPORTED_MODULE = {
    "sqlite3": Sqlite3Engine,
    "psycopg2": PostgresEngine,
}


def create_engine(database_config):
    name = database_config["name"]
    engine_class = SUPPORTED_MODULE.get(name, None)

    if engine_class:
        needs_pypy_hack = (name == "psycopg2" and
                platform.python_implementation() == "PyPy")
        if needs_pypy_hack:
            module = importlib.import_module("psycopg2cffi")
        else:
            module = importlib.import_module(name)
        return engine_class(module, database_config)

    raise RuntimeError(
        "Unsupported database engine '%s'" % (name,)
    )


__all__ = ["create_engine", "IncorrectDatabaseSetup"]


from ._base import IncorrectDatabaseSetup
from .postgres import PostgresEngine
from .sqlite3 import Sqlite3Engine

import importlib
import platform


SUPPORTED_MODULE = {
    "sqlite3": Sqlite3Engine,
    "psycopg2": PostgresEngine,
}


def create_engine(database_config):
    name = database_config["name"]
    engine_class = SUPPORTED_MODULE.get(name, None)

    if engine_class:
        # pypy requires psycopg2cffi rather than psycopg2
        if (name == "psycopg2" and
                platform.python_implementation() == "PyPy"):
            name = "psycopg2cffi"
        module = importlib.import_module(name)
        return engine_class(module, database_config)

    raise RuntimeError(
        "Unsupported database engine '%s'" % (name,)
    )


__all__ = ["create_engine", "IncorrectDatabaseSetup"]

Fix pep8 error on psycopg2cffi hack
Fix pep8 error on psycopg2cffi hack
  
  from ._base import IncorrectDatabaseSetup
  from .postgres import PostgresEngine
  from .sqlite3 import Sqlite3Engine
  
  import importlib
  import platform
  
  
  SUPPORTED_MODULE = {
      "sqlite3": Sqlite3Engine,
      "psycopg2": PostgresEngine,
  }
  
  
  def create_engine(database_config):
      name = database_config["name"]
      engine_class = SUPPORTED_MODULE.get(name, None)
  
      if engine_class:
+         # pypy requires psycopg2cffi rather than psycopg2
-         needs_pypy_hack = (name == "psycopg2" and
+         if (name == "psycopg2" and
-                 platform.python_implementation() == "PyPy")
+                 platform.python_implementation() == "PyPy"):
+             name = "psycopg2cffi"
-         if needs_pypy_hack:
-             module = importlib.import_module("psycopg2cffi")
-         else:
-             module = importlib.import_module(name)
+         module = importlib.import_module(name)
          return engine_class(module, database_config)
  
      raise RuntimeError(
          "Unsupported database engine '%s'" % (name,)
      )
  
  
  __all__ = ["create_engine", "IncorrectDatabaseSetup"]
  
Fix pep8 error on psycopg2cffi hack
## Code Before:

from ._base import IncorrectDatabaseSetup
from .postgres import PostgresEngine
from .sqlite3 import Sqlite3Engine

import importlib
import platform


SUPPORTED_MODULE = {
    "sqlite3": Sqlite3Engine,
    "psycopg2": PostgresEngine,
}


def create_engine(database_config):
    name = database_config["name"]
    engine_class = SUPPORTED_MODULE.get(name, None)

    if engine_class:
        needs_pypy_hack = (name == "psycopg2" and
                platform.python_implementation() == "PyPy")
        if needs_pypy_hack:
            module = importlib.import_module("psycopg2cffi")
        else:
            module = importlib.import_module(name)
        return engine_class(module, database_config)

    raise RuntimeError(
        "Unsupported database engine '%s'" % (name,)
    )


__all__ = ["create_engine", "IncorrectDatabaseSetup"]

## Instruction:
Fix pep8 error on psycopg2cffi hack
## Code After:

from ._base import IncorrectDatabaseSetup
from .postgres import PostgresEngine
from .sqlite3 import Sqlite3Engine

import importlib
import platform


SUPPORTED_MODULE = {
    "sqlite3": Sqlite3Engine,
    "psycopg2": PostgresEngine,
}


def create_engine(database_config):
    name = database_config["name"]
    engine_class = SUPPORTED_MODULE.get(name, None)

    if engine_class:
        # pypy requires psycopg2cffi rather than psycopg2
        if (name == "psycopg2" and
                platform.python_implementation() == "PyPy"):
            name = "psycopg2cffi"
        module = importlib.import_module(name)
        return engine_class(module, database_config)

    raise RuntimeError(
        "Unsupported database engine '%s'" % (name,)
    )


__all__ = ["create_engine", "IncorrectDatabaseSetup"]
