Skip to content
Draft
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: 10 additions & 2 deletions datadog_checks_dev/datadog_checks/dev/tooling/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,18 @@ def check_root():
return False


def repo_choice_from_root(root: str) -> str:
"""Derive ``repo_choice`` from a repo root path (same rule as ``--here``)."""
return os.path.basename(root).replace('integrations-', '')


def initialize_root(config, agent=False, core=False, extras=False, marketplace=False, here=False, **kwargs):
"""Initialize root directory based on config and options"""
if check_root():
root = get_root()
if root:
config['repo_choice'] = repo_choice_from_root(root)
config['repo_name'] = REPO_CHOICES.get(config['repo_choice'], config['repo_choice'])
return

repo_choice = (
Expand Down Expand Up @@ -197,8 +206,7 @@ def initialize_root(config, agent=False, core=False, extras=False, marketplace=F

root = os.getcwd()
if here:
# Repo choices use the integration repo name without the `integrations-` prefix
config['repo_choice'] = os.path.basename(root).replace('integrations-', '')
config['repo_choice'] = repo_choice_from_root(root)

config['repo_name'] = REPO_CHOICES.get(config['repo_choice'], config['repo_choice'])
set_root(root)
Expand Down
22 changes: 22 additions & 0 deletions datadog_checks_dev/tests/tooling/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from os.path import join

import mock
import pytest

from datadog_checks.dev.tooling.config import copy_default_config
from datadog_checks.dev.tooling.utils import (
Expand Down Expand Up @@ -87,6 +88,27 @@ def test_initialize_root_env_var(set_root, get_root):
set_root.assert_called_with(os.path.expanduser(ddev_env))


@pytest.mark.parametrize(
'root_path, expected_choice, expected_name',
[
('/fake/path/integrations-core', 'core', 'integrations-core'),
('/fake/path/integrations-extras', 'extras', 'integrations-extras'),
('/fake/path/marketplace', 'marketplace', 'marketplace'),
],
)
@mock.patch('datadog_checks.dev.tooling.utils.get_root')
@mock.patch('datadog_checks.dev.tooling.utils.set_root')
def test_initialize_root_sets_repo_when_root_already_set(set_root, get_root, root_path, expected_choice, expected_name):
get_root.return_value = root_path

config = copy_default_config()
initialize_root(config)

assert not set_root.called
assert config['repo_choice'] == expected_choice
assert config['repo_name'] == expected_name


@not_windows_ci
@mock.patch('datadog_checks.dev.tooling.utils.get_root')
@mock.patch('datadog_checks.dev.tooling.utils.set_root')
Expand Down
Loading