File: _toml.py

package info (click to toggle)
python-cyclopts 3.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,288 kB
  • sloc: python: 11,445; makefile: 24
file content (17 lines) | stat: -rw-r--r-- 553 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from pathlib import Path
from typing import Any

from cyclopts.config._common import ConfigFromFile


class Toml(ConfigFromFile):
    def _load_config(self, path: Path) -> dict[str, Any]:
        try:
            # Attempt to use builtin >=python3.11
            import tomllib  # pyright: ignore[reportMissingImports]
        except ImportError:
            # Fallback to most popular pypi toml package.
            import tomli as tomllib  # pyright: ignore[reportMissingImports]

        with path.open("rb") as f:
            return tomllib.load(f)