Gi_docgen KeyError: 'filename'

I want to generate local gtk documentation but I get the following error

(by modifying meson_options.txt gtk_doc)

gi-docgen version 2023.2
gtk 4.13.0

/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gi-docgen.py generate --quiet --no-namespace-dir --add-include-path=/home/demo/project/open_source_project/gtk/_build/docs/reference/gdk/../../../gtk --config=docs/reference/gdk/gdk4-wayland.toml --output-dir=docs/reference/gdk/gdk4-wayland --content-dir=/home/demo/project/open_source_project/gtk/docs/reference/gdk gtk/GdkWayland-4.0.gir
Traceback (most recent call last):
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gidocmain.py", line 78, in run
    res = options.run_func(options)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gdgenerate.py", line 3174, in run
    parser.parse(options.infile)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 92, in parse
    repository = self._parse_tree(tree.getroot())
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 242, in _parse_tree
    self._parse_dependency(include)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 191, in _parse_dependency
    repository = self._parse_tree(tree.getroot())
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 242, in _parse_tree
    self._parse_dependency(include)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 191, in _parse_dependency
    repository = self._parse_tree(tree.getroot())
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 268, in _parse_tree
    parser_method(node, repository, namespace)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 687, in _parse_enumeration
    members.append(self._parse_enum_member(child))
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 677, in _parse_enum_member
    self._maybe_parse_docs(node, res)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 320, in _maybe_parse_docs
    doc = self._maybe_parse_doc(node)
  File "/home/demo/project/open_source_project/gtk/subprojects/gi-docgen/gidocgen/gir/parser.py", line 290, in _maybe_parse_doc
    return ast.Doc(content=content, filename=child.attrib['filename'], line=int(child.attrib['line']))
KeyError: 'filename'

I don’t understand why Gtk – 4.0 Capable of production. But I cannot generate it, even if the library is the latest

I mean: it works in CI and for people building it, except for you.

It seems that there’s a doc element that does not have a filename attribute. Check in the GIR file for a match.

I know, but I did it by modifying meson_options.txt gtk_doc to generate.

So does it indicate meson_options.txt gtk_doc option is not applicable to everyone?

What did you modify? Did you configure the GTK build with something like this:

meson setup -Dgtk_doc=true build

for instance?

No, that’s not what I meant at all.

Your problem is caused by an element in the introspection XML not having a filename attribute; you have to look into the generated XML and check which doc element is missing the filename attribute.

$ /bin/meson setup --buildtype debug --prefix  /home/demo/project/open_source_project/gtk/_build/4.13.0 -Dgtk_doc=true build
$ cd build
$ ninja instal

Got the same error

That’s not how you configure and build GTK.

As the documentation says, use:

meson setup --buildtype debug \
      --prefix whatever \
      -Dintrospection=enabled \
      -Dgtk_doc=true build
meson compile -C build
meson install -C build

You still haven’t answered the question: have you checked in the GIR XML file and located the doc element without the filename attribute?

meson setup --buildtype debug \
      --prefix whatever \
      -Dintrospection=enabled \
      -Dgtk_doc=true build 
meson compile -C build

Got the same error

You still haven’t answered the question: have you checked in the GIR XML file and located the doc element without the filename attribute?

I don’t know what this is, how to obtain it, and where is it stored?

It’s listed here:

You want GdkWayland-4.0.gir in the build directory.

It’s not my wish, it’s beyond my control. I only need gtk gsk gdk

Actually, multiple targets have errors

  • FAILED: docs/reference/gdk/gdk4-x11
  • FAILED: docs/reference/gdk/gdk4 wayland
  • FAILED: docs/reference/gdk/gdk4
  • FAILED: docs/reference/gsk/gsk4
$ find . -name "*.gir"
./build/gtk/Gtk-4.0.gir
./build/gtk/GdkWayland-4.0.gir
./build/gtk/Gsk-4.0.gir
./build/gtk/Gdk-4.0.gir
./build/gtk/GdkX11-4.0.gir
./subprojects/gi-docgen/test/gir/Regress-1.0.gir
./subprojects/gi-docgen/test/gir/Utility-1.0.gir
./subprojects/gi-docgen/test/gir/GLib-2.0.gir
./subprojects/gi-docgen/test/gir/cairo-1.0.gir
./subprojects/gi-docgen/test/gir/GObject-2.0.gir
./subprojects/gi-docgen/test/gir/Gio-2.0.gir
./_build/gtk/Gtk-4.0.gir
./_build/gtk/GdkWayland-4.0.gir
./_build/gtk/Gsk-4.0.gir
./_build/gtk/Gdk-4.0.gir
./_build/gtk/GdkX11-4.0.gir

Which GIR XML file should I choose as the target? How can I confirm that the doc element is missing a filename attribute? Due to the large size of the file, tools are needed for retrieval.

I can only modify the gir/parser.py:_maybe_parse_doc function to further detect variable values

        filename = child.attrib.get('filename')
        line     = child.attrib.get('line')
        if filename is None or line is None:
            return None;

        return ast.Doc(content=content, filename=filename, line=int(line))

Anyway, now I have the document, although I don’t know if there may be any problems.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.