From d896ad88e445fe4d8e28c9a24e508510960c5d38 Mon Sep 17 00:00:00 2001 From: Hector Clement Date: Wed, 19 Mar 2025 15:47:15 +0100 Subject: [PATCH 1/7] Use self._repr_def to create the parent template instead of self.definition --- python/tank/template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tank/template.py b/python/tank/template.py index 77c135fc57..ba31e12f6d 100644 --- a/python/tank/template.py +++ b/python/tank/template.py @@ -566,8 +566,8 @@ def parent(self): :returns: :class:`Template` """ - parent_definition = os.path.dirname(self.definition) - if parent_definition: + parent_definition = os.path.dirname(self._repr_def) + if parent_definition and parent_definition != "/": return TemplatePath( parent_definition, self.keys, From 6021bbd6ea3025909833406183c56e2161899607 Mon Sep 17 00:00:00 2001 From: Hector Clement Date: Wed, 19 Mar 2025 15:47:34 +0100 Subject: [PATCH 2/7] Add test for TemplatePath parent with optional key --- tests/core_tests/test_templatepath.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/core_tests/test_templatepath.py b/tests/core_tests/test_templatepath.py index ef7625bb9e..1e9ffb3b97 100644 --- a/tests/core_tests/test_templatepath.py +++ b/tests/core_tests/test_templatepath.py @@ -1184,3 +1184,16 @@ def test_aliased_key(self): template = TemplatePath(definition, keys, root_path=self.project_root) result = template.parent self.assertEqual("{new_name}", result.definition) + + def test_parent_with_optional(self): + definition = "shots/{Sequence}[-{seq_num}]/{Shot}/{Step}/work" + parent_expected_definitions = [ + "shots/{Sequence}-{seq_num}/{Shot}/{Step}", + "shots/{Sequence}/{Shot}/{Step}", + ] + parent_expected__repr_def = os.path.dirname(definition) + + template = TemplatePath(definition, self.keys, root_path=self.project_root) + parent = template.parent + self.assertEqual(parent_expected_definitions, parent._definitions) + self.assertEqual(parent_expected__repr_def, parent._repr_def) From 0ae2f936edc16b832d7842dda28da76be538307c Mon Sep 17 00:00:00 2001 From: Hector Clement Date: Fri, 21 Mar 2025 17:03:10 +0100 Subject: [PATCH 3/7] Add _dirname method to TemplatePath for improved directory handling --- python/tank/template.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/tank/template.py b/python/tank/template.py index ba31e12f6d..eba299a006 100644 --- a/python/tank/template.py +++ b/python/tank/template.py @@ -557,6 +557,17 @@ def root_path(self): """ return self._prefix + def _dirname(self): + """ + Returns the directory part of the template. + + :returns: String + """ + dirname, basename = os.path.split(self._repr_def) + if "[" in basename and "]" not in basename: + return dirname.split("[")[0] + return dirname + @property def parent(self): """ @@ -566,7 +577,7 @@ def parent(self): :returns: :class:`Template` """ - parent_definition = os.path.dirname(self._repr_def) + parent_definition = self._dirname() if parent_definition and parent_definition != "/": return TemplatePath( parent_definition, From ed752fc1aa88ca1bcec14a715f9da80b38077740 Mon Sep 17 00:00:00 2001 From: Hector Clement Date: Fri, 21 Mar 2025 17:03:19 +0100 Subject: [PATCH 4/7] Add tests for dirname method in TemplatePath to validate directory extraction --- tests/core_tests/test_templatepath.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/core_tests/test_templatepath.py b/tests/core_tests/test_templatepath.py index 1e9ffb3b97..a1f164c659 100644 --- a/tests/core_tests/test_templatepath.py +++ b/tests/core_tests/test_templatepath.py @@ -1197,3 +1197,29 @@ def test_parent_with_optional(self): parent = template.parent self.assertEqual(parent_expected_definitions, parent._definitions) self.assertEqual(parent_expected__repr_def, parent._repr_def) + +class TestDirname(TestTemplatePath): + def test_dirname_with_word(self): + definition = "shots/{Sequence}/{Shot}/{Step}/work" + template = TemplatePath(definition, self.keys, root_path=self.project_root) + self.assertEqual("shots/{Sequence}/{Shot}/{Step}", template.dirname) + + def test_dirname_with_key(self): + definition = "shots/{Sequence}/{Shot}/{Step}" + template = TemplatePath(definition, self.keys, root_path=self.project_root) + self.assertEqual("shots/{Sequence}/{Shot}", template.dirname) + + def test_dirname_with_optional(self): + definition = "shots/{Sequence}/{Shot}[/{Step}]" + template = TemplatePath(definition, {}, root_path=self.project_root) + self.assertEqual("shots/{Sequence}/{Shot}", template.dirname) + + def test_dirname_with_optional_word_and_key(self): + definition = "shots/{Sequence}/{Shot}/[abc_{Step}]" + template = TemplatePath(definition, {}, root_path=self.project_root) + self.assertEqual("", template.dirname) + + def test_dirname_with_optional_key_and_key(self): + definition = "shots/{Sequence}/[{Shot}]-{Step}" + template = TemplatePath(definition, {}, root_path=self.project_root) + self.assertEqual("shots/{Sequence}", template.dirname) From c04d8617b2316f71d98fbc7582a9421e4062acb9 Mon Sep 17 00:00:00 2001 From: Hector Clement Date: Fri, 21 Mar 2025 17:26:36 +0100 Subject: [PATCH 5/7] Fix formatting in test_templatepath.py for consistency --- tests/core_tests/test_templatepath.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core_tests/test_templatepath.py b/tests/core_tests/test_templatepath.py index a1f164c659..7eb6f91281 100644 --- a/tests/core_tests/test_templatepath.py +++ b/tests/core_tests/test_templatepath.py @@ -1198,6 +1198,7 @@ def test_parent_with_optional(self): self.assertEqual(parent_expected_definitions, parent._definitions) self.assertEqual(parent_expected__repr_def, parent._repr_def) + class TestDirname(TestTemplatePath): def test_dirname_with_word(self): definition = "shots/{Sequence}/{Shot}/{Step}/work" @@ -1215,7 +1216,7 @@ def test_dirname_with_optional(self): self.assertEqual("shots/{Sequence}/{Shot}", template.dirname) def test_dirname_with_optional_word_and_key(self): - definition = "shots/{Sequence}/{Shot}/[abc_{Step}]" + definition = "shots/{Sequence}/{Shot}/[abc_{Step}]" template = TemplatePath(definition, {}, root_path=self.project_root) self.assertEqual("", template.dirname) From 3163f52d7f39e012d1a4e392bd0f960c10e3eda7 Mon Sep 17 00:00:00 2001 From: Hector Clement Date: Tue, 25 Mar 2025 12:42:58 +0100 Subject: [PATCH 6/7] Fix dirname output in test_dirname_with_optional_word_and_key to match expected value --- tests/core_tests/test_templatepath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_tests/test_templatepath.py b/tests/core_tests/test_templatepath.py index 7eb6f91281..d9ea70df77 100644 --- a/tests/core_tests/test_templatepath.py +++ b/tests/core_tests/test_templatepath.py @@ -1218,7 +1218,7 @@ def test_dirname_with_optional(self): def test_dirname_with_optional_word_and_key(self): definition = "shots/{Sequence}/{Shot}/[abc_{Step}]" template = TemplatePath(definition, {}, root_path=self.project_root) - self.assertEqual("", template.dirname) + self.assertEqual("shots/{Sequence}/{Shot}", template.dirname) def test_dirname_with_optional_key_and_key(self): definition = "shots/{Sequence}/[{Shot}]-{Step}" From 1bf7819418209819a8c4275b15a084cb5f118847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hector?= Date: Tue, 25 Mar 2025 19:37:32 +0100 Subject: [PATCH 7/7] Update azure-pipelines.yml --- azure-pipelines.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9fb3e0d6e3..9c57d2efac 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -38,6 +38,11 @@ variables: - group: deploy-secrets jobs: +- template: pip-install-packages.yml@templates + parameters: + packages: + - mock + - template: build-pipeline.yml@templates parameters: # After the tests have run, run the integration tests.