diff options
author | David Bradford <david.bradford@mongodb.com> | 2021-04-21 17:32:53 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-23 17:16:03 +0000 |
commit | 1b9f63cdaf59922feec3b2c6d2c9017fefd595f1 (patch) | |
tree | ce60f70d8b1d49ef1371aacf165b0af80981d122 /buildscripts | |
parent | 1852f29b020ac45ca6a43f6d7c9ecd2d3333be54 (diff) | |
download | mongo-1b9f63cdaf59922feec3b2c6d2c9017fefd595f1.tar.gz |
SERVER-50595: Don't require evergreen.py for local lint runs
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/evergreen_burn_in_tests.py | 3 | ||||
-rw-r--r-- | buildscripts/linter/git.py | 5 | ||||
-rw-r--r-- | buildscripts/patch_builds/change_data.py | 21 | ||||
-rw-r--r-- | buildscripts/patch_builds/evg_change_data.py | 27 | ||||
-rw-r--r-- | buildscripts/selected_tests.py | 4 | ||||
-rw-r--r-- | buildscripts/tests/patch_builds/test_change_data.py | 17 | ||||
-rw-r--r-- | buildscripts/tests/patch_builds/test_evg_change_data.py | 32 |
7 files changed, 66 insertions, 43 deletions
diff --git a/buildscripts/evergreen_burn_in_tests.py b/buildscripts/evergreen_burn_in_tests.py index bdea8664635..14fd46672cc 100644 --- a/buildscripts/evergreen_burn_in_tests.py +++ b/buildscripts/evergreen_burn_in_tests.py @@ -17,7 +17,8 @@ from evergreen import RetryingEvergreenApi, EvergreenApi from buildscripts.burn_in_tests import RepeatConfig, BurnInExecutor, TaskInfo, FileChangeDetector, \ DEFAULT_REPO_LOCATIONS, BurnInOrchestrator from buildscripts.ciconfig.evergreen import parse_evergreen_file, EvergreenProjectConfig -from buildscripts.patch_builds.change_data import RevisionMap, generate_revision_map_from_manifest +from buildscripts.patch_builds.change_data import RevisionMap +from buildscripts.patch_builds.evg_change_data import generate_revision_map_from_manifest from buildscripts.patch_builds.task_generation import TimeoutInfo, resmoke_commands, \ validate_task_generation_limit from buildscripts.util.fileops import write_file diff --git a/buildscripts/linter/git.py b/buildscripts/linter/git.py index 83c45771c20..ef321620305 100644 --- a/buildscripts/linter/git.py +++ b/buildscripts/linter/git.py @@ -3,12 +3,12 @@ from __future__ import annotations import itertools import os +from pathlib import Path import re from typing import Callable, List from buildscripts.linter import git_base as _git from buildscripts import moduleconfig -from buildscripts.resmokelib.utils import globstar # Path to the modules in the mongodb source tree # Has to match the string in SConstruct @@ -147,7 +147,8 @@ class Repo(_git.Repository): def expand_file_string(glob_pattern): # type: (str) -> List[str] """Expand a string that represents a set of files.""" - return [os.path.abspath(f) for f in globstar.iglob(glob_pattern)] + current_path = Path(".") + return [str(glob_match.resolve()) for glob_match in current_path.glob(glob_pattern)] def get_files_to_check_working_tree(filter_function): diff --git a/buildscripts/patch_builds/change_data.py b/buildscripts/patch_builds/change_data.py index cd606333b09..44af0fca70b 100644 --- a/buildscripts/patch_builds/change_data.py +++ b/buildscripts/patch_builds/change_data.py @@ -5,7 +5,6 @@ from typing import Any, Dict, Iterable, Set, Optional, List import structlog from git import DiffIndex, Repo -from evergreen import EvergreenApi LOGGER = structlog.get_logger(__name__) @@ -36,26 +35,6 @@ def generate_revision_map(repos: List[Repo], revisions_data: Dict[str, str]) -> return {k: v for k, v in revision_map.items() if v} -def generate_revision_map_from_manifest(repos: List[Repo], task_id: str, - evg_api: EvergreenApi) -> RevisionMap: - """ - Generate a revision map for the given repositories using the revisions from the manifest. - - :param repos: Repositories to generate map for. - :param task_id: Id of evergreen task running. - :param evg_api: Evergreen API object. - :return: Map of repositories to revisions - """ - manifest = evg_api.manifest_for_task(task_id) - revisions_data = { - module_name: module.revision - for module_name, module in manifest.modules.items() - } - revisions_data["mongo"] = manifest.revision - - return generate_revision_map(repos, revisions_data) - - def _paths_for_iter(diff, iter_type): """ Get the set for all the files in the given diff for the specified type. diff --git a/buildscripts/patch_builds/evg_change_data.py b/buildscripts/patch_builds/evg_change_data.py new file mode 100644 index 00000000000..4506defa203 --- /dev/null +++ b/buildscripts/patch_builds/evg_change_data.py @@ -0,0 +1,27 @@ +"""Tools for detecting changes inside of Evergreen.""" +from typing import List + +from git import Repo +from evergreen import EvergreenApi + +from buildscripts.patch_builds.change_data import RevisionMap, generate_revision_map + + +def generate_revision_map_from_manifest(repos: List[Repo], task_id: str, + evg_api: EvergreenApi) -> RevisionMap: + """ + Generate a revision map for the given repositories using the revisions from the manifest. + + :param repos: Repositories to generate map for. + :param task_id: Id of evergreen task running. + :param evg_api: Evergreen API object. + :return: Map of repositories to revisions + """ + manifest = evg_api.manifest_for_task(task_id) + revisions_data = { + module_name: module.revision + for module_name, module in manifest.modules.items() + } + revisions_data["mongo"] = manifest.revision + + return generate_revision_map(repos, revisions_data) diff --git a/buildscripts/selected_tests.py b/buildscripts/selected_tests.py index c967f5cf31a..845c8a65f70 100644 --- a/buildscripts/selected_tests.py +++ b/buildscripts/selected_tests.py @@ -15,8 +15,8 @@ from shrub.v2 import ShrubProject, BuildVariant from evergreen.api import EvergreenApi, RetryingEvergreenApi # Get relative imports to work when the package is not installed on the PYTHONPATH. -from buildscripts.patch_builds.change_data import find_changed_files_in_repos, \ - generate_revision_map_from_manifest +from buildscripts.patch_builds.change_data import find_changed_files_in_repos +from buildscripts.patch_builds.evg_change_data import generate_revision_map_from_manifest if __name__ == "__main__" and __package__ is None: sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) diff --git a/buildscripts/tests/patch_builds/test_change_data.py b/buildscripts/tests/patch_builds/test_change_data.py index 531dea65569..88eb2522224 100644 --- a/buildscripts/tests/patch_builds/test_change_data.py +++ b/buildscripts/tests/patch_builds/test_change_data.py @@ -72,20 +72,3 @@ class TestGenerateRevisionMap(unittest.TestCase): self.assertEqual(revision_map[mock_repo_list[0].git_dir], revision_data["mongo"]) self.assertEqual(len(revision_map), 1) - - -class TestGenerateRevisionMapFromManifest(unittest.TestCase): - def test_map_can_be_created_from_evergreen_api(self): - mock_repo_list = [create_mock_repo(os.getcwd()), create_mock_repo("/path/to/enterprise")] - mongo_revision = "revision1234" - enterprise_revision = "revision5678" - mock_manifest = MagicMock(revision=mongo_revision, - modules={"enterprise": MagicMock(revision=enterprise_revision)}) - mock_evg_api = MagicMock() - mock_evg_api.manifest_for_task.return_value = mock_manifest - - revision_map = under_test.generate_revision_map_from_manifest(mock_repo_list, "task_id", - mock_evg_api) - - self.assertEqual(revision_map[mock_repo_list[0].git_dir], mongo_revision) - self.assertEqual(revision_map[mock_repo_list[1].git_dir], enterprise_revision) diff --git a/buildscripts/tests/patch_builds/test_evg_change_data.py b/buildscripts/tests/patch_builds/test_evg_change_data.py new file mode 100644 index 00000000000..c7ddcf9d1a3 --- /dev/null +++ b/buildscripts/tests/patch_builds/test_evg_change_data.py @@ -0,0 +1,32 @@ +"""Unit tests for buildscripts.patch_builds.evg_change_data.py.""" +from __future__ import absolute_import + +import os +import unittest + +from mock import MagicMock + +import buildscripts.patch_builds.evg_change_data as under_test + +# pylint: disable=missing-docstring + + +def create_mock_repo(working_dir=""): + return MagicMock(working_dir=working_dir) + + +class TestGenerateRevisionMapFromManifest(unittest.TestCase): + def test_map_can_be_created_from_evergreen_api(self): + mock_repo_list = [create_mock_repo(os.getcwd()), create_mock_repo("/path/to/enterprise")] + mongo_revision = "revision1234" + enterprise_revision = "revision5678" + mock_manifest = MagicMock(revision=mongo_revision, + modules={"enterprise": MagicMock(revision=enterprise_revision)}) + mock_evg_api = MagicMock() + mock_evg_api.manifest_for_task.return_value = mock_manifest + + revision_map = under_test.generate_revision_map_from_manifest(mock_repo_list, "task_id", + mock_evg_api) + + self.assertEqual(revision_map[mock_repo_list[0].git_dir], mongo_revision) + self.assertEqual(revision_map[mock_repo_list[1].git_dir], enterprise_revision) |