How to use the anyconfig.ioinfo.make function in anyconfig

To help you get started, we’ve selected a few anyconfig 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 ssato / python-anyconfig / tests / backend / common.py View on Github external
def _to_ioinfo(self, path):
        return anyconfig.ioinfo.make(path)
github ssato / python-anyconfig / tests / processors.py View on Github external
def test_20_find__maybe_file(self):
        self.assertEqual(TT.findall("/path/to/a.jsn", PRS), [A3, A2, A])
        self.assertEqual(TT.findall("../../path/to/b.yml", PRS), [B, C])

        obj = anyconfig.ioinfo.make("/path/to/a.json")
        self.assertEqual(TT.findall(obj, PRS), [A3, A2, A])
github ssato / python-anyconfig / tests / processors.py View on Github external
def test_32_find__maybe_file(self):
        self.assertEqual(TT.find("/path/to/a.jsn", PRS), A3)
        self.assertEqual(TT.find("../../path/to/b.yml", PRS), B)

        obj = anyconfig.ioinfo.make("/path/to/a.json")
        self.assertEqual(TT.find(obj, PRS), A3)
github ssato / python-anyconfig / src / anyconfig / api.py View on Github external
File path or file or file-like object or pathlib.Path object represents
        the file or a namedtuple 'anyconfig.globals.IOInfo' object represents
        some input to load some data from
    :param ac_parser: Forced parser type or parser object itself
    :param ac_template:
        Assume configuration file may be a template file and try to compile it
        AAR if True
    :param ac_context: A dict presents context to instantiate template
    :param options:
        Optional keyword arguments :func:`single_load` supports except for
        ac_schema and ac_query

    :return: Mapping object
    :raises: ValueError, UnknownProcessorTypeError, UnknownFileTypeError
    """
    ioi = anyconfig.ioinfo.make(input_)
    psr = find(ioi, forced_type=ac_parser)
    filepath = ioi.path

    # .. note::
    #    This will be kept for backward compatibility until 'ignore_missing'
    #    option is deprecated and removed completely.
    if "ignore_missing" in options:
        warnings.warn("keyword option 'ignore_missing' is deprecated, use "
                      "'ac_ignore_missing' instead", DeprecationWarning)
        options["ac_ignore_missing"] = options["ignore_missing"]

    LOGGER.info("Loading: %s", filepath)
    if ac_template and filepath is not None:
        content = anyconfig.template.try_render(filepath=filepath,
                                                ctx=ac_context, **options)
        if content is not None:
github ssato / python-anyconfig / src / anyconfig / processors.py View on Github external
def find_by_maybe_file(obj, prs):
    """
    :param obj:
        a file path, file or file-like object, pathlib.Path object or an
        'anyconfig.globals.IOInfo' (namedtuple) object
    :param cps_by_ext: A list of processor classes
    :return: A list of processor classes to process given (maybe) file
    :raises: UnknownFileTypeError
    """
    if not isinstance(obj, IOInfo):
        obj = anyconfig.ioinfo.make(obj)

    return find_by_fileext(obj.extension, prs)  # :: [Processor], never []