1
  <   'ˆl—äY>”*h¥2 Y¸ÛweLZ7ÿ’þHE›”d�º'[ ›Ù«þØÑÐ×165ÏÈÕ  ¥    '‹      uŽÝ
ƒ0Fïû�	u 8¬c�°w°¸ ÂêOe ¾ûZa—»	äp’ï[C`š—ž)×Æ`?ñàÞé3�,ú|WkôBßUï¤+“‘l…õ3“Hž¤_‰v"S°ˆÒ\n†bBã]u­ð¨)ýïBeùâ¸%± Ó#]@7á…`/`Sp²ÇT{LýñdÌ     !   )ˆÆ�þZ}éVq²‘¸Ý�Jð?ŸØ„Ï2×ÉÈÕ ?÷     )"""
Load setuptools configuration from ``pyproject.toml`` files.

**PRIVATE MODULE**: API reserved for setuptools internal usage only.

To read project metadata, consider using
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
For simple scenarios, you can also try parsing the file directly
with the help of ``tomllib`` or ``tomli``.
"""

from __future__ import annotations

import logging
import os
from collections.abc import Callable, Mapping
from contextlib import contextmanager
from functools import partial
from types import TracebackType
from typing import TYPE_CHECKING, Any

from .._path import StrPath
from ..errors import FileError, InvalidConfigError
from ..warnings import SetuptoolsWarning
from . import expand as _expand
from ._apply_pyprojecttoml import _PREVIOUSLY_DEFINED, _MissingDynamic, apply as _apply

if TYPE_CHECKING:
    from typing_extensions import Self

    from setuptools.dist import Distribution

_logger = logging.getLogger(__name__)


def load_file(filepath: StrPath) -> dict:
    from ..compat.py310 import tomllib

    with open(filepath, "rb") as file:
        return tomllib.load(file)


def validate(config: dict, filepath: StrPath) -> bool:
    from . import _validate_pyproject as validator

    trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")
    if hasattr(trove_classifier, "_disable_download"):
        # Improve reproducibility by default. See abravalheri/validate-pyproject#31
        trove_classifier._disable_download()  # type: ignore[union-attr]

    try:
        return validator.validate(config)
    except validator.ValidationError as ex:
        summary = f"configuration error: {ex.summary}"
        if ex.name.strip("`") != "project":
            # Probably it is just a field missing/misnamed, not worthy the verbosity...
            _logger.debug(summary)
            _logger.debug(ex.details)

        error = f"invalid pyproject.toml config: {ex.name}."
        raise ValueError(f"{error}\n{summary}") from None


def apply_configuration(
    dist: Distribution,
    filepath: StrPath,
    ignore_option_errors: bool = False,
) -> Distribution:
    """Apply the configuration from a ``pyproject.toml`` file into an existing
    distribution object.
    """
    config = read_configuration(filepath, True, ignore_option_errors, dist)
    return _apply(dist, config, filepath)


def read_configuration(
    filepath: StrPath,
    expand: bool = True,
    ignore_option_errors: bool = False,
    dist: Distribution | None = None,
) -> dict[str, Any]:
    """Read given configuration file and returns options from it as a dict.

    :param str|unicode filepath: Path to configuration file in the ``pyproject.toml``
        format.

    :param bool expand: Whether to expand directives and other computed values
        (i.e. post-process the given configuration)

    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.

    :param Distribution|None: Distribution object to which the configuration refers.
        If not given a dummy object will be created and discarded after the
        configuration is read. This is used for auto-discovery of packages and in the
        case a dynamic configuration (e.g. ``attr`` or ``cmdclass``) is expanded.
        When ``expand=False`` this object is simply ignored.

    :rtype: dict
    """
    filepath = os.path.abspath(filepath)

    if not os.path.isfile(filepath):
        raise FileError(f"Configuration file {filepath!r} does not exist.")

    asdict = load_file(filepath) or {}
    project_table = asdict.get("project", {})
    tool_table = asdict