Skip to content

Commit

Permalink
refactor: Update to match some improvements in the Maya submitter
Browse files Browse the repository at this point in the history
* Cleanup to hatch_version_hook.py
* Change the job bundle test runner to match the refactoring done in
  Maya, including placing the scene file in a scene subdirectory and
  separating the Nuke-specific parts into a set of interface functions
  that we can turn into a class in a follow-up refactor.

Signed-off-by: Mark Wiebe <markw@amazon.com>
  • Loading branch information
mwiebe committed Sep 7, 2023
1 parent 4e273af commit 80812f8
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 216 deletions.
47 changes: 47 additions & 0 deletions hatch_custom_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
import os
import shutil

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from typing import Any


class HatchCustomBuildHook(BuildHookInterface):
"""
This class implements Hatch's [custom build hook] (https://hatch.pypa.io/1.6/plugins/build-hook/custom/)
for a copy_version_py operation that copies the _version.py file generated by the hatch-vcs build hook into
specified destination directories. See the `[[tool.hatch.build.hooks.custom]]` section in `pyproject.toml`.
"""

def _validate_config(self):
if sorted(self.config) != ["copy_version_py", "path"] or list(
self.config["copy_version_py"]
) != ["destinations"]:
raise RuntimeError(
"Configuration of the custom build hook must be like { 'copy_version_py': {'destinations': ['path1', ...]}}."
+ f" Received:\n{self.config}"
)

def initialize(self, version: str, build_data: dict[str, Any]) -> None:
self._validate_config()

for destination in self.config["copy_version_py"]["destinations"]:
print(f"Copying _version.py to {destination}")
shutil.copy(
os.path.join(self.root, "_version.py"),
os.path.join(self.root, destination),
)

def clean(self, versions: list[str]) -> None:
self._validate_config()

cleaned_count = 0
for destination in self.config["copy_version_py"]["destinations"]:
print(f"Cleaning _version.py from {destination}")
clean_path = os.path.join(self.root, destination, "_version.py")
try:
os.remove(clean_path)
cleaned_count += 1
except FileNotFoundError:
pass
print(f"Cleaned {cleaned_count} items")
160 changes: 0 additions & 160 deletions hatch_version_hook.py

This file was deleted.

9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ version_scheme = "post-release"
version-file = "_version.py"

[tool.hatch.build.hooks.custom]
path = "hatch_version_hook.py"
path = "hatch_custom_hook.py"

[[tool.hatch.build.hooks.custom.copy_map]]
sources = [
"_version.py",
]
[tool.hatch.build.hooks.custom.copy_version_py]
destinations = [
"src/deadline/nuke_adaptor",
"src/deadline/nuke_submitter",
Expand All @@ -50,7 +47,7 @@ destinations = [
[tool.hatch.build.targets.sdist]
include = [
"src/*",
"hatch_version_hook.py",
"hatch_custom_hook.py",
]

[tool.hatch.build.targets.wheel]
Expand Down
4 changes: 2 additions & 2 deletions src/deadline/nuke_submitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from ._logging import get_logger
from ._version import __version__
from .deadline_submitter_for_nuke import show_nuke_render_submitter_noargs
from .job_bundle_output_test_runner import run_nuke_render_submitter_job_bundle_output_test
from .job_bundle_output_test_runner import run_render_submitter_job_bundle_output_test

logger = get_logger("deadline")

__all__ = [
"__version__",
"logger",
"show_nuke_render_submitter_noargs",
"run_nuke_render_submitter_job_bundle_output_test",
"run_render_submitter_job_bundle_output_test",
]
Loading

0 comments on commit 80812f8

Please sign in to comment.