App.find_dir(): Allow return value None

Allow find_dir() to return None in case it couldn't find a directory, that's a legal outcome. Add a boolean parameter "throw" to support throwing an exception if the existence needs to be asserted.

It would probably be nicer for the type checkers to split this up into a throwing and non-throwing function. Postponed.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-01 19:55:43 +02:00
commit f687ded1a6
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
3 changed files with 27 additions and 18 deletions

View file

@ -57,9 +57,12 @@ class CmdGetAuthInfo(Cmd): # export
# --- Milk jw-pkg repo
jw_pkg_dir = self.app.find_dir('jw-pkg', pretty = False)
if jw_pkg_dir is None:
log(DEBUG, 'Can\'t find jw-pkg directory')
return None
if not os.path.isdir(jw_pkg_dir + '/.git'):
log(DEBUG, f'jw-pkg directory is not a Git repo: {jw_pkg_dir}')
return
return None
git_result = await self.app.exec_context.run(
['git', '-C', jw_pkg_dir, 'remote', '-v']
)

View file

@ -22,5 +22,8 @@ class CmdTmplDir(Cmd): # export
async def _run(self, args: Namespace) -> None:
r = []
for m in args.module:
r.append(self.app.tmpl_dir(m))
d = self.app.tmpl_dir(m)
if d is None:
continue
r.append(d)
print(' '.join(r))