How to use the datafiles.settings 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 / hooks.py View on Github external
def wrapped(self, *args, **kwargs):
        __tracebackhide__ = settings.HIDE_TRACEBACK_IN_HOOKS

        mapper = get_mapper(self)
        if enabled(mapper, args):
            if mapper.exists and mapper.modified:
                log.debug(f"Loading automatically before '{method.__name__}' call")
                mapper.load()

        result = method(self, *args, **kwargs)

        if enabled(mapper, args):
            log.debug(f"Saving automatically after '{method.__name__}' call")
            mapper.save()
            if mapper.auto_load:
                log.debug("Loading automatically after save")
                mapper.load(_log=False)
github jacebrowning / datafiles / datafiles / hooks.py View on Github external
def wrapped(self, *args, **kwargs):
        __tracebackhide__ = settings.HIDE_TRACEBACK_IN_HOOKS

        mapper = get_mapper(self)
        if enabled(mapper, args):
            if mapper.exists and mapper.modified:
                log.debug(f"Loading automatically before '{method.__name__}' call")
                mapper.load()
                if mapper.auto_save:
                    log.debug("Saving automatically after load")
                    mapper.save(_log=False)

        return method(self, *args, **kwargs)
github jacebrowning / gitman / gitman / settings.py View on Github external
"""Program defaults."""

import os

import datafiles
import log


# Serialization settings
datafiles.settings.INDENT_YAML_BLOCKS = False

# Cache settings
CACHE = os.path.expanduser(os.getenv('GITMAN_CACHE', "~/.gitcache"))
CACHE_DISABLE = bool(os.getenv('GITMAN_CACHE_DISABLE'))

# Logging settings
DEFAULT_LOGGING_FORMAT = "%(message)s"
LEVELED_LOGGING_FORMAT = "%(levelname)s: %(message)s"
VERBOSE_LOGGING_FORMAT = "[%(levelname)-8s] %(message)s"
VERBOSE2_LOGGING_FORMAT = "[%(levelname)-8s] (%(name)s @%(lineno)4d) %(message)s"
QUIET_LOGGING_LEVEL = log.ERROR
DEFAULT_LOGGING_LEVEL = log.WARNING
VERBOSE_LOGGING_LEVEL = log.INFO
VERBOSE2_LOGGING_LEVEL = log.DEBUG
LOGGING_DATEFMT = "%Y-%m-%d %H:%M"
github jacebrowning / datafiles / datafiles / formats.py View on Github external
def _get_formatter(extension: str):
    if settings.YAML_LIBRARY == 'PyYAML':  # pragma: no cover
        register('.yml', PyYAML)

    with suppress(KeyError):
        return _REGISTRY[extension]

    for formatter in Formatter.__subclasses__():
        if extension in formatter.extensions():
            return formatter

    raise ValueError(f'Unsupported file extension: {extension!r}')
github jacebrowning / datafiles / datafiles / formats.py View on Github external
def increase_indent(self, flow=False, indentless=False):
                return super().increase_indent(
                    flow=flow,
                    indentless=False if settings.INDENT_YAML_BLOCKS else indentless,
                )
github jacebrowning / datafiles / datafiles / formats.py View on Github external
def serialize(cls, data):
        from ruamel import yaml

        yaml.representer.RoundTripRepresenter.add_representer(
            types.List, yaml.representer.RoundTripRepresenter.represent_list
        )
        yaml.representer.RoundTripRepresenter.add_representer(
            types.Dict, yaml.representer.RoundTripRepresenter.represent_dict
        )

        if settings.INDENT_YAML_BLOCKS:
            f = StringIO()
            y = yaml.YAML()
            y.indent(mapping=2, sequence=4, offset=2)
            y.dump(data, f)
            text = f.getvalue().strip() + '\n'
        else:
            text = yaml.round_trip_dump(data) or ""

        if text == "{}\n":
            return ""

        return text.replace('- \n', '-\n')