Improve CmdPythonpath / mypy_path generation #10

Merged
Jan Lindemann merged 4 commits from jan/feature/20260611-feature/20260611-better-mypy-path into master 2026-06-11 12:48:14 +02:00 AGit
Showing only changes of commit 46b1ce776e - Show all commits

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>
Jan Lindemann 2026-06-11 11:56:11 +02:00
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -1,8 +1,9 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from ...App import Scope from ...App import Scope
from .Cmd import Cmd, Parent from .Cmd import Cmd, Parent
from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace from argparse import ArgumentParser, Namespace
@ -16,6 +17,25 @@ class CmdPythonpath(Cmd): # export
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser) 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 = '*') parser.add_argument('module', help = 'Modules', nargs = '*')
async def _run(self, args: Namespace) -> None: async def _run(self, args: Namespace) -> None:
@ -29,8 +49,10 @@ class CmdPythonpath(Cmd): # export
) )
out = [] out = []
for m in deps: 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 path is not None:
if args.path_component_prefix is not None:
path = f'{args.path_component_prefix}{path}'
out.append(path) out.append(path)
if out: if out:
print(':'.join(out)) print(args.delimiter.join(out))