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

Add new --core-conf command line argument to allow passing core. confs via CLI #15441

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions conan/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def _init_log_levels(parser):
help="Level of detail of the output. Valid options from less verbose "
"to more verbose: -vquiet, -verror, -vwarning, -vnotice, -vstatus, "
"-v or -vverbose, -vv or -vdebug, -vvv or -vtrace")
parser.add_argument("-gc", "--global-conf", action="append",
help="Global configuration for Conan")

@property
def _help_formatters(self):
Expand Down Expand Up @@ -97,12 +99,18 @@ def _format(self, parser, info, *args):

class ConanArgumentParser(argparse.ArgumentParser):

def __init__(self, *args, **kwargs):
def __init__(self, conan_api, *args, **kwargs):
self._conan_api = conan_api
super().__init__(*args, **kwargs)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

def parse_args(self, args=None, namespace=None):
args = super().parse_args(args)
ConanOutput.define_log_level(os.getenv("CONAN_LOG_LEVEL", args.v))
if args.global_conf:
from conans.model.conf import ConfDefinition
confs = ConfDefinition()
confs.loads("\n".join(args.global_conf))
self._conan_api.config.global_conf.update_conf_definition(confs)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
return args


Expand All @@ -118,7 +126,8 @@ def add_subcommand(self, subcommand):
self._subcommands[subcommand.name] = subcommand

def run(self, conan_api, *args):
parser = ConanArgumentParser(description=self._doc, prog="conan {}".format(self._name),
parser = ConanArgumentParser(conan_api, description=self._doc,
prog="conan {}".format(self._name),
formatter_class=SmartFormatter)
self._init_log_levels(parser)
self._init_formatters(parser)
Expand All @@ -135,10 +144,10 @@ def run(self, conan_api, *args):
sub = self._subcommands[args[0][0]]
except (KeyError, IndexError): # display help
for sub in self._subcommands.values():
sub.set_parser(subcommand_parser)
sub.set_parser(subcommand_parser, conan_api)
parser.parse_args(*args)
else:
sub.set_parser(subcommand_parser)
sub.set_parser(subcommand_parser, conan_api)
sub.run(conan_api, parser, *args)

@property
Expand All @@ -160,8 +169,8 @@ def run(self, conan_api, parent_parser, *args):
def set_name(self, parent_name):
self._name = self._subcommand_name.replace(f'{parent_name}-', '', 1)

def set_parser(self, subcommand_parser):
self._parser = subcommand_parser.add_parser(self._name, help=self._doc)
def set_parser(self, subcommand_parser, conan_api):
self._parser = subcommand_parser.add_parser(self._name, conan_api=conan_api, help=self._doc)
self._parser.description = self._doc
self._init_formatters(self._parser)
self._init_log_levels(self._parser)
Expand Down
20 changes: 20 additions & 0 deletions conans/test/integration/configuration/conf/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from conan import conan_version
from conan.internal.api import detect_api
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.test_files import temp_folder
from conans.util.files import save, load
from conans.test.utils.tools import TestClient

Expand Down Expand Up @@ -307,6 +308,25 @@ def test_global_conf_auto_created():
assert "# core:non_interactive = True" in global_conf


def test_command_line_core_conf():
c = TestClient()
c.run("config show * -gc core:default_profile=potato")
assert "core:default_profile: potato" in c.out
c.run("config show * -gc core:default_profile=potato -gc core:default_build_profile=orange")
assert "core:default_profile: potato" in c.out
assert "core:default_build_profile: orange" in c.out

c.save({"conanfile.py": GenConanfile("pkg", "0.1")})
c.run("export .")

tfolder = temp_folder()
c.run(f'list * -gc core.cache:storage_path="{tfolder}"')
assert "WARN: There are no matching recipe references" in c.out
c.run(f'list *')
assert "WARN: There are no matching recipe references" not in c.out
assert "pkg/0.1" in c.out


def test_build_test_consumer_only():
c = TestClient()
dep = textwrap.dedent("""
Expand Down