How to use the tomlkit.dumps function in tomlkit

To help you get started, we’ve selected a few tomlkit 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 greenbone / python-gvm / gvm / version.py View on Github external
"""
    version = safe_version(new_version)

    pyproject_toml = tomlkit.parse(pyproject_toml_path.read_text())

    if 'tool' not in pyproject_toml:
        tool_table = tomlkit.table()
        pyproject_toml['tool'] = tool_table

    if 'poetry' not in pyproject_toml['tool']:
        poetry_table = tomlkit.table()
        pyproject_toml['tool'].add('poetry', poetry_table)

    pyproject_toml['tool']['poetry']['version'] = version

    pyproject_toml_path.write_text(tomlkit.dumps(pyproject_toml))
github dictation-toolbox / Caster / castervoice / lib / settings.py View on Github external
try:
        # pylint: disable=import-error
        import natlink
    except ImportError:
        return ''
    if os.path.isfile(_SETTINGS_PATH):
        with io.open(_SETTINGS_PATH, "rt", encoding="utf-8") as toml_file:
            data = tomlkit.loads(toml_file.read()).value
            engine_path = data["paths"]["ENGINE_PATH"]
            if os.path.isfile(engine_path):
                return engine_path
            else:
                engine_path = _find_natspeak()
                data["paths"]["ENGINE_PATH"] = engine_path
                try:
                    formatted_data = unicode(tomlkit.dumps(data))
                    with io.open(_SETTINGS_PATH, "w", encoding="utf-8") as toml_file:
                        toml_file.write(formatted_data)
                    print("Setting engine path to " + engine_path)
                except Exception as e:
                    print("Error saving settings file ") + str(e) + _SETTINGS_PATH
                return engine_path
    else:
        return _find_natspeak()
github pypa / pipenv / pipenv / project.py View on Github external
def write_toml(self, data, path=None):
        """Writes the given data structure out as TOML."""
        if path is None:
            path = self.pipfile_location
        data = convert_toml_outline_tables(data)
        try:
            formatted_data = tomlkit.dumps(data).rstrip()
        except Exception:
            document = tomlkit.document()
            for section in ("packages", "dev-packages"):
                document[section] = tomlkit.container.Table()
                # Convert things to inline tables — fancy :)
                for package in data.get(section, {}):
                    if hasattr(data[section][package], "keys"):
                        table = tomlkit.inline_table()
                        table.update(data[section][package])
                        document[section][package] = table
                    else:
                        document[section][package] = tomlkit.string(data[section][package])
            formatted_data = tomlkit.dumps(document).rstrip()

        if (
            vistir.compat.Path(path).absolute()
github jacebrowning / datafiles / datafiles / formats.py View on Github external
def serialize(cls, data):
        import tomlkit

        return tomlkit.dumps(data)
github pypa / pipenv / pipenv / project.py View on Github external
data = convert_toml_outline_tables(data)
        try:
            formatted_data = tomlkit.dumps(data).rstrip()
        except Exception:
            document = tomlkit.document()
            for section in ("packages", "dev-packages"):
                document[section] = tomlkit.container.Table()
                # Convert things to inline tables — fancy :)
                for package in data.get(section, {}):
                    if hasattr(data[section][package], "keys"):
                        table = tomlkit.inline_table()
                        table.update(data[section][package])
                        document[section][package] = table
                    else:
                        document[section][package] = tomlkit.string(data[section][package])
            formatted_data = tomlkit.dumps(document).rstrip()

        if (
            vistir.compat.Path(path).absolute()
            == vistir.compat.Path(self.pipfile_location).absolute()
        ):
            newlines = self._pipfile_newlines
        else:
            newlines = DEFAULT_NEWLINES
        formatted_data = cleanup_toml(formatted_data)
        with io.open(path, "w", newline=newlines) as f:
            f.write(formatted_data)
        # pipfile is mutated!
        self.clear_pipfile_cache()