Bug #10347

Feature #9979: Support python3 for in-gate tools

git-pbchk requires more python3 fixes

Added by Andy Fiddaman about 2 years ago. Updated about 2 years ago.

tools - gate/build tools
Start date:
Due date:
% Done:


Estimated time:
Gerrit CR:


When running under python3, pbchk can produce a python stacktrace when spawning an external process such as cstyle.

Traceback (most recent call last):
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/git-pbchk", line 389, in <module>
    main(os.path.basename(sys.argv[0]), sys.argv[1:])
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/git-pbchk", line 381, in main
    pbchk(git_root(), parent_branch, None)
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/git-pbchk", line 348, in pbchk
    run_checks(root, parent, cmds)
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/git-pbchk", line 319, in run_checks
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/git-pbchk", line 266, in cstyle
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/../lib/python3.5/onbld/Checks/", line 55, in cstyle
    ret, tmpfile = processcheck('cstyle', options, fh, output)
  File "/build/illumos-omnios/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/../lib/python3.5/onbld/Checks/", line 63, in processcheck
TypeError: a bytes-like object is required, not 'str'

This is happening because git-pbchk is opening the file in non-binary mode (which in python 3 means as text with automatic character conversion from UTF-8 by default), but then attempting to feed this to a stdin pipe which needs bytes and not str.

The fix is for git-pbchk to open the file in binary mode when it is going to send the file handle over to be used on a pipe, which is the case for cstyle and manlint, and to make the backend processcheck function use a binary file handle to record the stdout.

However, since the manlint function in pbchk passes the same file handle to both manlint (which spawns an external perl process) and to spellcheck (which is internal in python), I have also modified spellcheck to do a binary->str conversion on lines read from the file handle which is in binary mode.


Updated by Andy Fiddaman about 2 years ago

  • Description updated (diff)

Updated by Andy Fiddaman about 2 years ago

  • Status changed from In Progress to Pending RTI
  • % Done changed from 90 to 100

Testing: Built and ran a `git-pbchk` against the last 100 commits in gate using both python2 and python3.


Updated by Electric Monk about 2 years ago

  • Status changed from Pending RTI to Closed

git commit a90997d2f0a442a8aa8a56cbbbbf577716a18742

commit  a90997d2f0a442a8aa8a56cbbbbf577716a18742
Author: Andy Fiddaman <>
Date:   2019-02-09T21:43:47.000Z

    10347 git-pbchk requires more python3 fixes
    Reviewed by: Sebastian Wiedenroth <>
    Reviewed by: C Fraire <>
    Reviewed by: John Levon <>
    Approved by: Joshua M. Clulow <>

Also available in: Atom PDF