How to use the datafiles.settings.HOOKS_ENABLED function in datafiles

To help you get started, we’ve selected a few datafiles 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 jacebrowning / datafiles / datafiles / model.py View on Github external
def __post_init__(self):
        log.debug(f'Initializing {self.__class__} object')

        self.datafile = create_mapper(self)

        if settings.HOOKS_ENABLED:
            with hooks.disabled():

                path = self.datafile.path
                exists = self.datafile.exists
                create = not self.datafile.manual

                if path:
                    log.debug(f'Datafile path: {path}')
                    log.debug(f'Datafile exists: {exists}')

                    if exists:
                        self.datafile.load(_first_load=True)
                    elif path and create:
                        self.datafile.save()

                    hooks.apply(self, self.datafile)
github jacebrowning / datafiles / datafiles / hooks.py View on Github external
def enabled(mapper, args) -> bool:
    """Determine if hooks are enabled for the current method."""
    if not settings.HOOKS_ENABLED:
        return False

    if mapper is None:
        return False

    if mapper.manual:
        return False

    if args and isinstance(args[0], str):
        if args[0] in {'Meta', 'datafile'}:
            return False
        if args[0].startswith('_'):
            return False

    return True
github jacebrowning / datafiles / datafiles / hooks.py View on Github external
def disabled():
    """Globally disable method hooks, temporarily."""
    enabled = settings.HOOKS_ENABLED
    if enabled:
        settings.HOOKS_ENABLED = False
    try:
        yield
    finally:
        settings.HOOKS_ENABLED = enabled
github jacebrowning / datafiles / datafiles / hooks.py View on Github external
def disabled():
    """Globally disable method hooks, temporarily."""
    enabled = settings.HOOKS_ENABLED
    if enabled:
        settings.HOOKS_ENABLED = False
    try:
        yield
    finally:
        settings.HOOKS_ENABLED = enabled
github jacebrowning / datafiles / datafiles / hooks.py View on Github external
def disabled():
    """Globally disable method hooks, temporarily."""
    enabled = settings.HOOKS_ENABLED
    if enabled:
        settings.HOOKS_ENABLED = False
    try:
        yield
    finally:
        settings.HOOKS_ENABLED = enabled