Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop2] Improve a bit the output msgs #12746

Merged
merged 16 commits into from
Feb 20, 2023
8 changes: 7 additions & 1 deletion conan/api/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def json_encoder(_obj):
else:
ret = "{}: ".format(self._scope)

if self._color and not self._scope:
if self._color:
ret += "{}{}{}{}".format(fg or '', bg or '', msg, Style.RESET_ALL)
else:
ret += "{}".format(msg)
Expand Down Expand Up @@ -170,6 +170,12 @@ def status(self, msg, fg=None, bg=None):
info = status

def title(self, msg):
if log_level_allowed(LEVEL_NOTICE):
self._write_message("\n======== {} ========".format(msg), "NOTICE",
fg=Color.BRIGHT_MAGENTA)
return self

def subtitle(self, msg):
if log_level_allowed(LEVEL_NOTICE):
self._write_message("\n-------- {} --------".format(msg), "NOTICE",
fg=Color.BRIGHT_MAGENTA)
Expand Down
1 change: 1 addition & 0 deletions conan/api/subapi/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, conan_api):
self.conan_api = conan_api

def export(self, path, name, version, user, channel, lockfile=None, remotes=None):
ConanOutput().title("Exporting recipe to the cache")
app = ConanApp(self.conan_api.cache_folder)
return cmd_export(app, path, name, version, user, channel, graph_lock=lockfile,
remotes=remotes)
Expand Down
34 changes: 3 additions & 31 deletions conan/api/subapi/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from conan.api.output import ConanOutput
from conan.internal.conan_app import ConanApp
from conan.cli.printers.graph import print_graph_basic
from conans.client.graph.graph import Node, RECIPE_CONSUMER, CONTEXT_HOST, RECIPE_VIRTUAL
from conans.client.graph.graph_binaries import GraphBinariesAnalyzer
from conans.client.graph.graph_builder import DepsGraphBuilder
Expand Down Expand Up @@ -110,65 +109,37 @@ def _scope_options(profile, requires, tool_requires):
profile.options.scope(tool_requires[0])

def load_graph_requires(self, requires, tool_requires, profile_host, profile_build,
lockfile, remotes, update, check_updates=False, allow_error=False):
lockfile, remotes, update, check_updates=False):
requires = [RecipeReference.loads(r) if isinstance(r, str) else r for r in requires] \
if requires else None
tool_requires = [RecipeReference.loads(r) if isinstance(r, str) else r
for r in tool_requires] if tool_requires else None

out = ConanOutput()
out.title("Input profiles")
out.info("Profile host:")
out.info(profile_host.dumps())
out.info("Profile build:")
out.info(profile_build.dumps())

self._scope_options(profile_host, requires=requires, tool_requires=tool_requires)
root_node = self._load_root_virtual_conanfile(requires=requires, tool_requires=tool_requires,
profile_host=profile_host)

out.title("Computing dependency graph")
# check_updates = args.check_updates if "check_updates" in args else False
deps_graph = self.load_graph(root_node, profile_host=profile_host,
profile_build=profile_build,
lockfile=lockfile,
remotes=remotes,
update=update,
check_update=check_updates)
print_graph_basic(deps_graph)
if deps_graph.error:
if allow_error:
return deps_graph
raise deps_graph.error

return deps_graph

def load_graph_consumer(self, path, name, version, user, channel,
profile_host, profile_build, lockfile, remotes, update,
allow_error=False, check_updates=False, is_build_require=False):
out = ConanOutput()
out.title("Input profiles")
out.info("Profile host:")
out.info(profile_host.dumps())
out.info("Profile build:")
out.info(profile_build.dumps())

check_updates=False, is_build_require=False):
root_node = self._load_root_consumer_conanfile(path, profile_host, profile_build,
name=name, version=version, user=user,
channel=channel, lockfile=lockfile,
remotes=remotes, update=update,
is_build_require=is_build_require)

out.title("Computing dependency graph")
deps_graph = self.load_graph(root_node, profile_host=profile_host,
profile_build=profile_build, lockfile=lockfile,
remotes=remotes, update=update, check_update=check_updates)
print_graph_basic(deps_graph)
if deps_graph.error:
if allow_error:
return deps_graph
raise deps_graph.error

