From 5422f4f5cd972158e7b793b38715737dbbef4cfe Mon Sep 17 00:00:00 2001 From: ddog-nasirthomas Date: Fri, 8 May 2026 16:54:09 -0400 Subject: [PATCH 1/2] Always set repo_choice if check_root is true --- .../datadog_checks/dev/tooling/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/utils.py b/datadog_checks_dev/datadog_checks/dev/tooling/utils.py index c8c4a4d1d3be5..79d03daced62f 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/utils.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/utils.py @@ -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 = ( @@ -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) From 88a78096fd39cc8014a50773447bae24ab8e8f28 Mon Sep 17 00:00:00 2001 From: ddog-nasirthomas Date: Fri, 8 May 2026 16:55:34 -0400 Subject: [PATCH 2/2] Adding tests to confirm repo_choice is set --- .../tests/tooling/test_utils.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/datadog_checks_dev/tests/tooling/test_utils.py b/datadog_checks_dev/tests/tooling/test_utils.py index fbed01ae9aba0..ba2404ac6aefe 100644 --- a/datadog_checks_dev/tests/tooling/test_utils.py +++ b/datadog_checks_dev/tests/tooling/test_utils.py @@ -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 ( @@ -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')