From 5d9a528f92a27c183a180fc8945067f0d02611ef Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Tue, 29 Jul 2025 14:37:02 -0400 Subject: [PATCH 1/3] fix: removed exception for vcs root property t Removing this exception should all for non-standard root directories to work. Closes #522. I am not sure exactly what this #522 is asking for, please correct me if interpretation was wrong --- src/taskgraph/config.py | 5 ----- src/taskgraph/parameters.py | 5 +---- test/test_config.py | 12 ++++++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/taskgraph/config.py b/src/taskgraph/config.py index 41954b9d1..50810c3e3 100644 --- a/src/taskgraph/config.py +++ b/src/taskgraph/config.py @@ -11,7 +11,6 @@ from voluptuous import ALLOW_EXTRA, All, Any, Extra, Length, Optional, Required -from .util import path from .util.caches import CACHES from .util.python_path import find_object from .util.schema import Schema, optionally_keyed_by, validate_schema @@ -151,10 +150,6 @@ def register(self): @property def vcs_root(self): - if path.split(self.root_dir)[-1:] != ["taskcluster"]: - raise Exception( - "Not guessing path to vcs root. Graph config in non-standard location." - ) return os.path.dirname(self.root_dir) @property diff --git a/src/taskgraph/parameters.py b/src/taskgraph/parameters.py index 1f8f640ae..d88a155b7 100644 --- a/src/taskgraph/parameters.py +++ b/src/taskgraph/parameters.py @@ -363,10 +363,7 @@ def load_parameters_file( def parameters_loader(spec, strict=True, overrides=None): def get_parameters(graph_config): - try: - repo_root = graph_config.vcs_root - except Exception: - repo_root = None + repo_root = graph_config.vcs_root parameters = load_parameters_file( spec, diff --git a/test/test_config.py b/test/test_config.py index 84e459f85..4bf02f640 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -30,3 +30,15 @@ def test_graph_config_basic(): with pytest.raises(TypeError): graph_config["baz"] = 2 + + +def test_vcs_root_property(): + """Test the vcs_root property returns the parent directory of root_dir without throwing an exception.""" + + # Test with a standard taskcluster directory structure + graph_config = GraphConfig({}, "/path/to/project/taskcluster") + assert graph_config.vcs_root == "/path/to/project" + + # Test with a different directory structure + graph_config = GraphConfig({}, "/path/to/custom/.taskgraph") + assert graph_config.vcs_root == "/path/to/custom" From 2f8f7f3f739759bc611748672fee6faaa5a144c0 Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Wed, 30 Jul 2025 11:02:10 -0400 Subject: [PATCH 2/3] Revert "fix: removed exception for vcs root property t" This reverts commit 5d9a528f92a27c183a180fc8945067f0d02611ef. --- src/taskgraph/config.py | 5 +++++ src/taskgraph/parameters.py | 5 ++++- test/test_config.py | 12 ------------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/taskgraph/config.py b/src/taskgraph/config.py index 50810c3e3..41954b9d1 100644 --- a/src/taskgraph/config.py +++ b/src/taskgraph/config.py @@ -11,6 +11,7 @@ from voluptuous import ALLOW_EXTRA, All, Any, Extra, Length, Optional, Required +from .util import path from .util.caches import CACHES from .util.python_path import find_object from .util.schema import Schema, optionally_keyed_by, validate_schema @@ -150,6 +151,10 @@ def register(self): @property def vcs_root(self): + if path.split(self.root_dir)[-1:] != ["taskcluster"]: + raise Exception( + "Not guessing path to vcs root. Graph config in non-standard location." + ) return os.path.dirname(self.root_dir) @property diff --git a/src/taskgraph/parameters.py b/src/taskgraph/parameters.py index d88a155b7..1f8f640ae 100644 --- a/src/taskgraph/parameters.py +++ b/src/taskgraph/parameters.py @@ -363,7 +363,10 @@ def load_parameters_file( def parameters_loader(spec, strict=True, overrides=None): def get_parameters(graph_config): - repo_root = graph_config.vcs_root + try: + repo_root = graph_config.vcs_root + except Exception: + repo_root = None parameters = load_parameters_file( spec, diff --git a/test/test_config.py b/test/test_config.py index 4bf02f640..84e459f85 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -30,15 +30,3 @@ def test_graph_config_basic(): with pytest.raises(TypeError): graph_config["baz"] = 2 - - -def test_vcs_root_property(): - """Test the vcs_root property returns the parent directory of root_dir without throwing an exception.""" - - # Test with a standard taskcluster directory structure - graph_config = GraphConfig({}, "/path/to/project/taskcluster") - assert graph_config.vcs_root == "/path/to/project" - - # Test with a different directory structure - graph_config = GraphConfig({}, "/path/to/custom/.taskgraph") - assert graph_config.vcs_root == "/path/to/custom" From 6e43a0e5f9fac35f8da608dc0580fc8fef4a1c61 Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Wed, 30 Jul 2025 13:42:09 -0400 Subject: [PATCH 3/3] fix: changed how graph_config.vcs_root is found close #522 --- src/taskgraph/config.py | 12 ++++++------ src/taskgraph/parameters.py | 5 +---- test/test_config.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/taskgraph/config.py b/src/taskgraph/config.py index 41954b9d1..c5ae48375 100644 --- a/src/taskgraph/config.py +++ b/src/taskgraph/config.py @@ -7,14 +7,15 @@ import os import sys from dataclasses import dataclass +from pathlib import Path from typing import Dict from voluptuous import ALLOW_EXTRA, All, Any, Extra, Length, Optional, Required -from .util import path from .util.caches import CACHES from .util.python_path import find_object from .util.schema import Schema, optionally_keyed_by, validate_schema +from .util.vcs import get_repository from .util.yaml import load_yaml logger = logging.getLogger(__name__) @@ -151,11 +152,10 @@ def register(self): @property def vcs_root(self): - if path.split(self.root_dir)[-1:] != ["taskcluster"]: - raise Exception( - "Not guessing path to vcs root. Graph config in non-standard location." - ) - return os.path.dirname(self.root_dir) + repo = get_repository(os.getcwd()) + path = Path(repo.path) + + return path @property def taskcluster_yml(self): diff --git a/src/taskgraph/parameters.py b/src/taskgraph/parameters.py index 1f8f640ae..d88a155b7 100644 --- a/src/taskgraph/parameters.py +++ b/src/taskgraph/parameters.py @@ -363,10 +363,7 @@ def load_parameters_file( def parameters_loader(spec, strict=True, overrides=None): def get_parameters(graph_config): - try: - repo_root = graph_config.vcs_root - except Exception: - repo_root = None + repo_root = graph_config.vcs_root parameters = load_parameters_file( spec, diff --git a/test/test_config.py b/test/test_config.py index 84e459f85..cbde9b3ff 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -3,6 +3,8 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import os.path +from pathlib import Path +from unittest.mock import Mock, patch import pytest @@ -30,3 +32,19 @@ def test_graph_config_basic(): with pytest.raises(TypeError): graph_config["baz"] = 2 + + +def test_vcs_root_with_non_standard_dir(): + """Test that property uses vcs_root correctly with a non standard path""" + + path_repo = "/path/to/repo" + mock_repo = Mock() + mock_repo.path = path_repo + + with patch("taskgraph.config.get_repository", return_value=mock_repo): + graph_config = GraphConfig({"foo": "bar"}, "root/data") + vcs_root = graph_config.vcs_root + + expected_path = Path("/path/to/repo") + + assert vcs_root == expected_path