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