App.__find_dir() Support --topdir-format make:XXX
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 2m57s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m46s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m26s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m38s
CI / Packaging test (push) Successful in 0s

The global --topdir-format make:XXX option to jw-pkg is half-baked at best, and __find_dir() ignores it entirely. Make __find_dir() return some Makefile-syntax-formatted output if the option is present. Not used anywhere, currently, and, hence, badly tested, but still better than the situation before.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-14 15:39:11 +02:00
commit b7d211b21e
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -130,7 +130,17 @@ class App(Base):
pretty: bool = True,
) -> str | None:
def format_pd(name: str, pd: str, pretty: bool):
def __format_relpath(path: str):
if path.startswith('./'):
return path[2:]
if path.endswith('/.'):
return path[:-2]
return path
def __relpath(target: str, base: str):
return __format_relpath(os.path.relpath(target, base))
def __format_pd(name: str, pd: str, pretty: bool):
if not pretty:
return pd
if self.__topdir_fmt == 'absolute':
@ -138,7 +148,11 @@ class App(Base):
if self.__topdir_fmt == 'unaltered':
return pd
if self.__topdir_fmt == 'relative':
return os.path.relpath(pd, self.__pretty_topdir)
return __relpath(pd, self.__topdir)
if self.__topdir_fmt.startswith('make:'):
relpath = __relpath(pd, self.__topdir)
var = self.__topdir_fmt.split(':')[1]
return __format_relpath(f'$({var})/{relpath}')
if name == self.__top_name:
return self.__pretty_topdir
raise NotImplementedError(
@ -149,11 +163,11 @@ class App(Base):
if pd is None:
return None
if not search_subdirs and not search_absdirs:
return format_pd(name, pd, pretty)
return __format_pd(name, pd, pretty)
for sd in search_subdirs:
path = pd + '/' + sd
if os.path.isdir(path):
ret = format_pd(name, pd, pretty)
ret = __format_pd(name, pd, pretty)
if sd and sd[0] != '/':
if ret == '.':
ret = ''