Turning VS Code into an Ayon script editor

I’m trying to set up a coding test bed in VS Code so that I can interact with the Ayon modules kind of like you can in the Nuke script editor. I’ve followed some of the steps in @mustafa_jafar’s Ayon Development Workbench repo to get all of our internal Ayon dev repos into the PYTHONPATH. So that everything is accessible from my VS Code workspace. But I want to be able to run Ayon code in VS Code.

I was just curious to see what it would take to set VS Code up for this or if anyone else has tried it…

I was able to get this sort of working. In the .vscode folder in my project I added an env file to establish the pythonpath and any envars I need.

In the settings.json
"python.envFile": "${workspaceFolder}/.vscode/env"

Then in the env file:

PYTHONPATH=/pipe/dev/jberkheimer/ayon/ayon-core/client:/sw/nuke/15.0v4/lib/python3.10/site-packages:/pipe/ayon/release/AYON-1.0.5-dev.2-linux-ubuntu22/dependencies:$PYTHONPATH

AYON_BUNDLE_NAME=DEV

As long as I gave my test code the proper arguments (project_name, folder_path, task_name,host_name) I was able to ayon_core.pipeline.template_data.get_template_data() and get data returned.

This allowed me to edit some code in ayon_core and do some testing right away without having to open Nuke. It’s probably not the perfect setup to cover all dev possibilities. But it’s enough to get me what wanted for now.

1 Like

You could also run ayon_console run /path/to/pythonscript.py which would go through the core addon CLI here

However, it’d run slower than just a python interpreter - but at least it’d go through the full ayon ‘initialization’ of the core itself?

Note that you can also do ayon_core interactive (which is one of the other CLI entry points in core in the linked code but a bit lower here

But, you could set up your IDE to run ayon_console run {current_file} and you’re off to a good start potentially?


Also, are you aware of the DEV mode in AYON? Basically you can run, e.g. Nuke integration (and launcher, etc.) from live source code on your machine instead of installed packages. I’d say that’s critical for development workflows with AYON.

Let me just spell out some thoughts:
(As far as I know and please correct me if I’m wrong.)

  1. Testing integration addon’s functionality (e.g. Nuke addon) is different from testing core functionalities and API calls. as the integration addon is supposed to be run within the host (e.g. Nuke) it self.
  2. Being able to import all code from different addons doesn’t mean you have a working AYON dev environment setup because there are important things that happens on initialization (e.g. setting tool groups for your current context). This is reason why I only used these paths for code completion without caring much about running it.

Possible ways to test:

(sorry for repeating most of @BigRoy’s answer)

  • Run Code in AYON’s console (script editor). (Access it via Tray menu, Admin > Console)

  • Ask AYON to run a script. which I think is equivalent to the previous suggestion). You can do it via terminal.

    ayon_console run /path/to/pythonscript.py
    
  • Run AYON in interactively (Python like) console.

    ayon_console interactive
    
  • There some internal discussion about using Jupyter but currently there is some conflicts in the dependencies on my side. and there is no request for supporting Jupyter atm.

  • Open Terminal with your app environment initialized. I think it can be a middle ground for running scripts while expecting all env to be set like AYON_PROJECT_NAME.

  • Run Apps in Headless mode and build up some testing scripts like if you are doing it outside of AYON.

    ayon_console addon applications launch --app <app_name> -- project <project_name> --folder <ayon_folder_path> --task <ayon_task_name>
    
  • Use AYON Dev Mode where you can test directly/manually client code. Ayon Developer Mode -- Guide

1 Like

@mustafa_jafar @BigRoy Thanks for the replies. First off, yes I am aware of dev mode. If you notice in my last post, I am setting AYON_BUNDLE_NAME=DEV

I was not aware of the CLI functionality on Core, that’s actually good to know. I was aware of the terminal launcher. While I find it useful for certain circumstances, I wouldn’t use that in my main dev workflow.

VS Code is what I use as my main dev platform. I try to do as much in there as I can. In my test bed I setup entry points for the project in my pyproject.toml:

[project.scripts]
cmd = "ax_tester.main:main"
test1 = "ax_tester.tester:test1"
test2 = "ax_tester.tester:test2"
test3 = "ax_tester.tester:test3"
test4 = "ax_tester.tester:test4"

Those test[1-4] entry points are functions I put my test code in. For example here is test2()

def test2():
    import json

    from ayon_core.pipeline import context_tools, template_data

    # context = context_tools.get_current_context()

    project_name = "sandbox_2024"
    folder_path = "/504/504_025/evl_504_025_040"
    task_name = "james_test"
    host_name = "nuke"

    print(
        f"\nProject Name: {project_name}, Folder Path: {folder_path}, Task Name: {task_name}, Host Name: {host_name}"
    )

    anatomy_data = template_data.get_template_data_with_names(
        project_name, folder_path, task_name, host_name
    )

    print(f"\n{json.dumps(anatomy_data, indent=4)}")

So in my terminal in VS Code, which has my virtual env activated, I can call test2 and that function will run. To me this is essentially the same as running ayon_console run /path/to/pythonscript.py but much more convenient.

This might not be a test system that covers every possible scenario. But so far it’s working for me.