Re: [libgpiod v2][PATCH v4 2/4] bindings: python: add examples

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 26, 2022 at 2:53 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> On Wed, Oct 26, 2022 at 02:34:23PM +0200, Bartosz Golaszewski wrote:
> > This adds the regular set of example programs implemented using libgpiod
> > python bindings.
>
> ...
>
> > +if __name__ == "__main__":
> > +    for chip in gpio_chips():
> > +        info = chip.get_info()
> > +        print("{} [{}] ({} lines)".format(info.name, info.label, info.num_lines))
>
> In all of them I would prefer to see the main() explicitly, like
>
> def main():
>         ...
>
> if __name__ == "__main__":
>     main()
>
> (In this case the module can be imported by another one and main be reused)
>
> Also have you considered use of SystemExit() wrapper?
>
> ...
>
> > +                    sys.exit(0)
> > +
> > +    sys.exit(1)
>
> Is it in the original C code?!
> I would expect that no chips -- no error.
>
> ...
>
> > +if __name__ == "__main__":
> > +    if len(sys.argv) < 3:
> > +        raise TypeError("usage: gpioget.py <gpiochip> <offset1> <offset2> ...")
>
>         SystemExit(main(sys.argv)) ?
>
> > +    path = sys.argv[1]
> > +    lines = [int(line) if line.isdigit() else line for line in sys.argv[2:]]
> > +
> > +    request = gpiod.request_lines(
> > +        path,
> > +        consumer="gpioget.py",
> > +        config={tuple(lines): gpiod.LineSettings(direction=Direction.INPUT)},
> > +    )
> > +
> > +    vals = request.get_values()
> > +
> > +    for val in vals:
> > +        print("{} ".format(val.value), end="")
>
> > +    print()
>
> Without any conditional it will print an empty line, was it originally in the C
> variant?
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

Thanks Andy but this is unnecessary churn, these are literally just
code samples. Unless some new issues pop up for the other patches,
I'll leave it like that and apply it to master. Then we can work on it
further in there.

Bart



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux