jw-pkg/src/python/jw/pkg/cmds/projects/CmdPythonpath.py

29 lines
958 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from ..Cmd import Cmd
class CmdPythonpath(Cmd): # export
def __init__(self) -> None:
super().__init__('pythonpath', help='Generate PYTHONPATH for given modules')
def add_arguments(self, p: ArgumentParser) -> None:
super().add_arguments(p)
p.add_argument('module', help='Modules', nargs='*')
def _run(self, args: Namespace) -> None:
import os
deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], [ 'run', 'build' ],
scope = 2, add_self=True, names_only=True)
r = ''
for m in deps:
pd = self.app.proj_dir(m)
if pd is None:
continue
for subdir in [ 'src/python', 'tools/python' ]:
cand = pd + "/" + subdir
if os.path.isdir(cand):
r = r + ':' + cand
print(r[1:])