Bug 195359

Summary: [GTK] Make Tools/gtkdoc/ python3 compatible
Product: WebKit Reporter: Tomas Popela <tpopela>
Component: WebKitGTKAssignee: Tomas Popela <tpopela>
Status: RESOLVED FIXED    
Severity: Normal CC: bugs-noreply, cgarcia, ews-watchlist
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch cgarcia: review+

Description Tomas Popela 2019-03-06 06:39:17 PST
In bug 106195 the Tools/gtk/generate-gtkdoc was made Python 3 compatible. But using Python 3.7.2 I can't make the 2.23.91 tarball to build with -DPYTHON_EXECUTABLE=%{_bindir}/python3 passed to cmake.

It fails with:

FAILED: docs-build.stamp
cd /home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/x86_64-redhat-linux-gnu && /usr/bin/cmake -E env CC=/usr/lib64/ccache/cc "CFLAGS=-fdiagnostics-color=always -Wextra -Wall -Wno-expansion-to-defined -Wno-maybe-uninitialized -Wwrite-strings -Wundef -Wpointer-arith -Wmissing-format-attribute -Wformat-security -Wcast-align -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -DUSER_AGENT_GTK_DISTRIBUTOR_NAME='\"Fedora\"' -fno-strict-aliasing -fno-exceptions -Wno-unused-parameter" /home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc --gtk && touch docs-build.stamp
Traceback (most recent call last):
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 19, in <module>
    from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'

because the ConfigParser module was reworked in Python 3.2 (see https://github.com/jaraco/configparser/#configparser). We need to make the import Python 2 and 3 compatible.

Also there is another error when the import is fixed:

Traceback (most recent call last):
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 252, in <module>
    build_gtkdoc_for_wkgtk(arguments)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 201, in build_gtkdoc_for_wkgtk
    jsc_generator = get_generator_for_config(common.build_path('gtkdoc-jsc-glib.cfg'), arguments.virtual_root)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 136, in get_generator_for_config
    'cross_reference_deps': get_gtkdoc_module_paths(cross_reference_deps),
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 60, in get_gtkdoc_module_paths
    for package, modules in dependent_packages.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

We should user items() instead of iteritems().

Patch follows.
Comment 1 Tomas Popela 2019-03-07 05:02:40 PST
Another error hit in Tools/gtkdoc/gtkdoc.py:

Traceback (most recent call last):
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 257, in <module>
    build_gtkdoc_for_wkgtk(arguments)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 219, in build_gtkdoc_for_wkgtk
    saw_warnings = generate_documentation(webkitdom_generator)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 161, in generate_documentation
    return generate_doc(generator, arguments.skip_html)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/generate-gtkdoc", line 148, in generate_doc
    generator.generate(not skip_html)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/gtkdoc.py", line 154, in generate
    self._run_gtkdoc_fixxref()
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/gtkdoc.py", line 383, in _run_gtkdoc_fixxref
    self._run_command(args, cwd=self.output_dir, ignore_warnings=True)
  File "/home/tpopela/dev/fedora/webkit2gtk3/webkitgtk-2.23.91/Tools/gtkdoc/gtkdoc.py", line 203, in _run_command
    sys.stdout.write(stdout.encode("utf-8"))
TypeError: write() argument must be str, not bytes
Comment 2 Tomas Popela 2019-03-07 06:22:16 PST
Created attachment 363871 [details]
Patch
Comment 3 EWS Watchlist 2019-03-07 06:25:01 PST
Attachment 363871 [details] did not pass style-queue:


ERROR: Tools/gtkdoc/gtkdoc.py:205:  [GTKDoc._run_command] Instance of 'file' has no 'buffer' member  [pylint/E1101] [5]
Total errors found: 1 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Carlos Garcia Campos 2019-03-07 07:54:41 PST
Comment on attachment 363871 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363871&action=review

> Tools/gtkdoc/generate-gtkdoc:120
> +    if sys.version_info < (3, 2):
> +        config = SafeConfigParser();
> +    else:
> +        config = configparser.ConfigParser()

Could we do something like:

from ConfigParser import SafeConfigParser as ConfigParser

and

from configparser import ConfigParser

and then we don't need to check version here again?
Comment 5 Tomas Popela 2019-03-07 23:06:52 PST
(In reply to Carlos Garcia Campos from comment #4)
> Comment on attachment 363871 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=363871&action=review
> 
> > Tools/gtkdoc/generate-gtkdoc:120
> > +    if sys.version_info < (3, 2):
> > +        config = SafeConfigParser();
> > +    else:
> > +        config = configparser.ConfigParser()
> 
> Could we do something like:
> 
> from ConfigParser import SafeConfigParser as ConfigParser
> 
> and
> 
> from configparser import ConfigParser
> 
> and then we don't need to check version here again?

Good catch Carlos!
Comment 6 Tomas Popela 2019-03-07 23:11:58 PST
Committed r242637: <https://trac.webkit.org/changeset/242637>