docling-project/docling · error · DocumentLoadError

Could not initialize AsciiDoc backend for file with hash {se

Error message

Could not initialize AsciiDoc backend for file with hash {self.document_hash}.

What it means

Raised by the benchmark script's _runtime_info() helper when its regex `^version\s*=\s*"([^"]+)"` (MULTILINE) finds no match in the pyproject.toml located at Path(__file__).resolve().parents[1]. The script records the Docling version in every benchmark result line, so it refuses to run without it. This is a script-environment sanity check, not a Docling library error: it fires when the pyproject.toml next to perfs/ is missing, not a project file, or declares its version in a format the regex does not recognize.

Source

Thrown at docling/backend/asciidoc_backend.py:50


class AsciiDocBackend(DeclarativeDocumentBackend):
    def __init__(self, in_doc: "InputDocument", path_or_stream: Union[BytesIO, Path]):
        super().__init__(in_doc, path_or_stream)

        self.path_or_stream = path_or_stream

        try:
            if isinstance(self.path_or_stream, BytesIO):
                text_stream = self.path_or_stream.getvalue().decode("utf-8")
                self.lines = text_stream.split("\n")
            if isinstance(self.path_or_stream, Path):
                with open(self.path_or_stream, encoding="utf-8") as f:
                    self.lines = f.readlines()
            self.valid = True

        except Exception as e:
            raise DocumentLoadError(
                f"Could not initialize AsciiDoc backend for file with hash {self.document_hash}."
            ) from e
        return

    def is_valid(self) -> bool:
        return self.valid

    @classmethod
    def supports_pagination(cls) -> bool:
        return False

    def unload(self):
        return

    @classmethod
    def supported_formats(cls) -> set[InputFormat]:
        return {InputFormat.ASCIIDOC}

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Run the script from the Docling repository root as documented: `uv run python perfs/xlsx_merged_cells.py --merge-count 100` so parents[1] resolves to the real repo with its pyproject.toml.
  2. If you must run it elsewhere, ensure the directory containing perfs/ has a pyproject.toml with a top-level (or [project]-section) `version = "x.y.z"` line using double quotes.
  3. If your pyproject uses dynamic versioning, pin the version explicitly (remove `dynamic = ["version"]` and add `version = "..."`) or adjust the regex in _runtime_info() to also match your version source (e.g. `^version = '([^']+)'` or [tool.hatch.version] paths).
  4. Alternatively replace the pyproject parsing with `importlib.metadata.version("docling")` so the version comes from the installed package instead of the source tree.

Example fix

// before (perfs/xlsx_merged_cells.py:86-93)
pyproject_text = (repository_root / "pyproject.toml").read_text(encoding="utf-8")
version_match = re.search(r'^version\s*=\s*"([^"]+)"', pyproject_text, flags=re.MULTILINE)
if version_match is None:
    raise RuntimeError("Could not determine Docling version from pyproject.toml")

// after
from importlib.metadata import PackageNotFoundError, version as pkg_version
try:
    docling_version = pkg_version("docling")
except PackageNotFoundError:
    docling_version = "unknown"
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
import re

repository_root = Path("perfs/xlsx_merged_cells.py").resolve().parents[1]
pyproject = repository_root / "pyproject.toml"
if not pyproject.is_file():
    raise SystemExit(f"no pyproject.toml at {repository_root}; run from the Docling repo root")
text = pyproject.read_text(encoding="utf-8")
if re.search(r'^version\s*=\s*"([^"]+)"', text, flags=re.MULTILINE) is None:
    raise SystemExit("pyproject.toml has no double-quoted top-level version; script cannot record docling_version")

Try / catch

try:
    runtime_info = _runtime_info()
except (RuntimeError, FileNotFoundError, subprocess.CalledProcessError) as exc:
    raise SystemExit(f"cannot collect runtime info for benchmark: {exc}") from exc

Prevention

When it happens

Trigger: Running perfs/xlsx_merged_cells.py from anything other than a full Docling repository checkout (parents[1] of the script must be the repo root containing pyproject.toml); copying the script into another project whose pyproject.toml uses `dynamic = ["version"]` (PEP 621 dynamic version), a [tool.poetry] `version = "..."` line under a section with different indentation, single-quoted TOML strings, or version defined only in a submodule/package __init__.py. In this repo the top-level `version = "2.120.1"` matches, so the error only appears in modified/derived environments.

Common situations: Running the benchmark from an installed wheel/site-packages copy of the script; vendoring the script into a private benchmark repo that uses setuptools dynamic versioning or hatch version hooks; a pyproject.toml that was reformatted with single quotes or puts version inside [project] with unusual spacing/line continuations; running against a source tree where pyproject.toml was replaced by setup.py-only metadata.

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/ed22c9ff985f8162. Report an issue: GitHub.