From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, alex.bennee@linaro.org
Subject: Re: [RFC PATCH 2/4] lcitool: use libvirt-ci as library
Date: Wed, 8 Feb 2023 17:27:01 +0000 [thread overview]
Message-ID: <Y+PbZWwG+n20ODcg@redhat.com> (raw)
In-Reply-To: <20230117091638.50523-3-pbonzini@redhat.com>
On Tue, Jan 17, 2023 at 10:16:36AM +0100, Paolo Bonzini wrote:
> Using the lcitool package as a library will make it possible to
> customize more of the process, for example by introducing custom
> mappings.
I wouldn't consider the lcitool python code to be a public
library API, which is for example, why its not a published
pakage on pypi. So from that POV I'm really not a fan of
this change to use the internal APIs directly, as it means
that any contributors who want to update the submodule are
liable to get hit by incompatible API changes.
> diff --git a/tests/lcitool/refresh b/tests/lcitool/refresh
> index ee55ee40ee5d..31a34dce7a33 100755
> --- a/tests/lcitool/refresh
> +++ b/tests/lcitool/refresh
> @@ -12,61 +12,80 @@
> # or (at your option) any later version. See the COPYING file in
> # the top-level directory.
>
> -import sys
> -import subprocess
> -
> +from contextlib import contextmanager
> from pathlib import Path
>
> +import sys
> +
> if len(sys.argv) != 1:
> print("syntax: %s" % sys.argv[0], file=sys.stderr)
> sys.exit(1)
>
> -self_dir = Path(__file__).parent
> -src_dir = self_dir.parent.parent
> +script = Path(__file__)
> +script_dir = script.parent
> +src_dir = script_dir.parent.parent
> dockerfiles_dir = Path(src_dir, "tests", "docker", "dockerfiles")
>
> -lcitool_path = Path(self_dir, "libvirt-ci", "bin", "lcitool")
> +sys.path.append(str(Path(script_dir, "libvirt-ci")))
>
> -lcitool_cmd = [lcitool_path, "--data-dir", self_dir]
> +from lcitool import LcitoolError
> +from lcitool.packages import Packages
> +from lcitool.projects import Projects
> +from lcitool.targets import BuildTarget, Targets
> +from lcitool.formatters import DockerfileFormatter, ShellVariablesFormatter
> +from lcitool.util import DataDir
> +
> +PREFIX = ''
> +
> +DATA_DIR = DataDir(script_dir)
> +PROJECTS = Projects(DATA_DIR)
> +PACKAGES = Packages()
> +TARGETS = Targets()
>
>
> -def atomic_write(filename, content):
> +@contextmanager
> +def atomic_write(filename):
> tmp = filename.with_suffix(filename.suffix + ".tmp")
> try:
> with tmp.open("w") as fp:
> - print(content, file=fp, end="")
> + yield fp
> tmp.rename(filename)
> - except Exception as ex:
> + except Exception:
> tmp.unlink()
> raise
>
>
> -def generate(filename, cmd, trailer):
> - print("Generate %s" % filename)
> - lcitool = subprocess.run(cmd, capture_output=True)
> -
> - if lcitool.returncode != 0:
> - raise Exception("Failed to generate %s: %s" % (filename, lcitool.stderr))
> -
> - content = lcitool.stdout.decode("utf8")
> - if trailer is not None:
> - content += trailer
> - atomic_write(filename, content)
> +@contextmanager
> +def generate(filename):
> + print("Generating %s" % filename)
> + nonlocal PREFIX
> + try:
> + PREFIX = "Failed to generate %s: " % filename
> + with atomic_write(filename) as fp:
> + print('# THIS FILE WAS AUTO-GENERATED BY',
> + script.relative_to(src_dir), file=fp)
> + print(file=fp)
> + yield fp
> + finally:
> + PREFIX = ''
>
>
> def generate_dockerfile(host, target, cross=None, trailer=None):
> filename = Path(src_dir, "tests", "docker", "dockerfiles", host + ".docker")
> - cmd = lcitool_cmd + ["dockerfile"]
> - if cross is not None:
> - cmd.extend(["--cross", cross])
> - cmd.extend([target, "qemu"])
> - generate(filename, cmd, trailer)
> + with generate(filename) as fp:
> + dockerfile = DockerfileFormatter(PROJECTS)
> + target = BuildTarget(TARGETS, PACKAGES, target, cross)
> + print(dockerfile.format(target, ["qemu"]), file=fp)
> + if trailer is not None:
> + print(trailer, file=fp, end="")
>
>
> -def generate_cirrus(target, trailer=None):
> +def generate_cirrus(target):
> filename = Path(src_dir, ".gitlab-ci.d", "cirrus", target + ".vars")
> - cmd = lcitool_cmd + ["variables", target, "qemu"]
> - generate(filename, cmd, trailer)
> + with generate(filename) as fp:
> + variables = ShellVariablesFormatter(PROJECTS)
> + target = BuildTarget(TARGETS, PACKAGES, target)
> + print(variables.format(target, ["qemu"]), file=fp)
>
>
> ubuntu2004_tsanhack = [
> @@ -98,11 +117,11 @@ def cross_build(prefix, targets):
> targets = "ENV DEF_TARGET_LIST %s\n" % (targets)
> return "".join([conf, targets])
>
> +
> #
> # Update all the various build configurations.
> # Please keep each group sorted alphabetically for easy reading.
> #
> -
> try:
> #
> # Standard native builds
> @@ -179,6 +198,6 @@ try:
> generate_cirrus("macos-12")
>
> sys.exit(0)
> -except Exception as ex:
> - print(str(ex), file=sys.stderr)
> +except LcitoolError as ex:
> + print(PREFIX + ex.module_prefix + " error: " + str(ex), file=sys.stderr)
> sys.exit(1)
> --
> 2.38.1
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2023-02-08 17:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 9:16 [RFC PATCH 0/4] Update CentOS and OpenSUSE CI to Python >=3.7 Paolo Bonzini
2023-01-17 9:16 ` [RFC PATCH 1/4] lcitool: update submodule Paolo Bonzini
2023-01-17 9:16 ` [RFC PATCH 2/4] lcitool: use libvirt-ci as library Paolo Bonzini
2023-02-08 17:27 ` Daniel P. Berrangé [this message]
2023-01-17 9:16 ` [RFC PATCH 3/4] lcitool: allow overriding package mappings and target facts Paolo Bonzini
2023-02-08 17:31 ` Daniel P. Berrangé
2023-01-17 9:16 ` [RFC PATCH 4/4] ci, docker: update CentOS and OpenSUSE Python to non-EOL versions Paolo Bonzini
2023-02-08 17:45 ` Daniel P. Berrangé
2023-02-08 17:22 ` [RFC PATCH 0/4] Update CentOS and OpenSUSE CI to Python >=3.7 Paolo Bonzini
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=Y+PbZWwG+n20ODcg@redhat.com \
--to=berrange@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).