Improve CmdPythonpath / mypy_path generation #10
1 changed files with 25 additions and 3 deletions
cmds.projects.CmdPythonpath: Opts subdir, delimiter, prefix
Support additional options:
--subdir makes the command look for these existing subdirectories. Can be specified multiple times.--delimiter Does the obvious and defaults to ":"
--prefix A string to prepend verbatim before each path component
Signed-off-by: Jan Lindemann <jan@janware.com>
commit
46b1ce776e
|
|
@ -1,8 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...App import Scope
|
||||
from .Cmd import Cmd, Parent
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
|
@ -16,6 +17,25 @@ class CmdPythonpath(Cmd): # export
|
|||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument(
|
||||
'--subdir',
|
||||
action = 'append',
|
||||
help = (
|
||||
'Directories to look for relative to the '
|
||||
'respective project root directory'
|
||||
),
|
||||
default = ['src/python', 'tools/python'],
|
||||
)
|
||||
parser.add_argument(
|
||||
'--delimiter',
|
||||
default = ':',
|
||||
help = 'Delimiter between paths',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--prefix',
|
||||
help = 'Prefix to prepend before every path component',
|
||||
dest = 'path_component_prefix',
|
||||
)
|
||||
parser.add_argument('module', help = 'Modules', nargs = '*')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
|
|
@ -29,8 +49,10 @@ class CmdPythonpath(Cmd): # export
|
|||
)
|
||||
out = []
|
||||
for m in deps:
|
||||
path = self.app.find_dir(m, ['src/python', 'tools/python'])
|
||||
path = self.app.find_dir(m, args.subdir)
|
||||
if path is not None:
|
||||
if args.path_component_prefix is not None:
|
||||
path = f'{args.path_component_prefix}{path}'
|
||||
out.append(path)
|
||||
if out:
|
||||
print(':'.join(out))
|
||||
print(args.delimiter.join(out))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue