Skip to content

Commit 2525fd4

Browse files
fix: changed how graph_config.vcs_root is found
close #522
1 parent 2f8f7f3 commit 2525fd4

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/taskgraph/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import os
88
import sys
99
from dataclasses import dataclass
10+
from pathlib import Path
1011
from typing import Dict
1112

1213
from voluptuous import ALLOW_EXTRA, All, Any, Extra, Length, Optional, Required
1314

14-
from .util import path
1515
from .util.caches import CACHES
1616
from .util.python_path import find_object
1717
from .util.schema import Schema, optionally_keyed_by, validate_schema
18+
from .util.vcs import get_repository
1819
from .util.yaml import load_yaml
1920

2021
logger = logging.getLogger(__name__)
@@ -151,11 +152,10 @@ def register(self):
151152

152153
@property
153154
def vcs_root(self):
154-
if path.split(self.root_dir)[-1:] != ["taskcluster"]:
155-
raise Exception(
156-
"Not guessing path to vcs root. Graph config in non-standard location."
157-
)
158-
return os.path.dirname(self.root_dir)
155+
repo = get_repository(os.getcwd())
156+
path = Path(repo.path)
157+
158+
return path
159159

160160
@property
161161
def taskcluster_yml(self):

test/test_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
import os.path
6+
from pathlib import Path
7+
from unittest.mock import Mock, patch
68

79
import pytest
810

@@ -30,3 +32,19 @@ def test_graph_config_basic():
3032

3133
with pytest.raises(TypeError):
3234
graph_config["baz"] = 2
35+
36+
37+
def test_vcs_root_with_non_standard_dir():
38+
"""Test that property uses vcs_root correctly with a non standard path"""
39+
40+
path_repo = "/path/to/repo"
41+
mock_repo = Mock()
42+
mock_repo.path = path_repo
43+
44+
with patch("taskgraph.config.get_repository", return_value=mock_repo):
45+
graph_config = GraphConfig({"foo": "bar"}, "root/data")
46+
vcs_root = graph_config.vcs_root
47+
48+
expected_path = Path("/path/to/repo")
49+
50+
assert vcs_root == expected_path

0 commit comments

Comments
 (0)