Understanding the basics

Harald Seiler hws at denx.de
Tue Mar 24 11:09:25 CET 2020


Hello Simon,

On Mon, 2020-03-23 at 22:10 -0600, Simon Glass wrote:
> Hi,
> 
> Thanks for the pointer to join this list.
> 
> I am making progress with automation. Thank you for the help. I can
> definitely see the potential.
> 
> I am struggling with quite basic things in tbot.
> 
> One thing that I think would help is to use absolute imports:
> 
> import tbot.x.y
> 
> And never use from xx import
> 

If I am understanding you correctly with this, I totally agree:  The
relative imports (`from .* import *`) I have used across the code-base
need to be removed as they make following the code quite hard.  I don't
think from-imports in general are an anti-pattern as long as they are
strictly absolute:

    from tbot.machine import linux

IMO this is still easily understandable as long as module names don't
reappear across the hierarchy (so you can immediately know what is
referenced).  I think it also helps because you don't need to write the
fully qualified class path (e.g. `tbot.machine.linux.build.Toolchain`)
every time and `build.Toolchain` already contains enough information.

Although, on the other hand, the hierarchy is needlessly deep at the moment
and I am thinking about flattening it a bit (and at the same time pulling
components which don't relate too much further apart).

> Also remove everything from -the __init__.py files. Too much magic I think.

I'm not sure what you mean?  The __init__.py files should all just reexport
the names from the individual files in that module and define an `__all__`
so glob-imports work properly.

The only exception I know of is the madness in
tbot/machine/linux/__init__.py which is used to transparently provide
compatibility aliases so old testcases and configs still work.  You can
just assume that code does not exist though, because you shouldn't ever
need to use any of the old names.

-- 
Harald

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-62  Fax: +49-8142-66989-80   Email: hws at denx.de



More information about the tbot mailing list