poethepoet
1from .__version__ import __version__ 2 3__all__ = ["__version__", "main"] 4 5 6def main(): 7 import sys 8 from pathlib import Path 9 10 if len(sys.argv) > 1 and sys.argv[1].startswith("_"): 11 first_arg = sys.argv[1] 12 second_arg = next(iter(sys.argv[2:]), "") 13 third_arg = next(iter(sys.argv[3:]), "") 14 15 if first_arg in ("_list_tasks", "_describe_tasks"): 16 _list_tasks(target_path=str(Path(second_arg).expanduser().resolve())) 17 return 18 19 target_path = "" 20 if second_arg: 21 if not second_arg.isalnum(): 22 raise ValueError(f"Invalid alias: {second_arg!r}") 23 24 if third_arg: 25 if not Path(third_arg).expanduser().resolve().exists(): 26 raise ValueError(f"Invalid path: {third_arg!r}") 27 28 target_path = str(Path(third_arg).resolve()) 29 30 if first_arg == "_zsh_completion": 31 from .completion.zsh import get_zsh_completion_script 32 33 print(get_zsh_completion_script(name=second_arg)) 34 return 35 36 if first_arg == "_bash_completion": 37 from .completion.bash import get_bash_completion_script 38 39 print(get_bash_completion_script(name=second_arg, target_path=target_path)) 40 return 41 42 if first_arg == "_fish_completion": 43 from .completion.fish import get_fish_completion_script 44 45 print(get_fish_completion_script(name=second_arg)) 46 return 47 48 from .app import PoeThePoet 49 50 app = PoeThePoet(cwd=Path().resolve(), output=sys.stdout) 51 result = app(cli_args=sys.argv[1:]) 52 if result: 53 raise SystemExit(result) 54 55 56def _list_tasks(target_path: str = ""): 57 """ 58 A special task accessible via `poe _list_tasks` for use in shell completion 59 60 Note this code path should include minimal imports to avoid slowing down the shell 61 """ 62 63 try: 64 from .config import PoeConfig 65 66 config = PoeConfig() 67 config.load(target_path, strict=False) 68 task_names = (task for task in config.task_names if task and task[0] != "_") 69 print(" ".join(task_names)) 70 except Exception: 71 # this happens if there's no pyproject.toml present 72 pass
__version__ =
'0.30.0'
def
main():
7def main(): 8 import sys 9 from pathlib import Path 10 11 if len(sys.argv) > 1 and sys.argv[1].startswith("_"): 12 first_arg = sys.argv[1] 13 second_arg = next(iter(sys.argv[2:]), "") 14 third_arg = next(iter(sys.argv[3:]), "") 15 16 if first_arg in ("_list_tasks", "_describe_tasks"): 17 _list_tasks(target_path=str(Path(second_arg).expanduser().resolve())) 18 return 19 20 target_path = "" 21 if second_arg: 22 if not second_arg.isalnum(): 23 raise ValueError(f"Invalid alias: {second_arg!r}") 24 25 if third_arg: 26 if not Path(third_arg).expanduser().resolve().exists(): 27 raise ValueError(f"Invalid path: {third_arg!r}") 28 29 target_path = str(Path(third_arg).resolve()) 30 31 if first_arg == "_zsh_completion": 32 from .completion.zsh import get_zsh_completion_script 33 34 print(get_zsh_completion_script(name=second_arg)) 35 return 36 37 if first_arg == "_bash_completion": 38 from .completion.bash import get_bash_completion_script 39 40 print(get_bash_completion_script(name=second_arg, target_path=target_path)) 41 return 42 43 if first_arg == "_fish_completion": 44 from .completion.fish import get_fish_completion_script 45 46 print(get_fish_completion_script(name=second_arg)) 47 return 48 49 from .app import PoeThePoet 50 51 app = PoeThePoet(cwd=Path().resolve(), output=sys.stdout) 52 result = app(cli_args=sys.argv[1:]) 53 if result: 54 raise SystemExit(result)