From: Alexandre Detiste Date: Fri, 16 May 2025 13:40:50 +0200 Subject: Prefer tomllib from the Standard Library when available --- docs/conf.py | 9 +++++++-- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index dc974a9..fae6398 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,8 +4,13 @@ import sys from pathlib import Path # Ensure documentation examples are deterministically random. +try: + # Added in Python 3.11 + import tomllib +except ImportError + import tomli as tomllib + import numpy -import tomli from pkg_resources import get_distribution try: @@ -21,7 +26,7 @@ except ImportError: # Get configuration information from `pyproject.toml` with open(Path(__file__).parent.parent / "pyproject.toml", "rb") as configuration_file: - conf = tomli.load(configuration_file) + conf = tomllib.load(configuration_file) configuration = conf["project"] # -- General configuration ---------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index b49bf41..db78946 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dynamic = ['version'] [project.optional-dependencies] docs = [ - 'tomli', + 'tomli; python_version < "3.11"', 'sphinx', 'sphinx-asdf >= 0.1.3', 'sphinx-astropy',