How to use the tomlkit.table 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 sdispater / tomlkit / tests / test_build.py View on Github external
clients.add(nl())
    clients.add(comment("Line breaks are OK when inside arrays"))
    clients["hosts"] = array(
        """[
  "alpha",
  "omega"
]"""
    )

    doc.add(nl())
    doc.add(comment("Products"))

    products = aot()
    doc["products"] = products

    hammer = table().indent(2)
    hammer["name"] = "Hammer"
    hammer["sku"] = 738594937

    nail = table().indent(2)
    nail["name"] = "Nail"
    nail["sku"] = 284758393
    nail["color"] = "gray"

    products.append(hammer)
    products.append(nail)

    assert content == doc.as_string()
github dnkorpushov / libro / src / main / python / libro / converterconfig.py View on Github external
def generate_default():
    css_file = os.path.normpath(os.path.join(config.config_dir, 'default.css'))
    doc = document()
    doc.add(comment('fb2c configuration file'))
    doc.add(comment('Generated by Libro'))

    logger = table()

    logger_console = table()
    logger_console.add('level', 'none')

    logger_file = table()
    logger_file.add('level', 'debug')
    logger_file.add('destination', config.converter_log_file)
    logger_file.add('mode', 'overwrite')

    logger.add('console', logger_console)
    logger.add('file', logger_file)

    docum = table()

    docum.add('style', css_file)
    docum.add('remove_png_transparency', True)
    docum.add('title_format', '#title')
    docum.add('series_number_positions', 2)
    docum.add('author_format', '{#f }#l')
    docum.add('insert_soft_hyphen', False)
    docum.add('characters_per_page', 1200)
github sarugaku / requirementslib / src / requirementslib / models / pipfile.py View on Github external
def reorder_source_keys(data):
    # type: ignore
    sources = data["source"]  # type: sources_type
    for i, entry in enumerate(sources):
        table = tomlkit.table()  # type: Mapping
        source_entry = PipfileLoader.populate_source(entry.copy())
        table["name"] = source_entry["name"]
        table["url"] = source_entry["url"]
        table["verify_ssl"] = source_entry["verify_ssl"]
        data["source"][i] = table
    return data
github dephell / dephell / dephell / commands / generate_config.py View on Github external
def _make_env(from_format, from_path, to_format, to_path):
        table = tomlkit.table()

        table['from'] = tomlkit.inline_table()
        table['from']['format'] = from_format
        table['from']['path'] = from_path

        table['to'] = tomlkit.inline_table()
        table['to']['format'] = to_format
        table['to']['path'] = to_path

        return table
github sarugaku / passa / src / passa / projects.py View on Github external
def _get_pipfile_section(self, develop, insert=True):
        name = "dev-packages" if develop else "packages"
        try:
            section = self.pipfile[name]
        except KeyError:
            section = plette.models.PackageCollection(tomlkit.table())
            if insert:
                self.pipfile[name] = section
        return section
github greenbone / python-gvm / gvm / version.py View on Github external
def update_pyproject_version(
    new_version: str, pyproject_toml_path: Path,
) -> None:
    """
    Update the version in the pyproject.toml file
    """
    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 dephell / dephell / dephell / converters / poetry.py View on Github external
for group_name, group_content in section['plugins'].items():
                if group_name not in groups:
                    del section['plugins'][group_name]
                    continue
                for script_name in group_content:
                    if script_name not in groups[group_name]:
                        del section['plugins'][group_name][script_name]

        # add plugins
        for entrypoint in entrypoints:
            if entrypoint.group == 'console_scripts':
                continue
            if 'plugins' not in section:
                section['plugins'] = tomlkit.table()
            if entrypoint.group not in section['plugins']:
                section['plugins'][entrypoint.group] = tomlkit.table()
            section['plugins'][entrypoint.group][entrypoint.name] = entrypoint.path
github sarugaku / requirementslib / src / requirementslib / models / project.py View on Github external
def _get_pipfile_section(self, develop, insert=True):
        name = "dev-packages" if develop else "packages"
        try:
            section = self.pipfile[name]
        except KeyError:
            section = plette.models.PackageCollection(tomlkit.table())
            if insert:
                self.pipfile[name] = section
        return section
github dephell / dephell / dephell / converters / poetrylock.py View on Github external
def _format_req(self, req):
        result = tomlkit.table()
        for name, value in req:
            if name in self.fields:
                if isinstance(value, tuple):
                    value = list(value)
                result[name] = value
        result['category'] = 'dev' if req.is_dev else 'main'
        if 'version' not in result:
            result['version'] = '*'
        result['version'] = result['version'].lstrip('=')
        if req.markers:
            result['marker'] = req.markers

        # add link
        if req.link and (req.git or isinstance(req.link, DirLink)):
            result['source'] = tomlkit.table()
            if req.git:
github python-poetry / poetry / poetry / layouts / layout.py View on Github external
poetry_content["version"] = self._version
        poetry_content["description"] = self._description
        poetry_content["authors"].append(self._author)
        if self._license:
            poetry_content["license"] = self._license

        poetry_content["dependencies"]["python"] = self._python

        for dep_name, dep_constraint in self._dependencies.items():
            poetry_content["dependencies"][dep_name] = dep_constraint

        for dep_name, dep_constraint in self._dev_dependencies.items():
            poetry_content["dev-dependencies"][dep_name] = dep_constraint

        # Add build system
        build_system = table()
        build_system_version = ">=" + BUILD_SYSTEM_MIN_VERSION
        if BUILD_SYSTEM_MAX_VERSION is not None:
            build_system_version += ",<" + BUILD_SYSTEM_MAX_VERSION

        build_system.add("requires", ["poetry" + build_system_version])
        build_system.add("build-backend", "poetry.masonry.api")

        content.add("build-system", build_system)

        return dumps(content)