commit: d77990efa1b8a2151471e8e112b36b048b25ea54
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 19 13:55:47 2022 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Nov 19 13:55:47 2022 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=d77990ef
scan: add support for NOCOLOR to disable colors
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgcheck/scripts/pkgcheck_scan.py | 3 +++
tests/scripts/test_pkgcheck_scan.py | 15 +++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/src/pkgcheck/scripts/pkgcheck_scan.py
b/src/pkgcheck/scripts/pkgcheck_scan.py
index c6300b5b..e5227bbf 100644
--- a/src/pkgcheck/scripts/pkgcheck_scan.py
+++ b/src/pkgcheck/scripts/pkgcheck_scan.py
@@ -342,6 +342,9 @@ def _setup_scan(parser, namespace, args):
# load repo-specific args from config if they exist
namespace = config_parser.parse_config_sections(namespace,
namespace.target_repo.aliases)
+ if os.getenv('NOCOLOR'):
+ namespace.color = False
+
return namespace, args
diff --git a/tests/scripts/test_pkgcheck_scan.py
b/tests/scripts/test_pkgcheck_scan.py
index 8b8113e7..6c1600f8 100644
--- a/tests/scripts/test_pkgcheck_scan.py
+++ b/tests/scripts/test_pkgcheck_scan.py
@@ -264,6 +264,21 @@ class TestPkgcheckScanParseArgs:
assert options.jobs == expected_jobs
assert options.tasks == 5 * expected_jobs
+ def test_no_color(self, parser, tmp_path):
+ (config_file := tmp_path / 'config').write_text(textwrap.dedent('''\
+ [DEFAULT]
+ color = true
+ '''))
+
+ args = ('scan', '--config', str(config_file))
+ assert parser.parse_args(args).color is True
+ with os_environ(NOCOLOR='1'):
+ # NOCOLOR overrides config file
+ assert parser.parse_args(args).color is False
+ # cmd line option overrides NOCOLOR
+ assert parser.parse_args([*args, '--color', 'n']).color is False
+ assert parser.parse_args([*args, '--color', 'y']).color is True
+
class TestPkgcheckScanParseConfigArgs: