Skip to content

Commit

Permalink
feat: Handle different OCIO configs in adapter
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Banaszak <[email protected]>
  • Loading branch information
StevenBanaszak committed Oct 7, 2024
1 parent 0eb87cb commit 6c8ec85
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 63 deletions.
71 changes: 65 additions & 6 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]: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\<username>\deadline-clients\deadline-cloud` to install the AWS Deadline Cloud Client Library in edit mode.
4. Run `.\python -m pip install -e C:\Users\<username>\deadline-clients\deadline-cloud-for-nuke` to install the Nuke Submitter in edit mode.
5. Run `set NUKE_PATH=C:\Users\<username>\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<version>.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\<username>\deadline-clients\deadline-cloud
```

Mac (update the path as needed):
```
./python -m pip install -e /Users/<username>/dev/deadline-clients/deadline-cloud
```
1. Run `.\python -m pip install -e C:\Users\<username>\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\<username>\deadline-clients\deadline-cloud-for-nuke
```

Mac (update the path as needed):
```
./python -m pip install -e /Users/<username>/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\<username>\deadline-clients\deadline-cloud-for-nuke\src\deadline\nuke_submitter:C:\Users\<username>\deadline-clients\deadline-cloud-for-nuke\src
```

Mac (update the paths as needed):
```
export NUKE_PATH=/Users/<username>/dev/deadline-clients/deadline-cloud-for-nuke/src/deadline/nuke_submitter:/Users/<username>/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<version>.exe
```

Mac:
```
./Nuke<version>
```

## Application Interface Adaptor Development Workflow

Expand Down
2 changes: 1 addition & 1 deletion src/deadline/nuke_adaptor/NukeClient/nuke_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 1 addition & 14 deletions src/deadline/nuke_submitter/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions src/deadline/nuke_submitter/deadline_submitter_for_nuke.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions src/deadline/nuke_util/ocio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
39 changes: 0 additions & 39 deletions test/unit/deadline_submitter_for_nuke/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
get_node_file_knob_paths,
get_node_filenames,
get_scene_asset_references,
get_ocio_config_path,
)


Expand Down Expand Up @@ -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(
Expand Down
38 changes: 38 additions & 0 deletions test/unit/nuke_util/test_ocio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6c8ec85

Please sign in to comment.