return deps_graph

def load_graph(self, root_node, profile_host, profile_build, lockfile=None, remotes=None,
Expand All @@ -189,6 +160,7 @@ def load_graph(self, root_node, profile_host, profile_build, lockfile=None, remo
revisions for already existing recipes in the Conan cache
:param check_update: For "graph info" command, check if there are recipe updates
"""
ConanOutput().title("Computing dependency graph")
app = ConanApp(self.conan_api.cache_folder)

assert profile_host is not None
Expand Down
5 changes: 3 additions & 2 deletions conan/cli/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conan.cli.commands import make_abs_path
from conan.cli.args import add_lockfile_args, add_common_install_arguments, add_reference_args
from conan.internal.conan_app import ConanApp
from conan.cli.printers.graph import print_graph_packages
from conan.cli.printers.graph import print_graph_packages, print_graph_basic
from conans.client.conanfile.build import run_build_method


Expand Down Expand Up @@ -41,7 +41,8 @@ def build(conan_api, parser, *args):
args.user, args.channel,
profile_host, profile_build, lockfile, remotes,
args.update)

print_graph_basic(deps_graph)
deps_graph.report_graph_error()
conan_api.graph.analyze_binaries(deps_graph, args.build, remotes=remotes, update=args.update,
lockfile=lockfile)
print_graph_packages(deps_graph)
Expand Down
17 changes: 5 additions & 12 deletions conan/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from conan.cli.command import conan_command, OnceArgument
from conan.cli.commands.export import common_args_export
from conan.cli.args import add_lockfile_args, add_common_install_arguments
from conan.cli.printers import print_profiles
from conan.internal.conan_app import ConanApp
from conan.cli.printers.graph import print_graph_packages
from conan.cli.printers.graph import print_graph_packages, print_graph_basic
from conans.client.conanfile.build import run_build_method
from conans.errors import ConanException, conanfile_exception_formatter
from conans.util.files import chdir, mkdir
Expand Down Expand Up @@ -45,8 +46,6 @@ def create(conan_api, parser, *args):
remotes = conan_api.remotes.list(args.remote) if not args.no_remote else []
profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args)

out = ConanOutput()
out.highlight("Exporting the recipe")
ref, conanfile = conan_api.export.export(path=path,
name=args.name, version=args.version,
user=args.user, channel=args.channel,
Expand All @@ -57,34 +56,28 @@ def create(conan_api, parser, *args):
lockfile = conan_api.lockfile.update_lockfile_export(lockfile, conanfile, ref,
args.build_require)

out.title("Input profiles")
out.info("Profile host:")
out.info(profile_host.dumps())
out.info("Profile build:")
out.info(profile_build.dumps())
print_profiles(profile_host, profile_build)

deps_graph = None
if not is_python_require:
# TODO: This section might be overlapping with ``graph_compute()``
requires = [ref] if not args.build_require else None
tool_requires = [ref] if args.build_require else None

out.title("Computing dependency graph")
deps_graph = conan_api.graph.load_graph_requires(requires, tool_requires,
profile_host=profile_host,
profile_build=profile_build,
lockfile=lockfile,
remotes=remotes, update=args.update)
print_graph_basic(deps_graph)
deps_graph.report_graph_error()

out.title("Computing necessary packages")
# Not specified, force build the tested library
build_modes = [ref.repr_notime()] if args.build is None else args.build
conan_api.graph.analyze_binaries(deps_graph, build_modes, remotes=remotes,
update=args.update, lockfile=lockfile)
print_graph_packages(deps_graph)

out.title("Installing packages")
conan_api.install.install_binaries(deps_graph=deps_graph, remotes=remotes)
# We update the lockfile, so it will be updated for later ``test_package``
lockfile = conan_api.lockfile.update_lockfile(lockfile, deps_graph, args.lockfile_packages,
Expand Down Expand Up @@ -146,7 +139,7 @@ def test_package(conan_api, deps_graph, test_conanfile_path, tested_python_requi
conanfile.folders.set_base_package(conanfile.folders.base_build)
run_build_method(conanfile, app.hook_manager)

out.title("Testing the package: Running test()")
out.title("Testing the package: Executing test")
conanfile.output.highlight("Running test()")
with conanfile_exception_formatter(conanfile, "test"):
with chdir(conanfile.build_folder):
Expand Down
3 changes: 1 addition & 2 deletions conan/cli/commands/export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os

from conan.api.output import ConanOutput, cli_out_write
from conan.api.output import cli_out_write
from conan.cli.command import conan_command, OnceArgument
from conan.cli.args import add_reference_args

Expand Down Expand Up @@ -51,5 +51,4 @@ def export(conan_api, parser, *args):
lockfile = conan_api.lockfile.update_lockfile_export(lockfile, conanfile, ref,
args.build_require)
conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out, cwd)
ConanOutput().success("Exported recipe: {}".format(ref.repr_humantime()))
return ref
2 changes: 2 additions & 0 deletions conan/cli/commands/export_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from conan.cli.args import add_lockfile_args, add_profiles_args, add_reference_args
from conan.cli.commands import make_abs_path
from conan.cli.commands.create import _get_test_conanfile_path
from conan.cli.printers.graph import print_graph_basic


def json_export_pkg(info):
Expand Down Expand Up @@ -54,6 +55,7 @@ def export_pkg(conan_api, parser, *args):
lockfile=lockfile, remotes=None, update=None,
is_build_require=args.build_require)

print_graph_basic(deps_graph)
deps_graph.report_graph_error()
conan_api.graph.analyze_binaries(deps_graph, build_mode=[ref.name], lockfile=lockfile)
deps_graph.report_graph_error()
Expand Down
12 changes: 7 additions & 5 deletions conan/cli/commands/graph.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os

from conan.api.output import ConanOutput, cli_out_write
from conan.cli.printers.graph import print_graph_packages
from conan.api.output import ConanOutput, cli_out_write, Color
from conan.cli.printers.graph import print_graph_packages, print_graph_basic
from conan.internal.deploy import do_deploys
from conan.cli.command import conan_command, conan_subcommand
from conan.cli.commands import make_abs_path
Expand Down Expand Up @@ -144,15 +144,17 @@ def graph_info(conan_api, parser, subparser, *args):
args.user, args.channel,
profile_host, profile_build, lockfile,
remotes, args.update,
allow_error=True,
check_updates=args.check_updates)
else:
deps_graph = conan_api.graph.load_graph_requires(args.requires, args.tool_requires,
profile_host, profile_build, lockfile,
remotes, args.update,
allow_error=True,
check_updates=args.check_updates)
if not deps_graph.error:
print_graph_basic(deps_graph)
if deps_graph.error:
ConanOutput().info("Graph error", Color.BRIGHT_RED)
ConanOutput().info(" {}".format(deps_graph.error), Color.BRIGHT_RED)
else:
conan_api.graph.analyze_binaries(deps_graph, args.build, remotes=remotes, update=args.update,
lockfile=lockfile)
print_graph_packages(deps_graph)
Expand Down
8 changes: 6 additions & 2 deletions conan/cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from conan.cli.args import common_graph_args
from conan.cli.command import conan_command
from conan.cli.commands import make_abs_path
from conan.cli.printers.graph import print_graph_packages
from conan.cli.printers import print_profiles
from conan.cli.printers.graph import print_graph_packages, print_graph_basic
from conans.errors import ConanException


Expand Down Expand Up @@ -67,6 +68,7 @@ def install(conan_api, parser, *args):
cwd=cwd,
partial=args.lockfile_partial)
profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args)
print_profiles(profile_host, profile_build)
if path:
deps_graph = conan_api.graph.load_graph_consumer(path, args.name, args.version,
args.user, args.channel,
Expand All @@ -76,12 +78,13 @@ def install(conan_api, parser, *args):
deps_graph = conan_api.graph.load_graph_requires(args.requires, args.tool_requires,
profile_host, profile_build, lockfile,
remotes, args.update)
print_graph_basic(deps_graph)
deps_graph.report_graph_error()
conan_api.graph.analyze_binaries(deps_graph, args.build, remotes=remotes, update=args.update,
lockfile=lockfile)
print_graph_packages(deps_graph)

out = ConanOutput()
out.title("Installing packages")
conan_api.install.install_binaries(deps_graph=deps_graph, remotes=remotes)

out.title("Finalizing install (deploy, generators)")
Expand All @@ -92,6 +95,7 @@ def install(conan_api, parser, *args):
deploy=args.deploy
)

out.success("Install finished succesfully")
lockfile = conan_api.lockfile.update_lockfile(lockfile, deps_graph, args.lockfile_packages,
clean=args.lockfile_clean)
conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out, cwd)
Expand Down
4 changes: 3 additions & 1 deletion conan/cli/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from conan.cli.command import conan_command, OnceArgument, conan_subcommand
from conan.cli.commands import make_abs_path
from conan.cli.args import common_graph_args
from conan.cli.printers.graph import print_graph_packages
from conan.cli.printers.graph import print_graph_packages, print_graph_basic
from conans.errors import ConanException
from conans.model.graph_lock import Lockfile, LOCKFILE
from conans.model.recipe_ref import RecipeReference
Expand Down Expand Up @@ -47,6 +47,8 @@ def lock_create(conan_api, parser, subparser, *args):
profile_host, profile_build, lockfile,
remotes, args.build, args.update)

print_graph_basic(graph)
graph.report_graph_error()
conan_api.graph.analyze_binaries(graph, args.build, remotes=remotes, update=args.update,
lockfile=lockfile)
print_graph_packages(graph)
Expand Down
13 changes: 4 additions & 9 deletions conan/cli/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from conan.cli.command import conan_command, OnceArgument
from conan.cli.commands.create import test_package, _check_tested_reference_matches
from conan.cli.args import add_lockfile_args, add_common_install_arguments
from conan.cli.printers import print_profiles
from conan.cli.printers.graph import print_graph_basic, print_graph_packages
from conans.model.recipe_ref import RecipeReference

Expand Down Expand Up @@ -31,12 +32,7 @@ def test(conan_api, parser, *args):
remotes = conan_api.remotes.list(args.remote) if not args.no_remote else []
profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args)

out = ConanOutput()
out.title("Input profiles")
out.info("Profile host:")
out.info(profile_host.dumps())
out.info("Profile build:")
out.info(profile_build.dumps())
print_profiles(profile_host, profile_build)

deps_graph = run_test(conan_api, path, ref, profile_host, profile_build, remotes, lockfile,
args.update, build_modes=args.build)
Expand All @@ -55,21 +51,20 @@ def run_test(conan_api, path, ref, profile_host, profile_build, remotes, lockfil
tested_python_requires=tested_python_requires)

out = ConanOutput()
out.title("test_package: Computing dependency graph")
out.title("Launching test_package")
deps_graph = conan_api.graph.load_graph(root_node, profile_host=profile_host,
profile_build=profile_build,
lockfile=lockfile,
remotes=remotes,
update=update,
check_update=update)
print_graph_basic(deps_graph)
out.title("test_package: Computing necessary packages")
deps_graph.report_graph_error()

conan_api.graph.analyze_binaries(deps_graph, build_modes, remotes=remotes, update=update,
lockfile=lockfile)
print_graph_packages(deps_graph)

out.title("test_package: Installing packages")
conan_api.install.install_binaries(deps_graph=deps_graph, remotes=remotes)
_check_tested_reference_matches(deps_graph, ref, out)
test_package(conan_api, deps_graph, path, tested_python_requires)
Expand Down
10 changes: 10 additions & 0 deletions conan/cli/printers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from conan.api.output import ConanOutput, Color


def print_profiles(profile_host, profile_build):
out = ConanOutput()
out.title("Input profiles")
out.info("Profile host:", fg=Color.BRIGHT_CYAN)
out.info(profile_host.dumps())
out.info("Profile build:", fg=Color.BRIGHT_CYAN)
out.info(profile_build.dumps())
Loading