
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.