From 245bd13f9f6022df1dde356a43abf8a513bb9573 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 21 Apr 2023 11:23:05 +0200 Subject: [PATCH] auto create default global.conf --- conans/client/cache/cache.py | 11 ++++++++++- .../test/integration/configuration/conf/test_conf.py | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/conans/client/cache/cache.py b/conans/client/cache/cache.py index 30c7887217e..9fbf9baec84 100644 --- a/conans/client/cache/cache.py +++ b/conans/client/cache/cache.py @@ -1,5 +1,6 @@ import os import platform +import textwrap from typing import List import yaml @@ -167,8 +168,16 @@ def new_config(self): content = template.render({"platform": platform, "os": os, "distro": distro, "conan_version": conan_version, "conan_home_folder": self.cache_folder}) - self._new_config.loads(content) + else: # creation of a blank global.conf file for user convenience + default_global_conf = textwrap.dedent("""\ + # Core configuration (type 'conan config list' to list possible values) + # e.g, for CI systems, to raise if user input would block + # core:non_interactive = True + # some tools.xxx config also possible, though generally better in profiles + # tools.android:ndk_path = my/path/to/android/ndk + """) + save(self.new_config_path, default_global_conf) return self._new_config @property diff --git a/conans/test/integration/configuration/conf/test_conf.py b/conans/test/integration/configuration/conf/test_conf.py index 4471ce0c1d1..ff362e4e730 100644 --- a/conans/test/integration/configuration/conf/test_conf.py +++ b/conans/test/integration/configuration/conf/test_conf.py @@ -7,7 +7,7 @@ from conan import conan_version from conans.errors import ConanException -from conans.util.files import save +from conans.util.files import save, load from conans.test.utils.tools import TestClient @@ -270,3 +270,10 @@ def test_nonexisting_conf_global_conf(): c.save({"conanfile.txt": ""}) c.run("install . ", assert_error=True) assert "ERROR: Unknown conf 'tools.unknown:conf'" in c.out + + +def test_global_conf_auto_created(): + c = TestClient() + c.run("config list") # all commands will trigger + global_conf = load(c.cache.new_config_path) + assert "# core:non_interactive = True" in global_conf