Skip to content

Commit

Permalink
Merge pull request #372 from ynput/enhancement/run-command-enhancement
Browse files Browse the repository at this point in the history
Chore: Run command args handling
  • Loading branch information
iLLiCiTiT authored Apr 4, 2024
2 parents 33b3d05 + 041933e commit c12a351
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions client/ayon_core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import sys
import code
import traceback
from pathlib import Path

import click
import acre

from ayon_core import AYON_CORE_ROOT
from ayon_core.addon import AddonsManager
from ayon_core.settings import get_general_environments
from ayon_core.lib import initialize_ayon_connection
from ayon_core.lib import initialize_ayon_connection, is_running_from_build

from .cli_commands import Commands

Expand Down Expand Up @@ -167,16 +168,27 @@ def run(script):

if not script:
print("Error: missing path to script file.")
return

# Remove first argument if it is the same as AYON executable
# - Forward compatibility with future AYON versions.
# - Current AYON launcher keeps the arguments with first argument but
# future versions might remove it.
first_arg = sys.argv[0]
if is_running_from_build():
comp_path = os.path.join(os.environ["AYON_ROOT"], "start.py")
else:
comp_path = os.getenv("AYON_EXECUTABLE")
# Compare paths and remove first argument if it is the same as AYON
if Path(first_arg).resolve() == Path(comp_path).resolve():
sys.argv.pop(0)

args = sys.argv
args.remove("run")
args.remove(script)
sys.argv = args
# Remove 'run' command from sys.argv
sys.argv.remove("run")

args_string = " ".join(args[1:])
print(f"... running: {script} {args_string}")
runpy.run_path(script, run_name="__main__", )
args_string = " ".join(sys.argv[1:])
print(f"... running: {script} {args_string}")
runpy.run_path(script, run_name="__main__")


@main_cli.command()
Expand Down

0 comments on commit c12a351

Please sign in to comment.