How to use the patchy.patchy function in patchy

To help you get started, we’ve selected a few patchy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashleywaite / django-more / django_types / __init__.py View on Github external
def patch_types():
    """ Applies the patches necessary for django_types to work """
    logger.info('Applying django_types patches')

    # Patch fields to provide default dependency information
    with patchy('django.db.models', 'django_types.patches') as p:
        p.cls('Field').auto(allow={'dependencies'})
        p.cls('fields.related.RelatedField').auto()

    # Patch migration classes to statefully apply types and dependencies
    with patchy('django.db.migrations', 'django_types.patches') as p:
        p.cls('autodetector.MigrationAutodetector').auto(allow={
            '_generate_added_field',
            '_generate_altered_foo_together'})
        p.cls('state.ProjectState').auto(allow={'apps'})
        p.cls('state.StateApps').auto()

    # Patch backend classes to allow parametised db_types
    with patchy('django.db.backends', 'django_types.patches') as p:
        p.cls('base.schema.BaseDatabaseSchemaEditor').auto(allow={'_alter_column_type_sql'})
github ashleywaite / django-more / django_types / __init__.py View on Github external
# Patch fields to provide default dependency information
    with patchy('django.db.models', 'django_types.patches') as p:
        p.cls('Field').auto(allow={'dependencies'})
        p.cls('fields.related.RelatedField').auto()

    # Patch migration classes to statefully apply types and dependencies
    with patchy('django.db.migrations', 'django_types.patches') as p:
        p.cls('autodetector.MigrationAutodetector').auto(allow={
            '_generate_added_field',
            '_generate_altered_foo_together'})
        p.cls('state.ProjectState').auto(allow={'apps'})
        p.cls('state.StateApps').auto()

    # Patch backend classes to allow parametised db_types
    with patchy('django.db.backends', 'django_types.patches') as p:
        p.cls('base.schema.BaseDatabaseSchemaEditor').auto(allow={'_alter_column_type_sql'})
github ashleywaite / django-more / django_enum / __init__.py View on Github external
# Patch migrations classes
    logger.info('Applying django_enum patches')

    # If no support for add_type, apply django_types to add it
    from django.db.migrations.state import ProjectState
    if not hasattr(ProjectState, 'add_type'):
        from django_types import patch_types
        patch_types()

    with patchy('django.db.migrations', 'django_enum.patches') as p:
        p.cls('questioner.MigrationQuestioner').auto()
        p.cls('questioner.InteractiveMigrationQuestioner').auto()
        p.cls('autodetector.MigrationAutodetector').auto()

    # Patch backend features
    with patchy('django.db.backends', 'django_enum.patches') as p:
        # Add base changes necessary
        p.cls('base.features.BaseDatabaseFeatures').auto()

        # Only patch database backends in use (avoid dependencies)
        for backend in set(db_dict['ENGINE'] for db_name, db_dict in settings.DATABASES.items()):
            if backend == 'django.db.backends.postgresql':
                import django.db.backends.postgresql.base
                p.cls('postgresql.features.DatabaseFeatures', 'PostgresDatabaseFeatures').auto()
                p.cls('postgresql.schema.DatabaseSchemaEditor', 'PostgresDatabaseSchemaEditor').auto()
            if backend == 'django.db.backends.mysql':
                import django.db.backends.mysql.base
                p.cls('mysql.features.DatabaseFeatures', 'MysqlDatabaseFeatures').auto()
github ashleywaite / django-more / django_types / __init__.py View on Github external
def patch_types():
    """ Applies the patches necessary for django_types to work """
    logger.info('Applying django_types patches')

    # Patch fields to provide default dependency information
    with patchy('django.db.models', 'django_types.patches') as p:
        p.cls('Field').auto(allow={'dependencies'})
        p.cls('fields.related.RelatedField').auto()

    # Patch migration classes to statefully apply types and dependencies
    with patchy('django.db.migrations', 'django_types.patches') as p:
        p.cls('autodetector.MigrationAutodetector').auto(allow={
            '_generate_added_field',
            '_generate_altered_foo_together'})
        p.cls('state.ProjectState').auto(allow={'apps'})
        p.cls('state.StateApps').auto()

    # Patch backend classes to allow parametised db_types
    with patchy('django.db.backends', 'django_types.patches') as p:
        p.cls('base.schema.BaseDatabaseSchemaEditor').auto(allow={'_alter_column_type_sql'})
github ashleywaite / django-more / django_cte / patch.py View on Github external
def patch_cte():
    with patchy('django.db.models', 'django_cte') as p:
        p.mod('expressions').auto()
        p.mod('sql.compiler').auto()
        p.mod('sql.subqueries').auto()
        # Force reload so that new query types are imported into namespace
        reload(import_module('django.db.models.sql'))

        p.mod('query').auto()
        p.cls('manager.BaseManager').auto()
        p.cls('base.Model').auto()
github ashleywaite / django-more / django_cte / __init__.py View on Github external
def patch_cte():
    """ Apply CTE monkey patches to Django.
        At present these patches must be updated manually to conform with new CTE
         implementations, but this is only necessary to use new functionality.
        Order of patching *matters* due to namespace reload.
    """
    with patchy('django.db.models', 'django_cte') as p:
        p.mod('expressions').auto()
        p.mod('sql.compiler').auto()
        p.mod('sql.subqueries').auto()
        # Force reload so that new query types are imported into namespace
        reload(import_module('django.db.models.sql'))

        p.mod('query').auto()
        p.cls('manager.BaseManager').auto()
        p.cls('base.Model').auto()
github ashleywaite / django-more / django_enum / __init__.py View on Github external
def patch_enum():
    """ Applies the patches necessary for django_enum to work """
    # Patch migrations classes
    logger.info('Applying django_enum patches')

    # If no support for add_type, apply django_types to add it
    from django.db.migrations.state import ProjectState
    if not hasattr(ProjectState, 'add_type'):
        from django_types import patch_types
        patch_types()

    with patchy('django.db.migrations', 'django_enum.patches') as p:
        p.cls('questioner.MigrationQuestioner').auto()
        p.cls('questioner.InteractiveMigrationQuestioner').auto()
        p.cls('autodetector.MigrationAutodetector').auto()

    # Patch backend features
    with patchy('django.db.backends', 'django_enum.patches') as p:
        # Add base changes necessary
        p.cls('base.features.BaseDatabaseFeatures').auto()

        # Only patch database backends in use (avoid dependencies)
        for backend in set(db_dict['ENGINE'] for db_name, db_dict in settings.DATABASES.items()):
            if backend == 'django.db.backends.postgresql':
                import django.db.backends.postgresql.base
                p.cls('postgresql.features.DatabaseFeatures', 'PostgresDatabaseFeatures').auto()
                p.cls('postgresql.schema.DatabaseSchemaEditor', 'PostgresDatabaseSchemaEditor').auto()
            if backend == 'django.db.backends.mysql':