Improve CmdPythonpath / mypy_path generation #10
1 changed files with 9 additions and 2 deletions
App: Support --topdir-format "relative"
The global --topdir-format option governs how a project's root directory is represented in paths output by various queries. "absolute" means as absolute path, "unaltered" means verbatim as specified via --topdir, make:xyz means replaced by the string $(xyz), for later expansion in a makefile variable.
This commit adds another variant: "relative" yields the shortest possible output format of the output path in question relative to --topdir, with "shortest possible" in this context meaning canonicalized and leading "./" stripped.
Signed-off-by: Jan Lindemann <jan@janware.com>
commit
b35d61311c
|
|
@ -83,6 +83,8 @@ class App(Base):
|
||||||
match fmt:
|
match fmt:
|
||||||
case 'unaltered':
|
case 'unaltered':
|
||||||
return path
|
return path
|
||||||
|
case 'relative':
|
||||||
|
return os.path.relpath(path)
|
||||||
case None | 'absolute':
|
case None | 'absolute':
|
||||||
return os.path.abspath(path)
|
return os.path.abspath(path)
|
||||||
case _:
|
case _:
|
||||||
|
|
@ -135,6 +137,8 @@ class App(Base):
|
||||||
return os.path.abspath(pd)
|
return os.path.abspath(pd)
|
||||||
if self.__topdir_fmt == 'unaltered':
|
if self.__topdir_fmt == 'unaltered':
|
||||||
return pd
|
return pd
|
||||||
|
if self.__topdir_fmt == 'relative':
|
||||||
|
return os.path.relpath(pd, self.__pretty_topdir)
|
||||||
if name == self.__top_name:
|
if name == self.__top_name:
|
||||||
return self.__pretty_topdir
|
return self.__pretty_topdir
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
|
|
@ -151,7 +155,10 @@ class App(Base):
|
||||||
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] != '/':
|
||||||
ret += '/'
|
if ret == '.':
|
||||||
|
ret = ''
|
||||||
|
else:
|
||||||
|
ret += '/'
|
||||||
ret += sd
|
ret += sd
|
||||||
return ret
|
return ret
|
||||||
for ret in search_absdirs:
|
for ret in search_absdirs:
|
||||||
|
|
@ -345,7 +352,7 @@ class App(Base):
|
||||||
default = 'absolute',
|
default = 'absolute',
|
||||||
help = (
|
help = (
|
||||||
'Output references to topdir as one of "make:<var-name>", '
|
'Output references to topdir as one of "make:<var-name>", '
|
||||||
'"unaltered", "absolute". Absolute topdir by default'
|
'"unaltered", "relative", "absolute". Absolute topdir by default'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue