Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/taskgraph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions src/taskgraph/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Loading