From 6c8ec85298d56ec0a8c27465749b0e9d30bd1e84 Mon Sep 17 00:00:00 2001 From: Steven Banaszak Date: Sun, 6 Oct 2024 15:01:13 -0700 Subject: [PATCH] feat: Handle different OCIO configs in adapter Signed-off-by: Steven Banaszak --- DEVELOPMENT.md | 71 +++++++++++++++++-- .../nuke_adaptor/NukeClient/nuke_client.py | 2 +- src/deadline/nuke_submitter/assets.py | 15 +--- .../deadline_submitter_for_nuke.py | 3 +- src/deadline/nuke_util/ocio.py | 19 +++++ .../NukeClient/test_client.py | 2 +- .../test_assets.py | 39 ---------- test/unit/nuke_util/test_ocio.py | 38 ++++++++++ 8 files changed, 126 insertions(+), 63 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 14fc369..ac67b7f 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -50,12 +50,71 @@ will work on Linux or MacOS if you modify the path references as appropriate. WARNING: This workflow installs additional Python packages into your Nuke's python distribution. You may need to run the Command Prompt in Administrative mode if your current user does not have permission to write on Nuke's site-package folder. 1. Create a development location within which to do your git checkouts. For example `~/deadline-clients`. Clone packages from this directory with commands like `git clone git@github.com:aws-deadline/deadline-cloud-for-nuke.git`. You'll also want the `deadline-cloud` repo. -2. Switch to your Nuke directory, like `cd "C:\Program Files\Nuke15.0v2"`. -3. Run `.\python -m pip install -e C:\Users\\deadline-clients\deadline-cloud` to install the AWS Deadline Cloud Client Library in edit mode. -4. Run `.\python -m pip install -e C:\Users\\deadline-clients\deadline-cloud-for-nuke` to install the Nuke Submitter in edit mode. -5. Run `set NUKE_PATH=C:\Users\\deadline-clients\deadline-cloud-for-nuke\src\deadline\nuke_submitter` to put the `menu.py` file in the path Nuke searches for menu extensions. -6. Run `set DEADLINE_ENABLE_DEVELOPER_OPTIONS=true` to enable the job bundle debugging support. This enables a menu item you can use to run the tests from the `job_bundle_output_tests` directory. -7. Run `.\Nuke.exe` to run Nuke. The Nuke submitter should be available in the AWS Deadline menu. +1. Switch to your Nuke directory, like `cd "C:\Program Files\Nuke15.0v2"`. + + Windows (update the path as needed): + ``` + cd "C:\Program Files\Nuke15.0v2" + ``` + + Mac (update the path as needed): + ``` + cd /Applications/Nuke15.0v4/Nuke15.0v4.app/Contents/MacOS + ``` +1. Install the AWS Deadline Cloud Client Library in edit mode. + + Windows (update the path as needed): + ``` + .\python -m pip install -e C:\Users\\deadline-clients\deadline-cloud + ``` + + Mac (update the path as needed): + ``` + ./python -m pip install -e /Users//dev/deadline-clients/deadline-cloud + ``` +1. Run `.\python -m pip install -e C:\Users\\deadline-clients\deadline-cloud-for-nuke` to install the Nuke Submitter in edit mode. + + Windows (update the path as needed): + ``` + .\python -m pip install -e C:\Users\\deadline-clients\deadline-cloud-for-nuke + ``` + + Mac (update the path as needed): + ``` + ./python -m pip install -e /Users//dev/deadline-clients/deadline-cloud-for-nuke + ``` +1. Put the `menu.py` file in the path Nuke searches for menu extensions. If you have already set your `NUKE_PATH` environment variable, append these paths to it instead of replacing it. + + Windows (update the paths as needed): + ``` + set NUKE_PATH=C:\Users\\deadline-clients\deadline-cloud-for-nuke\src\deadline\nuke_submitter:C:\Users\\deadline-clients\deadline-cloud-for-nuke\src + ``` + + Mac (update the paths as needed): + ``` + export NUKE_PATH=/Users//dev/deadline-clients/deadline-cloud-for-nuke/src/deadline/nuke_submitter:/Users//dev/deadline-clients/deadline-cloud-for-nuke/src + ``` +1. Set the `DEADLINE_ENABLE_DEVELOPER_OPTIONS` environment variable to `true` to enable the job bundle debugging support. This enables a menu item you can use to run the tests from the `job_bundle_output_tests` directory. + + Windows: + ``` + set DEADLINE_ENABLE_DEVELOPER_OPTIONS=true + ``` + + Mac: + ``` + export DEADLINE_ENABLE_DEVELOPER_OPTIONS=true + ``` +1. Run Nuke. The Nuke submitter should be available in the AWS Deadline menu. + Windows: + ``` + .\Nuke.exe + ``` + + Mac: + ``` + ./Nuke + ``` ## Application Interface Adaptor Development Workflow diff --git a/src/deadline/nuke_adaptor/NukeClient/nuke_client.py b/src/deadline/nuke_adaptor/NukeClient/nuke_client.py index 9d0fb31..9dee15d 100644 --- a/src/deadline/nuke_adaptor/NukeClient/nuke_client.py +++ b/src/deadline/nuke_adaptor/NukeClient/nuke_client.py @@ -117,7 +117,7 @@ def _which_rule_applies( def _map_ocio_config(self): """If the OCIO config contains absolute search paths, apply path mapping rules and create a new config""" - ocio_config_path = nuke_ocio.get_custom_config_path() + ocio_config_path = nuke_ocio.get_ocio_config_path() ocio_config = nuke_ocio.create_config_from_file(ocio_config_path) if nuke_ocio.config_has_absolute_search_paths(ocio_config): # make all search paths absolute since the new config will be saved in the nuke temp dir diff --git a/src/deadline/nuke_submitter/assets.py b/src/deadline/nuke_submitter/assets.py index 8c53261..2069a02 100644 --- a/src/deadline/nuke_submitter/assets.py +++ b/src/deadline/nuke_submitter/assets.py @@ -7,7 +7,6 @@ from collections.abc import Generator from os.path import commonpath, dirname, join, normpath, samefile from sys import platform -from typing import Optional import nuke from deadline.client.job_bundle.submission import AssetReferences @@ -83,7 +82,7 @@ def get_scene_asset_references() -> AssetReferences: if nuke_ocio.is_OCIO_enabled(): # Determine and add the config file and associated search directories - ocio_config_path = get_ocio_config_path() + ocio_config_path = nuke_ocio.get_ocio_config_path() # Add the references if ocio_config_path is not None: if os.path.isfile(ocio_config_path): @@ -103,18 +102,6 @@ def get_scene_asset_references() -> AssetReferences: return asset_references -def get_ocio_config_path() -> Optional[str]: - # if using a custom OCIO environment variable - if nuke_ocio.is_env_config_enabled(): - return nuke_ocio.get_env_config_path() - elif nuke_ocio.is_custom_config_enabled(): - return nuke_ocio.get_custom_config_path() - elif nuke_ocio.is_stock_config_enabled(): - return nuke_ocio.get_stock_config_path() - else: - return None - - def find_all_write_nodes() -> set: write_nodes = set() diff --git a/src/deadline/nuke_submitter/deadline_submitter_for_nuke.py b/src/deadline/nuke_submitter/deadline_submitter_for_nuke.py index 36b866e..6fecc6d 100644 --- a/src/deadline/nuke_submitter/deadline_submitter_for_nuke.py +++ b/src/deadline/nuke_submitter/deadline_submitter_for_nuke.py @@ -30,7 +30,6 @@ get_nuke_script_file, get_scene_asset_references, find_all_write_nodes, - get_ocio_config_path, ) from .data_classes import RenderSubmitterUISettings from .ui.components.scene_settings_tab import SceneSettingsWidget @@ -276,7 +275,7 @@ def _get_parameter_values( # Set the OCIO config path value if nuke_ocio.is_OCIO_enabled(): - ocio_config_path = get_ocio_config_path() + ocio_config_path = nuke_ocio.get_ocio_config_path() if ocio_config_path: parameter_values.append({"name": "OCIOConfigPath", "value": ocio_config_path}) else: diff --git a/src/deadline/nuke_util/ocio.py b/src/deadline/nuke_util/ocio.py index 7c7ed54..3ee3508 100644 --- a/src/deadline/nuke_util/ocio.py +++ b/src/deadline/nuke_util/ocio.py @@ -84,3 +84,22 @@ def update_config_search_paths(ocio_config: OCIO.Config, search_paths: list[str] def set_custom_config_path(ocio_config_path: str) -> None: """Set the knob on the root settings to update the OCIO config""" nuke.root().knob("customOCIOConfigPath").setValue(ocio_config_path) + + +def get_ocio_config_path() -> Optional[str]: + """ + Get the path to the OCIO configurations. Supports: + - OCIO environment variable + - Custom config + - Stock config + Returns None if OCIO is not enabled + """ + # if using a custom OCIO environment variable + if is_env_config_enabled(): + return get_env_config_path() + elif is_custom_config_enabled(): + return get_custom_config_path() + elif is_stock_config_enabled(): + return get_stock_config_path() + else: + return None diff --git a/test/unit/deadline_adaptor_for_nuke/NukeClient/test_client.py b/test/unit/deadline_adaptor_for_nuke/NukeClient/test_client.py index efb5bd4..d6137a0 100644 --- a/test/unit/deadline_adaptor_for_nuke/NukeClient/test_client.py +++ b/test/unit/deadline_adaptor_for_nuke/NukeClient/test_client.py @@ -276,7 +276,7 @@ def test_recursive_map_path( @pytest.mark.skipif(os.name == "nt", reason="POSIX path mapping not implemented on Windows") @patch.dict(os.environ, {"NUKE_TEMP_DIR": "/var/tmp/nuke_temp_dir"}) @patch( - "deadline.nuke_util.ocio.get_custom_config_path", + "deadline.nuke_util.ocio.get_ocio_config_path", return_value="/session-dir/ocio/custom_config.ocio", ) @patch( diff --git a/test/unit/deadline_submitter_for_nuke/test_assets.py b/test/unit/deadline_submitter_for_nuke/test_assets.py index e118607..515ac0d 100644 --- a/test/unit/deadline_submitter_for_nuke/test_assets.py +++ b/test/unit/deadline_submitter_for_nuke/test_assets.py @@ -14,7 +14,6 @@ get_node_file_knob_paths, get_node_filenames, get_scene_asset_references, - get_ocio_config_path, ) @@ -114,44 +113,6 @@ def test_get_scene_asset_references( ) -@patch("deadline.nuke_util.ocio.is_env_config_enabled", return_value=True) -@patch("deadline.nuke_util.ocio.is_custom_config_enabled", return_value=False) -@patch("deadline.nuke_util.ocio.is_stock_config_enabled", return_value=False) -@patch( - "deadline.nuke_util.ocio.get_env_config_path", - return_value="/this/ocio_configs/env_variable_config.ocio", -) -@patch( - "deadline.nuke_util.ocio.get_custom_config_path", - return_value="/this/ocio_configs/custom_config.ocio", -) -@patch( - "deadline.nuke_util.ocio.get_stock_config_path", - return_value="/this/ocio_configs/stock_config.ocio", -) -def test_get_ocio_config_path( - mock_get_stock_config_path, - mock_get_custom_config_path, - mock_get_env_config_path, - mock_is_stock_config_enabled, - mock_is_custom_enabled, - mock_is_env_config_enabled, -): - env_variable_ocio_path = get_ocio_config_path() - assert env_variable_ocio_path == "/this/ocio_configs/env_variable_config.ocio" - - mock_is_env_config_enabled.return_value = False - mock_is_custom_enabled.return_value = True - custom_ocio_path = get_ocio_config_path() - assert custom_ocio_path == "/this/ocio_configs/custom_config.ocio" - - mock_is_env_config_enabled.return_value = False - mock_is_custom_enabled.return_value = False - mock_is_stock_config_enabled.return_value = True - stock_ocio_path = get_ocio_config_path() - assert stock_ocio_path == "/this/ocio_configs/stock_config.ocio" - - @patch("os.path.isfile", return_value=False) @patch("deadline.nuke_submitter.assets.get_nuke_script_file", return_value="/this/scriptfile.nk") def test_get_scene_asset_references_script_not_saved( diff --git a/test/unit/nuke_util/test_ocio.py b/test/unit/nuke_util/test_ocio.py index 577f7ac..d1234b2 100644 --- a/test/unit/nuke_util/test_ocio.py +++ b/test/unit/nuke_util/test_ocio.py @@ -239,3 +239,41 @@ def test_is_OCIO_enabled(root_node_with_default_ocio, root_node) -> None: os.environ["OCIO"] = "not-empty" actual = nuke_ocio.is_OCIO_enabled() assert expected == actual + + +@patch("deadline.nuke_util.ocio.is_env_config_enabled", return_value=True) +@patch("deadline.nuke_util.ocio.is_custom_config_enabled", return_value=False) +@patch("deadline.nuke_util.ocio.is_stock_config_enabled", return_value=False) +@patch( + "deadline.nuke_util.ocio.get_env_config_path", + return_value="/this/ocio_configs/env_variable_config.ocio", +) +@patch( + "deadline.nuke_util.ocio.get_custom_config_path", + return_value="/this/ocio_configs/custom_config.ocio", +) +@patch( + "deadline.nuke_util.ocio.get_stock_config_path", + return_value="/this/ocio_configs/stock_config.ocio", +) +def test_get_ocio_config_path( + mock_get_stock_config_path, + mock_get_custom_config_path, + mock_get_env_config_path, + mock_is_stock_config_enabled, + mock_is_custom_enabled, + mock_is_env_config_enabled, +): + env_variable_ocio_path = nuke_ocio.get_ocio_config_path() + assert env_variable_ocio_path == "/this/ocio_configs/env_variable_config.ocio" + + mock_is_env_config_enabled.return_value = False + mock_is_custom_enabled.return_value = True + custom_ocio_path = nuke_ocio.get_ocio_config_path() + assert custom_ocio_path == "/this/ocio_configs/custom_config.ocio" + + mock_is_env_config_enabled.return_value = False + mock_is_custom_enabled.return_value = False + mock_is_stock_config_enabled.return_value = True + stock_ocio_path = nuke_ocio.get_ocio_config_path() + assert stock_ocio_path == "/this/ocio_configs/stock_config.ocio"