Skip to content

Commit 91095c0

Browse files
fix: removed exception for vcs root property (#729)
* 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 * Revert "fix: removed exception for vcs root property t" This reverts commit 5d9a528. * fix: changed how graph_config.vcs_root is found close #522
1 parent d2dee6a commit 91095c0

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
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):

src/taskgraph/parameters.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,7 @@ def load_parameters_file(
363363

364364
def parameters_loader(spec, strict=True, overrides=None):
365365
def get_parameters(graph_config):
366-
try:
367-
repo_root = graph_config.vcs_root
368-
except Exception:
369-
repo_root = None
366+
repo_root = graph_config.vcs_root
370367

371368
parameters = load_parameters_file(
372369
spec,

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)