From aba4164ca9589d178175751e6f6bccebd99470a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 7 Apr 2021 15:12:55 -0700 Subject: [PATCH] update: add update.name-cache, update.path-cache config options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These set default values of the --name-cache and --path-cache command line options, respectively. Signed-off-by: Martí Bolívar --- src/west/app/project.py | 33 +++++++++++++++---------- tests/test_project.py | 54 +++++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/west/app/project.py b/src/west/app/project.py index c9ea044..7da5580 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -817,6 +817,10 @@ class Update(_ProjectCommand): self.narrow = args.narrow or config.getboolean('update', 'narrow', fallback=False) + self.path_cache = args.path_cache or config.get('update', 'path-cache', + fallback=None) + self.name_cache = args.name_cache or config.get('update', 'name-cache', + fallback=None) self.group_filter: List[str] = [] @@ -1151,26 +1155,29 @@ class Update(_ProjectCommand): def project_cache(self, project): # Find the absolute path to a pre-existing local clone of a project # and return it. If the search fails, return None. - name_cache, path_cache = self.args.name_cache, self.args.path_cache - if name_cache is not None: - maybe = Path(name_cache) / project.name + if self.name_cache is not None: + maybe = Path(self.name_cache) / project.name if maybe.is_dir(): - log.dbg(f'found {project.name} in --name-cache {name_cache}', - level=log.VERBOSE_VERY) + log.dbg( + f'found {project.name} in --name-cache {self.name_cache}', + level=log.VERBOSE_VERY) return os.fspath(maybe) else: - log.dbg(f'{project.name} not in --name-cache {name_cache}', - level=log.VERBOSE_VERY) - elif self.args.path_cache is not None: - maybe = Path(self.args.path_cache) / project.path + log.dbg( + f'{project.name} not in --name-cache {self.name_cache}', + level=log.VERBOSE_VERY) + elif self.path_cache is not None: + maybe = Path(self.path_cache) / project.path if maybe.is_dir(): - log.dbg(f'found {project.path} in --path-cache {path_cache}', - level=log.VERBOSE_VERY) + log.dbg( + f'found {project.path} in --path-cache {self.path_cache}', + level=log.VERBOSE_VERY) return os.fspath(maybe) else: - log.dbg(f'{project.path} not in --path-cache {path_cache}', - level=log.VERBOSE_VERY) + log.dbg( + f'{project.path} not in --path-cache {self.path_cache}', + level=log.VERBOSE_VERY) return None diff --git a/tests/test_project.py b/tests/test_project.py index 3160ac6..4a40a2a 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -969,23 +969,34 @@ def test_update_name_cache(tmpdir): # network if it doesn't have to. name_cache_dir = tmpdir / 'name_cache' - create_repo(name_cache_dir / 'foo') create_repo(name_cache_dir / 'bar') - foo_head = rev_parse(name_cache_dir / 'foo', 'HEAD') bar_head = rev_parse(name_cache_dir / 'bar', 'HEAD') workspace = tmpdir / 'workspace' setup_cache_workspace(workspace, foo_head, bar_head) + workspace.chdir() + foo = workspace / 'subdir' / 'foo' + bar = workspace / 'bar' - cmd(f'update --name-cache {name_cache_dir}', cwd=workspace) + # Test the command line option. + cmd(f'update --name-cache {name_cache_dir}') + assert foo.check(dir=1) + assert bar.check(dir=1) + assert rev_parse(foo, 'HEAD') == foo_head + assert rev_parse(bar, 'HEAD') == bar_head - assert (workspace / 'subdir' / 'foo').check(dir=1) - assert (workspace / 'bar').check(dir=1) - - assert rev_parse(workspace / 'subdir' / 'foo', 'HEAD') == foo_head - assert rev_parse(workspace / 'bar', 'HEAD') == bar_head + # Move the repositories out of the way and test the configuration option. + # (We can't use shutil.rmtree here because Windows.) + shutil.move(os.fspath(foo), os.fspath(tmpdir)) + shutil.move(os.fspath(bar), os.fspath(tmpdir)) + cmd(f'config update.name-cache {name_cache_dir}') + cmd('update') + assert foo.check(dir=1) + assert bar.check(dir=1) + assert rev_parse(foo, 'HEAD') == foo_head + assert rev_parse(bar, 'HEAD') == bar_head def test_update_path_cache(tmpdir): @@ -993,23 +1004,34 @@ def test_update_path_cache(tmpdir): # network if it doesn't have to. path_cache_dir = tmpdir / 'path_cache_dir' - create_repo(path_cache_dir / 'subdir' / 'foo') create_repo(path_cache_dir / 'bar') - foo_head = rev_parse(path_cache_dir / 'subdir' / 'foo', 'HEAD') bar_head = rev_parse(path_cache_dir / 'bar', 'HEAD') workspace = tmpdir / 'workspace' setup_cache_workspace(workspace, foo_head, bar_head) + workspace.chdir() + foo = workspace / 'subdir' / 'foo' + bar = workspace / 'bar' - cmd(f'update --path-cache {path_cache_dir}', cwd=workspace) + # Test the command line option. + cmd(f'update --path-cache {path_cache_dir}') + assert foo.check(dir=1) + assert bar.check(dir=1) + assert rev_parse(foo, 'HEAD') == foo_head + assert rev_parse(bar, 'HEAD') == bar_head - assert (workspace / 'subdir' / 'foo').check(dir=1) - assert (workspace / 'bar').check(dir=1) - - assert rev_parse(workspace / 'subdir' / 'foo', 'HEAD') == foo_head - assert rev_parse(workspace / 'bar', 'HEAD') == bar_head + # Move the repositories out of the way and test the configuration option. + # (We can't use shutil.rmtree here because Windows.) + shutil.move(os.fspath(foo), os.fspath(tmpdir)) + shutil.move(os.fspath(bar), os.fspath(tmpdir)) + cmd(f'config update.path-cache {path_cache_dir}') + cmd('update') + assert foo.check(dir=1) + assert bar.check(dir=1) + assert rev_parse(foo, 'HEAD') == foo_head + assert rev_parse(bar, 'HEAD') == bar_head def setup_narrow(tmpdir):