diff --git a/pype/lib/__init__.py b/pype/lib/__init__.py index d10f3d199d..59eb2a645c 100644 --- a/pype/lib/__init__.py +++ b/pype/lib/__init__.py @@ -14,6 +14,7 @@ site.addsitedir( from .terminal import Terminal from .execute import ( + get_pype_execute_args, execute, run_subprocess ) @@ -112,6 +113,7 @@ from .editorial import ( terminal = Terminal __all__ = [ + "get_pype_execute_args", "execute", "run_subprocess", diff --git a/pype/lib/execute.py b/pype/lib/execute.py index 1f1adcdf23..6ad43c5e0d 100644 --- a/pype/lib/execute.py +++ b/pype/lib/execute.py @@ -133,3 +133,26 @@ def run_subprocess(*args, **kwargs): raise RuntimeError(exc_msg) return full_output + + +def get_pype_execute_args(): + """Arguments to run pype command. + + Arguments for subprocess when need to spawn new pype process. Which may be + needed when new python process for pype scripts must be executed in build + pype. + + ## Why is this needed? + Pype executed from code has different executable set to virtual env python + and must have path to script as first argument which is not needed for + build pype. + """ + pype_executable = os.environ["PYPE_EXECUTABLE"] + args = [pype_executable] + + executable_filename = os.path.dirname(pype_executable) + if "python" in executable_filename.lower(): + args.append( + os.path.join(os.environ["PYPE_ROOT"], "start.py") + ) + return args