All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni via buildroot <buildroot@buildroot.org>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: "Yann E. MORIN" <yann.morin.1998@free.fr>, buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH v2 2/2] utils/scanpypi: add flit package support
Date: Wed, 3 Aug 2022 23:46:41 +0200	[thread overview]
Message-ID: <20220803234641.346d9c9c@windsurf> (raw)
In-Reply-To: <20220313171355.271345-2-james.hilliard1@gmail.com>

On Sun, 13 Mar 2022 11:13:55 -0600
James Hilliard <james.hilliard1@gmail.com> wrote:

> +def toml_load(f):
> +    with open(f, 'rb') as fh:
> +        ex = None
> +
> +        # Try regular tomli first
> +        try:
> +            from tomli import load
> +            return load(fh)
> +        except ImportError as e:
> +            ex = e
> +
> +        # Try pip's vendored tomli
> +        try:
> +            from pip._vendor.tomli import load
> +            try:
> +                return load(fh)
> +            except TypeError:
> +                # Fallback to handle older version
> +                try:
> +                    fh.seek(0)
> +                    w = io.TextIOWrapper(fh, encoding="utf8", newline="")
> +                    return load(w)
> +                finally:
> +                    w.detach()
> +        except ImportError as e:
> +            pass
> +
> +        # Try regular toml last
> +        try:
> +            from toml import load
> +            fh.seek(0)
> +            w = io.TextIOWrapper(fh, encoding="utf8", newline="")
> +            try:
> +                return load(w)
> +            finally:
> +                w.detach()
> +        except ImportError:
> +            pass
> +
> +        print('This package needs tomli')
> +        raise ex

I'm confused by how "ex" gets used here. It's initially none, and it's
set to the ImportError exception if the tomli module couldn't be used.

>      def get_requirements(self, pkg_folder):
>          """
>          Retrieve dependencies from the metadata found in the setup.py script of
> @@ -694,9 +767,12 @@ def main():
>              except ImportError as err:
>                  if 'buildutils' in str(err):
>                      print('This package needs buildutils')
> +                    continue
>                  else:
> -                    raise
> -                continue
> +                    try:
> +                        package.load_pyproject()
> +                    except Exception as e:
> +                        raise

I really don't like the construction here. We're doing this:

	try:
		... do an attempt with traditional setup.py ...
	expect ImportError as err:
		...
		try:
			... do an attempt with pyproject.toml ...
		expect Exception as e:
			...

So, if get a third and then a fourth method of Python module packaging,
we will end up with:

	try:
		... do an attempt with traditional setup.py ...
	expect ImportError as err:
		...
		try:
			... do an attempt with pyproject.toml ...
		expect Exception as e:
			...
			try:
				... do an attempt with another method
			except:
				try:
					... do an attempt with another method
				except:

Clearly ugly. Can we have a better construct? I would know how to do
that in C, but I'm not very good at Python-ic constructs.
				
Thanks!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2022-08-03 21:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13 17:13 [Buildroot] [PATCH v2 1/2] utils/scanpypi: ensure tmp_extract is cleaned up on exception James Hilliard
2022-03-13 17:13 ` [Buildroot] [PATCH v2 2/2] utils/scanpypi: add flit package support James Hilliard
2022-08-03 21:46   ` Thomas Petazzoni via buildroot [this message]
2022-08-03 22:19     ` James Hilliard
2022-08-17  0:48   ` Marcus Hoffmann
2022-08-17  5:56     ` James Hilliard
2022-08-17 14:24       ` Marcus Hoffmann
2022-08-18  8:32         ` James Hilliard
2022-08-03 21:38 ` [Buildroot] [PATCH v2 1/2] utils/scanpypi: ensure tmp_extract is cleaned up on exception Thomas Petazzoni via buildroot
2022-08-03 22:02   ` James Hilliard
2022-08-04  7:59     ` Thomas Petazzoni via buildroot
2022-08-17  5:57       ` James Hilliard
2022-08-17  6:16         ` James Hilliard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220803234641.346d9c9c@windsurf \
    --to=buildroot@buildroot.org \
    --cc=james.hilliard1@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.