import os
import sys
from glob import glob
from importlib import import_module

__all__ = ['migrate', 'get_migrations']

HERE = os.path.dirname(__file__)

package = sys.modules[__name__].__name__


def get_migrations():
    for module in sorted(glob(os.path.join(HERE, '[0-9]*.py'))):
        module_name, _ = os.path.basename(module).rsplit('.', 1)
        mod = import_module('.' + module_name, package=package)

        version, label = module_name.split('_', 1)

        yield int(version), label, mod.migrate


def migrate(data, version_src=0):
    for version, label, func in list(get_migrations()):
        if version_src < version:
            data = func(data)
            version_src = version
    return data

import os
import sys
from glob import glob
from importlib import import_module

__all__ = ['migrate', 'get_migrations']

HERE = os.path.dirname(__file__)

package = sys.modules[__name__].__name__


def get_migrations():
    """
    Return a generator with all JSON migrations sorted.

    Each item is a tuple with:
      - the version number (int)
      - the label of the migration
      - the reference to the migrate() function

    """
    for module in sorted(glob(os.path.join(HERE, '[0-9]*.py'))):
        module_name, _ = os.path.basename(module).rsplit('.', 1)
        mod = import_module('.' + module_name, package=package)

        version, label = module_name.split('_', 1)

        yield int(version), label, mod.migrate


def migrate(data, version_src=0):
    """
    Apply all migrations from ``version_src`` to the latest found on
    ``data``.

    """
    for version, label, func in list(get_migrations()):
        if version_src < version:
            data = func(data)
            version_src = version
    return data

Add docstrings to JSON migrations functions
Add docstrings to JSON migrations functions

  import os
  import sys
  from glob import glob
  from importlib import import_module
  
  __all__ = ['migrate', 'get_migrations']
  
  HERE = os.path.dirname(__file__)
  
  package = sys.modules[__name__].__name__
  
  
  def get_migrations():
+     """
+     Return a generator with all JSON migrations sorted.
+ 
+     Each item is a tuple with:
+       - the version number (int)
+       - the label of the migration
+       - the reference to the migrate() function
+ 
+     """
      for module in sorted(glob(os.path.join(HERE, '[0-9]*.py'))):
          module_name, _ = os.path.basename(module).rsplit('.', 1)
          mod = import_module('.' + module_name, package=package)
  
          version, label = module_name.split('_', 1)
  
          yield int(version), label, mod.migrate
  
  
  def migrate(data, version_src=0):
+     """
+     Apply all migrations from ``version_src`` to the latest found on
+     ``data``.
+ 
+     """
      for version, label, func in list(get_migrations()):
          if version_src < version:
              data = func(data)
              version_src = version
      return data
  
Add docstrings to JSON migrations functions
## Code Before:
import os
import sys
from glob import glob
from importlib import import_module

__all__ = ['migrate', 'get_migrations']

HERE = os.path.dirname(__file__)

package = sys.modules[__name__].__name__


def get_migrations():
    for module in sorted(glob(os.path.join(HERE, '[0-9]*.py'))):
        module_name, _ = os.path.basename(module).rsplit('.', 1)
        mod = import_module('.' + module_name, package=package)

        version, label = module_name.split('_', 1)

        yield int(version), label, mod.migrate


def migrate(data, version_src=0):
    for version, label, func in list(get_migrations()):
        if version_src < version:
            data = func(data)
            version_src = version
    return data

## Instruction:
Add docstrings to JSON migrations functions
## Code After:
import os
import sys
from glob import glob
from importlib import import_module

__all__ = ['migrate', 'get_migrations']

HERE = os.path.dirname(__file__)

package = sys.modules[__name__].__name__


def get_migrations():
    """
    Return a generator with all JSON migrations sorted.

    Each item is a tuple with:
      - the version number (int)
      - the label of the migration
      - the reference to the migrate() function

    """
    for module in sorted(glob(os.path.join(HERE, '[0-9]*.py'))):
        module_name, _ = os.path.basename(module).rsplit('.', 1)
        mod = import_module('.' + module_name, package=package)

        version, label = module_name.split('_', 1)

        yield int(version), label, mod.migrate


def migrate(data, version_src=0):
    """
    Apply all migrations from ``version_src`` to the latest found on
    ``data``.

    """
    for version, label, func in list(get_migrations()):
        if version_src < version:
            data = func(data)
            version_src = version
    return data
