From patchwork Mon Dec 19 17:01:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 1717486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=bV8HyeLO; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NbQxN2ChXz1ydb for ; Tue, 20 Dec 2022 04:02:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 15B14853D1; Mon, 19 Dec 2022 18:02:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bV8HyeLO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DD87F85310; Mon, 19 Dec 2022 18:02:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 897AC8505B for ; Mon, 19 Dec 2022 18:02:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.cournoyer@gmail.com Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1322d768ba7so12261344fac.5 for ; Mon, 19 Dec 2022 09:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CcO2uNzGgz5fjatbquxpWBQX7f6qdxFQfEZZpzpmBsk=; b=bV8HyeLO5w6s872DuDGwXm3FkLwSW/VgIKDwNcwiTuJSFiBv6EAbCthros0flmypo/ 0RDwzt7SczOcq8woRifSAWjjkjsYr47fZh15aHLy3vlSqJJuDjUFuOqtZQu0YMEEZBPO G/LFfnqY+zIhGdTRnqz3HiqSHo60X2zrwiwA8AXIoX2jP36KuUds7brOk9pIVPiScLfd q5ZACpzvNcIJ5zB4xZqzNkUr6NTs4txwdK4SBV4zw5R8brOTh378LbVRWzGluTj5f/ag WoOKPJIVri599QYGcVUn/hgJR9bw3JH31PGU/nrxcTFDx/AKSrHlXXhXPW4XFkqFl4vp HaQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CcO2uNzGgz5fjatbquxpWBQX7f6qdxFQfEZZpzpmBsk=; b=zFWszoIcTr6kjsNHKq0f0XqpNa4fCbHhq/3qCRNO+8fuYLZD2G7Qj656UmE0S5QLAV X+wu0mAvWK/H5DR3eErdh0X7hSQlQIps/B6DDiXD/Rzp8AdyTSJvgN49OY7Q7zsJJYov OZiIN2gVfbW3Ii/0F+Kfv4irrLpSmFLDlNWGC/3thNZiyYzE6q1Gz6BCCpqE4b+xhALh czVQR7HaPgA2dbLInXp5C2J/TVV5C0JwOJGaimcMRx1pVgO9NXKUENg4VlN/IvRJzllE 9SbjtxB89PMmzNGMbgyqVRRI0L6kVhlfcjVAlkqLnopwcwnJr2tl/LKD/DwzChEE7Uda DmIQ== X-Gm-Message-State: ANoB5pl/Z5omsqUTe9Xo8ivEZQveY5h1c83MY/4VxadRzlNrPBsT/P+1 K2lwt2aMMTlakdGeqM8yGyZqZl0A7miOHg== X-Google-Smtp-Source: AA0mqf5ivPVYhWWGEcriJDqoP6H8tvWs4fSBj6fYG2nwsp6G93OrIeSHZfj7MrRtiQQPHtV+wKzcyA== X-Received: by 2002:a05:6870:3c1a:b0:144:ca79:4d27 with SMTP id gk26-20020a0568703c1a00b00144ca794d27mr20223379oab.7.1671469335059; Mon, 19 Dec 2022 09:02:15 -0800 (PST) Received: from localhost.localdomain (dsl-10-133-202.b2b2c.ca. [72.10.133.202]) by smtp.gmail.com with ESMTPSA id c11-20020ac853cb000000b003a6a92a202esm6213508qtq.83.2022.12.19.09.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 09:02:14 -0800 (PST) From: Maxim Cournoyer X-Google-Original-From: Maxim Cournoyer To: U-Boot Mailing List Cc: Maxim Cournoyer , Simon Glass Subject: [PATCH v2 1/1] patman: additionally honor a local .patman config file Date: Mon, 19 Dec 2022 12:01:52 -0500 Message-Id: <20221219170152.26124-2-maxim.cournoyer@savoirfairelinux.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219170152.26124-1-maxim.cournoyer@savoirfairelinux.com> References: <20221219170152.26124-1-maxim.cournoyer@savoirfairelinux.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean This enables versioning a project specific patman configuration file. It also makes it possible to declare the project name, which is not a useful thing to do in $HOME/.patman. A new test is added, along updated documentation. Signed-off-by: Maxim Cournoyer --- Changes in v2: - Explicitly provide an empty args list to parse_known_args in test tools/patman/patman.rst | 8 ++++++- tools/patman/settings.py | 24 +++++++++++++++---- tools/patman/test_settings.py | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 tools/patman/test_settings.py diff --git a/tools/patman/patman.rst b/tools/patman/patman.rst index b06399b459..3e12251f03 100644 --- a/tools/patman/patman.rst +++ b/tools/patman/patman.rst @@ -74,7 +74,7 @@ out where to send patches pretty well. During the first run patman creates a config file for you by taking the default user name and email address from the global .gitconfig file. -To add your own, create a file ~/.patman like this:: +To add your own, create a file `~/.patman` like this:: # patman alias file @@ -85,6 +85,12 @@ To add your own, create a file ~/.patman like this:: wolfgang: Wolfgang Denk others: Mike Frysinger , Fred Bloggs +Patman will also look for a `.patman` configuration file at the root +of the current project git repository, which makes it possible to +override the `project` settings variable or anything else in a +project-specific way. The values of this "local" configuration file +take precedence over those of the "global" one. + Aliases are recursive. The checkpatch.pl in the U-Boot tools/ subdirectory will be located and diff --git a/tools/patman/settings.py b/tools/patman/settings.py index c05efd2475..636983e32d 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2011 The Chromium OS Authors. +# Copyright (c) 2022 Maxim Cournoyer # try: @@ -336,6 +337,12 @@ def GetItems(config, section): def Setup(parser, project_name, config_fname=None): """Set up the settings module by reading config files. + Unless `config_fname` is specified, a `.patman` config file local + to the git repository is consulted, followed by the global + `$HOME/.patman`. If none exists, the later is created. Values + defined in the local config file take precedence over those + defined in the global one. + Args: parser: The parser to update. project_name: Name of project that we're working on; we'll look @@ -352,12 +359,21 @@ def Setup(parser, project_name, config_fname=None): if not config_fname: config_fname = '%s/.patman' % os.getenv('HOME') + has_config = os.path.exists(config_fname) - if not os.path.exists(config_fname): - print("No config file found ~/.patman\nCreating one...\n") - CreatePatmanConfigFile(config_fname) + git_local_config_fname = os.path.join(gitutil.get_top_level(), '.patman') + has_git_local_config = os.path.exists(git_local_config_fname) - config.read(config_fname) + # Read the git local config last, so that its values override + # those of the global config, if any. + if has_config: + config.read(config_fname) + if has_git_local_config: + config.read(git_local_config_fname) + + if not (has_config or has_git_local_config): + print("No config file found.\nCreating ~/.patman...\n") + CreatePatmanConfigFile(config_fname) for name, value in GetItems(config, 'alias'): alias[name] = value.split(',') diff --git a/tools/patman/test_settings.py b/tools/patman/test_settings.py new file mode 100644 index 0000000000..b2f825f798 --- /dev/null +++ b/tools/patman/test_settings.py @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2022 Maxim Cournoyer +# + +import argparse +import contextlib +import os +import subprocess +import tempfile + +from patman import settings + + +@contextlib.contextmanager +def empty_git_repository(): + with tempfile.TemporaryDirectory() as tmpdir: + os.chdir(tmpdir) + subprocess.check_call(['git', 'init']) + yield tmpdir + + +def test_git_local_config(): + with empty_git_repository(): + with tempfile.NamedTemporaryFile() as global_config: + global_config.write(b'[settings]\n' + b'project=u-boot\n') + global_config.flush() + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--project', default='unknown') + + # Test "global" config is used. + settings.Setup(parser, 'unknown', global_config.name) + args, _ = parser.parse_known_args([]) + assert args.project == 'u-boot' + + # Test local config can shadow it. + with open('.patman', 'w', buffering=1) as f: + f.write('[settings]\n' + 'project=guix-patches\n') + settings.Setup(parser, 'unknown', global_config.name) + args, _ = parser.parse_known_args([]) + assert args.project == 'guix-patches'