All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Simon Glass <sjg@chromium.org>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
Subject: Re: [PATCH 6/6] patman: additionally honor a local .patman config file
Date: Mon, 19 Dec 2022 22:29:37 -0500	[thread overview]
Message-ID: <87sfha4use.fsf@gmail.com> (raw)
In-Reply-To: <CAPnjgZ3+nt2b7pZU8ftboH7c8HGpqVwd_BZE=SR4GBDYECS0cg@mail.gmail.com> (Simon Glass's message of "Mon, 19 Dec 2022 12:20:59 -0700")

Hi Simon,

Simon Glass <sjg@chromium.org> writes:

> Hi Maxim,
>
> On Mon, 19 Dec 2022 at 08:50, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:
>>
>> This enables versioning a project specific patman configuration file.
>> It also makes it possible to declare the the project name is,
>> which is not a useful thing to do in $HOME/.patman.  A new test is
>> added, along updated documentation.
>>
>> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
>> ---
>>
>>  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/test_settings.py b/tools/patman/test_settings.py
>> new file mode 100644
>> index 0000000000..9c14b4aaa3
>> --- /dev/null
>> +++ b/tools/patman/test_settings.py
>> @@ -0,0 +1,43 @@
>> +# SPDX-License-Identifier: GPL-2.0+
>> +#
>> +# Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
>> +#
>> +
>> +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'])
>
> We normally use tools.run()

Adjusted like so:

--8<---------------cut here---------------start------------->8---
modified   tools/patman/test_settings.py
@@ -6,18 +6,18 @@
 import argparse
 import contextlib
 import os
-import subprocess
 import sys
 import tempfile
 
 from patman import settings
+from patman import tools
 
 
 @contextlib.contextmanager
 def empty_git_repository():
     with tempfile.TemporaryDirectory() as tmpdir:
         os.chdir(tmpdir)
-        subprocess.check_call(['git', 'init'])
+        tools.run('git', 'init', raise_on_error=True)
         yield tmpdir
--8<---------------cut here---------------end--------------->8---

>> +        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:
>
> Can this be created in the temporary dir? At present it looks like it
> might overwrite a file in the current dir?

The 'empty_git_repository' context manager chdir to a temporary
directory upon entry, so anything that runs in its block such as the
open call above will be executed in that temporary directory.  See the
'os.chdir(tmpdir)' line above.

I sent a v4 with the above change.

-- 
Thanks,
Maxim

      reply	other threads:[~2022-12-20  3:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 15:50 [PATCH 0/6] add support for repository-local .patman config file Maxim Cournoyer
2022-12-19 15:50 ` [PATCH 1/6] patman: fix pep8 warnings in settings module Maxim Cournoyer
2022-12-19 19:20   ` Simon Glass
2022-12-19 15:50 ` [PATCH 2/6] patman: replace deprecated SafeConfigParser with ConfigParser Maxim Cournoyer
2022-12-19 19:20   ` Simon Glass
2022-12-19 15:50 ` [PATCH 3/6] patman: import gitutil module where it is needed Maxim Cournoyer
2022-12-19 19:20   ` Simon Glass
2022-12-19 15:50 ` [PATCH 4/6] patman: set the default config_fname argument value to None Maxim Cournoyer
2022-12-19 19:20   ` Simon Glass
2022-12-19 15:50 ` [PATCH 5/6] patman: fail early in Setup when provided config file does not exist Maxim Cournoyer
2022-12-19 19:20   ` Simon Glass
2022-12-19 15:50 ` [PATCH 6/6] patman: additionally honor a local .patman config file Maxim Cournoyer
2022-12-19 19:20   ` Simon Glass
2022-12-20  3:29     ` Maxim Cournoyer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sfha4use.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=maxim.cournoyer@savoirfairelinux.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.