How to use the tomlkit.loads 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 dry-python / dependencies / tests / View on Github external
def test_poetry_deps_not_pinned():
    """Dependencies of pyproject.toml files should not have versions."""
    for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]:
        pyproject_toml = tomlkit.loads(open(pyproject_toml).read())
        versions = [
            for d in pyproject_toml["tool"]["poetry"].get("dependencies", {}).values()
            if isinstance(d, dict)
        assert all(v == "*" for v in versions)
github dry-python / stories / tests / View on Github external
def test_packages_are_ordered():
    """Packages of pyproject.toml files should be in order."""
    for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]:
        pyproject_toml = tomlkit.loads(open(pyproject_toml).read())
        packages = [
            re.sub(r"\.py$", "", p["include"])
            for p in pyproject_toml["tool"]["poetry"]["packages"]
        assert packages == sorted(packages)
github jacebrowning / datafiles / datafiles / View on Github external
def deserialize(cls, file_object):
        import tomlkit

        return tomlkit.loads(
github dnkorpushov / libro / src / main / python / libro / utils / View on Github external
def set_converter_log_file(converter_config, log_file):
    if os.path.exists(converter_config):
        with, mode='r', encoding='utf-8') as f:
            doc = tomlkit.loads(

        doc['logger']['file']['level'] = 'normal'
        doc['logger']['file']['destination'] = log_file
        doc['logger']['file']['mode'] = 'overwrite'

        with, mode='w', encoding='utf-8') as f:
github pypa / pipenv / pipenv / vendor / requirementslib / View on Github external
def is_installable_dir(path):
    # type: (STRING_TYPE) -> bool
    if pip_shims.shims.is_installable_dir(path):
        return True
    pyproject_path = os.path.join(path, "pyproject.toml")
    if os.path.exists(pyproject_path):
        pyproject = Path(pyproject_path)
        pyproject_toml = tomlkit.loads(pyproject.read_text())
        build_system = pyproject_toml.get("build-system", {}).get("build-backend", "")
        if build_system:
            return True
    return False
github TankerHQ / tbump / tbump / View on Github external
def parse(cfg_path: Path) -> Config:
    parsed = tomlkit.loads(cfg_path.text())
    parsed = validate_basic_schema(parsed)
    current_version = parsed["version"]["current"]
    git_message_template = parsed["git"]["message_template"]
    git_tag_template = parsed["git"]["tag_template"]
    version_regex = re.compile(parsed["version"]["regex"], re.VERBOSE)
    files = []
    for file_dict in parsed["file"]:
        file_config = File(

    hooks = []
    for hook_type in ("hook", "before_push", "before_commit", "after_push"):
github pypa / pipenv / pipenv / vendor / requirementslib / models / View on Github external
def load(cls, f, encoding=None):
        # type: (Any, Text) -> PipfileLoader
        content =
        if encoding is not None:
            content = content.decode(encoding)
        _data = tomlkit.loads(content)
        _data["source"] = _data.get("source", []) + _data.get("sources", [])
        _data = reorder_source_keys(_data)
        if "source" not in _data:
            if "sources" in _data:
                _data["source"] = _data["sources"]
                content = tomlkit.dumps(_data)
                # HACK: There is no good way to prepend a section to an existing
                # TOML document, but there's no good way to copy non-structural
                # content from one TOML document to another either. Modify the
                # TOML content directly, and load the new in-memory document.
                sep = "" if content.startswith("\n") else "\n"
                content = plette.pipfiles.DEFAULT_SOURCE_TOML + sep + content
        data = tomlkit.loads(content)
        instance = cls(data)
        instance._data = dict(instance._data)
github sarugaku / passa / src / passa / models / View on Github external
def as_data(self):
        data = {
            "source": [source.as_data() for source in self.sources],
            "packages": {
                k: v.as_pipfile()[k] for k, v in self.packages.items()
            "dev-packages": {
                k: v.as_pipfile()[k] for k, v in self.dev_packages.items()
            "requires": self.requires.as_data(),
            k: tomlkit.loads(tomlkit.dumps(v))
            for k, v in self._data.items()
            if k not in data
        return data
github dictation-toolbox / Caster / castervoice / lib / View on Github external
def _validate_engine_path():
    Validates path 'Engine Path' in settings.toml
    if not sys.platform.startswith('win'):
        return ''
        # pylint: disable=import-error
        import natlink
    except ImportError:
        return ''
    if os.path.isfile(_SETTINGS_PATH):
        with, "rt", encoding="utf-8") as toml_file:
            data = tomlkit.loads(
            engine_path = data["paths"]["ENGINE_PATH"]
            if os.path.isfile(engine_path):
                return engine_path
                engine_path = _find_natspeak()
                data["paths"]["ENGINE_PATH"] = engine_path
                    formatted_data = unicode(tomlkit.dumps(data))
                    with, "w", encoding="utf-8") as toml_file:
                    print("Setting engine path to " + engine_path)
                except Exception as e:
                    print("Error saving settings file ") + str(e) + _SETTINGS_PATH
                return engine_path
        return _find_natspeak()