From b88f2a846169252e5e1d6a0874137d33e59903c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Wed, 13 Jan 2021 00:00:51 +0100 Subject: [PATCH] add run command --- pype/cli.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pype/cli.py b/pype/cli.py index 93858f15d0..e07786e76a 100644 --- a/pype/cli.py +++ b/pype/cli.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """Package for handling pype command line arguments.""" import os +import sys import click @@ -271,3 +272,25 @@ def generate_zip(path): """ PypeCommands().generate_zip(path) + + +@main.command( + context_settings=dict( + ignore_unknown_options=True, + allow_extra_args=True)) +@click.argument("script", required=True, type=click.Path(exists=True)) +def run(script): + """Run python script.""" + import runpy + + if not script: + print("Error: missing path to script file.") + else: + + args = sys.argv + args.remove("run") + args.remove(script) + sys.argv = args + args_string = " ".join(args[1:]) + print(f"... running: {script} {args_string}") + runpy.run_path(script, run_name="__main__", )