<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>14711</bug_id>
          
          <creation_ts>2022-02-01 17:32:19 +0000</creation_ts>
          <short_desc>bitbake: Use a standard python code formatter</short_desc>
          <delta_ts>2022-02-03 15:51:00 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>5.99</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Randy MacLeod">randy.macleod</reporter>
          <assigned_to name="Richard Purdie">richard.purdie</assigned_to>
          <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Yes (doc changes required)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>92444</commentid>
    <comment_count>0</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2022-02-01 17:32:19 +0000</bug_when>
    <thetext>At the start of the 3.6 release, start using a python code formatter.


The &apos;black&apos; python code formatter or any other widely used formatter could be used to standardize bitbake&apos;s code format more than has been done already.

Black&apos;s README ( https://github.com/psf/black ) says:
---
Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Blackened code looks the same regardless of the project you&apos;re reading. Formatting becomes transparent after a while and you can focus on the content instead.

Black makes code review faster by producing the smallest diffs possible.
---

Black is used by a number of well known python projects:
https://github.com/psf/black#used-by</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92445</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2022-02-01 17:51:32 +0000</bug_when>
    <thetext>Running:
$ for i in `ls lib/bb/*py`; do echo $i; black $i; done

results in diffs below. bitbake works well without any manual changes and bitbake-selftest also completes without error.


Running:
$ for i in `ls lib/bb/*py`; do echo $i; black $i; done

results in:
$ git diff | diffstat 
 COW.py                 |   37 -
 __init__.py            |   71 +-
 build.py               |  401 +++++++++------
 cache.py               |  242 +++++----
 cache_extra.py         |   36 -
 checksum.py            |   12 
 codeparser.py          |   84 ++-
 command.py             |  159 ++++--
 cooker.py              |  844 +++++++++++++++++++++++---------
 cookerdata.py          |  249 ++++++---
 daemonize.py           |   11 
 data.py                |  192 +++++--
 data_smart.py          |  440 +++++++++--------
 event.py               |  246 +++++++--
 exceptions.py          |   40 -
 main.py                |  639 +++++++++++++++++-------
 methodpool.py          |    4 
 monitordisk.py         |  116 +++-
 msg.py                 |  131 +++--
 namedtuple_with_abc.py |   66 +-
 persist_data.py        |   52 +-
 process.py             |   25 
 progress.py            |   52 +-
 providers.py           |  153 ++++-
 remotedata.py          |    5 
 runqueue.py            | 1242 ++++++++++++++++++++++++++++++++++++------------
 siggen.py              |  765 +++++++++++++++++++----------
 taskdata.py            |  208 ++++++--
 tinfoil.py             |  400 +++++++++------
 29 files changed, 4788 insertions(+), 2134 deletions(-)



Here&apos;s an example of the changes made for a short diff: process.py:

---

$ git diff lib/bb/process.py | cat
diff --git a/lib/bb/process.py b/lib/bb/process.py
index af5d804a..3d9f2732 100644
--- a/lib/bb/process.py
+++ b/lib/bb/process.py
@@ -9,13 +9,15 @@ import errno
 import select
 import bb
 
-logger = logging.getLogger(&apos;BitBake.Process&apos;)
+logger = logging.getLogger(&quot;BitBake.Process&quot;)
+
 
 def subprocess_setup():
     # Python installs a SIGPIPE handler by default. This is usually not what
     # non-Python subprocesses expect.
     signal.signal(signal.SIGPIPE, signal.SIG_DFL)
 
+
 class CmdError(RuntimeError):
     def __init__(self, command, msg=None):
         self.command = command
@@ -29,15 +31,17 @@ class CmdError(RuntimeError):
 
         msg = &quot;Execution of &apos;%s&apos; failed&quot; % cmd
         if self.msg:
-            msg += &apos;: %s&apos; % self.msg
+            msg += &quot;: %s&quot; % self.msg
         return msg
 
+
 class NotFoundError(CmdError):
     def __str__(self):
         return CmdError.__str__(self) + &quot;: command not found&quot;
 
+
 class ExecutionError(CmdError):
-    def __init__(self, command, exitcode, stdout = None, stderr = None):
+    def __init__(self, command, exitcode, stdout=None, stderr=None):
         CmdError.__init__(self, command)
         self.exitcode = exitcode
         self.stdout = stdout
@@ -52,8 +56,13 @@ class ExecutionError(CmdError):
             message += self.stdout
         if message:
             message = &quot;:\n&quot; + message
-        return (CmdError.__str__(self) +
-                &quot; with exit code %s&quot; % self.exitcode + message + (self.extra_message or &quot;&quot;))
+        return (
+            CmdError.__str__(self)
+            + &quot; with exit code %s&quot; % self.exitcode
+            + message
+            + (self.extra_message or &quot;&quot;)
+        )
+
 
 class Popen(subprocess.Popen):
     defaults = {
@@ -70,6 +79,7 @@ class Popen(subprocess.Popen):
         options.update(kwargs)
         subprocess.Popen.__init__(self, *args, **options)
 
+
 def _logged_communicate(pipe, log, input, extrafiles):
     if pipe.stdin:
         if input is not None:
@@ -106,7 +116,7 @@ def _logged_communicate(pipe, log, input, extrafiles):
         stderrbuf = b&quot;&quot;
 
         try:
-            r,w,e = select.select (rlist, [], [], 1)
+            r, w, e = select.select(rlist, [], [], 1)
         except OSError as e:
             if e.errno != errno.EINTR:
                 raise
@@ -151,7 +161,8 @@ def _logged_communicate(pipe, log, input, extrafiles):
         pipe.stdout.close()
     if pipe.stderr is not None:
         pipe.stderr.close()
-    return &apos;&apos;.join(outdata), &apos;&apos;.join(errdata)
+    return &quot;&quot;.join(outdata), &quot;&quot;.join(errdata)
+
 
 def run(cmd, input=None, log=None, extrafiles=None, **options):
     &quot;&quot;&quot;Convenience function to run a command and return its output, raising an

---

FYI, running on my laptop:
---
$ bitbake-selftest 
......................................................................................................................................................................................................................................................................................................ssss.ssssssssssssssss.sssss..........................................................................................................................................
----------------------------------------------------------------------
Ran 459 tests in 957.812s

OK (skipped=25)
$ echo $?
0
---</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92459</commentid>
    <comment_count>2</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2022-02-03 15:51:00 +0000</bug_when>
    <thetext>We have an older code-base and we&apos;re happy with out existing formatting conventions. We can adapt the code-base as we update individual files.
We don&apos;t want a big transition that will make tracing changes across the commit mess difficult.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>