App.__find_dir() Support --topdir-format make:XXX #21
1 changed files with 18 additions and 4 deletions
|
|
@ -130,7 +130,17 @@ class App(Base):
|
||||||
pretty: bool = True,
|
pretty: bool = True,
|
||||||
) -> str | None:
|
) -> 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:
|
if not pretty:
|
||||||
return pd
|
return pd
|
||||||
if self.__topdir_fmt == 'absolute':
|
if self.__topdir_fmt == 'absolute':
|
||||||
|
|
@ -138,7 +148,11 @@ class App(Base):
|
||||||
if self.__topdir_fmt == 'unaltered':
|
if self.__topdir_fmt == 'unaltered':
|
||||||
return pd
|
return pd
|
||||||
if self.__topdir_fmt == 'relative':
|
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:
|
if name == self.__top_name:
|
||||||
return self.__pretty_topdir
|
return self.__pretty_topdir
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
|
|
@ -149,11 +163,11 @@ class App(Base):
|
||||||
if pd is None:
|
if pd is None:
|
||||||
return None
|
return None
|
||||||
if not search_subdirs and not search_absdirs:
|
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:
|
for sd in search_subdirs:
|
||||||
path = pd + '/' + sd
|
path = pd + '/' + sd
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
ret = format_pd(name, pd, pretty)
|
ret = __format_pd(name, pd, pretty)
|
||||||
if sd and sd[0] != '/':
|
if sd and sd[0] != '/':
|
||||||
if ret == '.':
|
if ret == '.':
|
||||||
ret = ''
|
ret = ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue