From c9d9a6eedbe2ce423220755595ce5c26853ef9e2 Mon Sep 17 00:00:00 2001 From: Catherine Lee Date: Mon, 6 Nov 2023 09:04:38 -0800 Subject: [PATCH] update --- .github/workflows/check-alerts.yml | 16 ++++--------- .github/workflows/torchci.yml | 10 ++++++++ .github/workflows/update-test-times.yml | 4 ---- .../workflows/update_test_file_ratings.yml | 23 ++++++++----------- torchci/pyproject.toml | 10 ++++++++ torchci/scripts/queue_alert.py | 7 +++++- torchci/scripts/rockset_utils.py | 3 +-- .../{ => td}/calculate_file_test_rating.py | 5 +--- .../scripts/{ => td}/get_merge_base_info.py | 9 ++++++-- .../td_heuristic_historical_edited_files.py | 2 +- .../{ => td}/td_heuristic_profiling.py | 2 +- .../scripts/{ => td}/td_rockset_analysis.py | 4 ++-- .../{utils_td_heuristics.py => td/utils.py} | 4 ++-- .../test_calculate_file_test_rating.py | 2 +- .../scripts/{ => test}/test_check_alerts.py | 8 +++---- .../scripts/{ => test}/test_queue_alert.py | 6 ++++- .../{ => test}/test_update_test_times.py | 3 +-- 17 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 torchci/pyproject.toml rename torchci/scripts/{ => td}/calculate_file_test_rating.py (98%) rename torchci/scripts/{ => td}/get_merge_base_info.py (95%) rename torchci/scripts/{ => td}/td_heuristic_historical_edited_files.py (97%) rename torchci/scripts/{ => td}/td_heuristic_profiling.py (95%) rename torchci/scripts/{ => td}/td_rockset_analysis.py (98%) rename torchci/scripts/{utils_td_heuristics.py => td/utils.py} (97%) rename torchci/scripts/{ => test}/test_calculate_file_test_rating.py (98%) rename torchci/scripts/{ => test}/test_check_alerts.py (98%) rename torchci/scripts/{ => test}/test_queue_alert.py (94%) rename torchci/scripts/{ => test}/test_update_test_times.py (98%) diff --git a/.github/workflows/check-alerts.yml b/.github/workflows/check-alerts.yml index 52b5acbbdd..494322f8a9 100644 --- a/.github/workflows/check-alerts.yml +++ b/.github/workflows/check-alerts.yml @@ -42,14 +42,10 @@ jobs: uses: actions/checkout@v3 - name: Install requests run: | - pip3 install requests setuptools - - name: Run tests - if: ${{ github.event_name == 'pull_request'}} - run: | - python3 torchci/scripts/test_check_alerts.py + pip3 install requests setuptools==61.2.0 - name: Check for alerts and creates issue run: | - python3 torchci/scripts/check_alerts.py + python3 -m torchci.scripts.check_alerts env: # NOTE: Should be a blank string for pull requests GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -64,14 +60,10 @@ jobs: uses: actions/checkout@v3 - name: Install requests run: | - pip3 install requests setuptools rockset==1.0.3 - - name: Run tests - if: ${{ github.event_name == 'pull_request'}} - run: | - python3 torchci/scripts/test_queue_alert.py + pip3 install requests setuptools==61.2.0 rockset==1.0.3 - name: Check for alerts and creates issue run: | - python3 torchci/scripts/queue_alert.py + python3 -m torchci.scripts.queue_alert env: # NOTE: Should be a blank string for pull requests GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/torchci.yml b/.github/workflows/torchci.yml index 9a8b236bcc..2d5bbaa955 100644 --- a/.github/workflows/torchci.yml +++ b/.github/workflows/torchci.yml @@ -27,3 +27,13 @@ jobs: - run: yarn node scripts/checkRockset.mjs env: ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }} + + python-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: | + pip3 install --upgrade pip + pip3 install setuptools==68.2.2 rockset==1.0.3 boto3==1.19.12 pytest==7.2.0 + pip3 install -e . + pytest scripts/test diff --git a/.github/workflows/update-test-times.yml b/.github/workflows/update-test-times.yml index 53f9aee677..5c4de12986 100644 --- a/.github/workflows/update-test-times.yml +++ b/.github/workflows/update-test-times.yml @@ -8,7 +8,6 @@ on: workflow_dispatch: pull_request: paths: - - "torchci/scripts/test_update_test_times.yml" - "torchci/scripts/update_test_times.py" - ".github/workflows/update-test-times.yml" @@ -26,9 +25,6 @@ jobs: pip3 install boto3==1.19.12 pip3 install rockset==1.0.3 - - name: Run tests - run: python3 scripts/test_update_test_times.py - - name: Update test times run: | python3 scripts/update_test_times.py diff --git a/.github/workflows/update_test_file_ratings.yml b/.github/workflows/update_test_file_ratings.yml index a8b17c6333..1f8041a371 100644 --- a/.github/workflows/update_test_file_ratings.yml +++ b/.github/workflows/update_test_file_ratings.yml @@ -4,11 +4,7 @@ on: pull_request: paths: - ".github/workflows/update_test_file_ratings.yml" - - "torchci/scripts/calculate_file_test_rating.py" - - "torchci/scripts/test_calculate_file_test_rating.py" - - "torchci/scripts/td_heuristic_historical_edited_files.py" - - "torchci/scripts/td_heuristic_profiling.py" - - "torchci/scripts/get_merge_base_info.py" + - "torchci/scripts/td/**" schedule: - cron: 5 11 * * * # At 11:05 UTC every day or about 4am PT @@ -34,24 +30,23 @@ jobs: - name: Install Dependencies run: | - pip3 install boto3==1.19.12 - pip3 install rockset==1.0.3 - - - name: Run tests - run: python3 test-infra/torchci/scripts/test_calculate_file_test_rating.py + pip3 install --upgrade pip + pip3 install boto3==1.19.12 rockset==1.0.3 + cd test-infra/torchci + pip3 install -e . - name: Get merge base info run: | - python3 test-infra/torchci/scripts/get_merge_base_info.py + python3 test-infra/torchci/scripts/td/get_merge_base_info.py env: ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }} - name: Generate file test ratings run: | - python3 test-infra/torchci/scripts/calculate_file_test_rating.py - python3 test-infra/torchci/scripts/td_heuristic_historical_edited_files.py + python3 test-infra/torchci/scripts/td/calculate_file_test_rating.py + python3 test-infra/torchci/scripts/td/td_heuristic_historical_edited_files.py # Do not run this one, it won't change - # python3 test-infra/torchci/scripts/td_heuristic_profiling.py + # python3 test-infra/torchci/scripts/td/td_heuristic_profiling.py env: ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }} diff --git a/torchci/pyproject.toml b/torchci/pyproject.toml new file mode 100644 index 0000000000..57f97ff325 --- /dev/null +++ b/torchci/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "torchci" +dynamic = ["version"] + +[build-system] +requires = ["setuptools==68.2.2"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.package-dir] +"torchci.scripts" = "scripts" diff --git a/torchci/scripts/queue_alert.py b/torchci/scripts/queue_alert.py index fe9324734e..1f41d37b84 100644 --- a/torchci/scripts/queue_alert.py +++ b/torchci/scripts/queue_alert.py @@ -7,8 +7,13 @@ import rockset # type: ignore[import] -from check_alerts import clear_alerts, create_issue, fetch_alerts, update_issue from setuptools import distutils # type: ignore[import] +from torchci.scripts.check_alerts import ( + clear_alerts, + create_issue, + fetch_alerts, + update_issue, +) REPO_ROOT = Path(__file__).resolve().parent.parent.parent diff --git a/torchci/scripts/rockset_utils.py b/torchci/scripts/rockset_utils.py index 3e9db1fb68..5b6ed91900 100644 --- a/torchci/scripts/rockset_utils.py +++ b/torchci/scripts/rockset_utils.py @@ -3,8 +3,7 @@ from typing import Any, Dict, List, Optional import rockset - -from utils import cache_json # type: ignore[import] +from torchci.scripts.utils import cache_json # type: ignore[import] @lru_cache diff --git a/torchci/scripts/calculate_file_test_rating.py b/torchci/scripts/td/calculate_file_test_rating.py similarity index 98% rename from torchci/scripts/calculate_file_test_rating.py rename to torchci/scripts/td/calculate_file_test_rating.py index d812bf2d42..e810aa4515 100644 --- a/torchci/scripts/calculate_file_test_rating.py +++ b/torchci/scripts/td/calculate_file_test_rating.py @@ -1,10 +1,7 @@ import json from collections import defaultdict -from pathlib import Path -from rockset_utils import query_rockset - -REPO_ROOT = Path(__file__).resolve().parent.parent.parent +from torchci.scripts.rockset_utils import query_rockset FAILED_TESTS_QUERY = """ SELECT diff --git a/torchci/scripts/get_merge_base_info.py b/torchci/scripts/td/get_merge_base_info.py similarity index 95% rename from torchci/scripts/get_merge_base_info.py rename to torchci/scripts/td/get_merge_base_info.py index a5705e7154..d971f0cb65 100644 --- a/torchci/scripts/get_merge_base_info.py +++ b/torchci/scripts/td/get_merge_base_info.py @@ -3,8 +3,13 @@ from pathlib import Path from typing import List -from rockset_utils import query_rockset, remove_from_rockset, upload_to_rockset -from utils_td_heuristics import list_past_year_shas, run_command +from torchci.scripts.rockset_utils import ( + query_rockset, + remove_from_rockset, + upload_to_rockset, +) +from torchci.scripts.td.utils import list_past_year_shas, run_command + REPO_ROOT = Path(__file__).resolve().parent.parent.parent diff --git a/torchci/scripts/td_heuristic_historical_edited_files.py b/torchci/scripts/td/td_heuristic_historical_edited_files.py similarity index 97% rename from torchci/scripts/td_heuristic_historical_edited_files.py rename to torchci/scripts/td/td_heuristic_historical_edited_files.py index 96dad907cd..b5184bcb73 100644 --- a/torchci/scripts/td_heuristic_historical_edited_files.py +++ b/torchci/scripts/td/td_heuristic_historical_edited_files.py @@ -2,7 +2,7 @@ from collections import defaultdict from typing import Dict -from utils_td_heuristics import ( +from torchci.scripts.td.utils import ( cache_json, evaluate, get_all_invoking_files, diff --git a/torchci/scripts/td_heuristic_profiling.py b/torchci/scripts/td/td_heuristic_profiling.py similarity index 95% rename from torchci/scripts/td_heuristic_profiling.py rename to torchci/scripts/td/td_heuristic_profiling.py index a22dcd786c..ac046bcfec 100644 --- a/torchci/scripts/td_heuristic_profiling.py +++ b/torchci/scripts/td/td_heuristic_profiling.py @@ -2,7 +2,7 @@ import requests -from utils_td_heuristics import ( +from torchci.scripts.td.utils import ( evaluate, get_filtered_failed_tests, get_merge_bases_dict, diff --git a/torchci/scripts/td_rockset_analysis.py b/torchci/scripts/td/td_rockset_analysis.py similarity index 98% rename from torchci/scripts/td_rockset_analysis.py rename to torchci/scripts/td/td_rockset_analysis.py index cbc5c683e9..218c31912f 100644 --- a/torchci/scripts/td_rockset_analysis.py +++ b/torchci/scripts/td/td_rockset_analysis.py @@ -7,9 +7,9 @@ import matplotlib.pyplot as plt -from rockset_utils import query_rockset +from torchci.scripts.rockset_utils import query_rockset -REPO_ROOT = Path(__file__).resolve().parent.parent.parent +REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent OUTPUT_FOLDER = REPO_ROOT / "_logs" / "td_analysis" QUERY = """ diff --git a/torchci/scripts/utils_td_heuristics.py b/torchci/scripts/td/utils.py similarity index 97% rename from torchci/scripts/utils_td_heuristics.py rename to torchci/scripts/td/utils.py index c00e436b8e..9626a23093 100644 --- a/torchci/scripts/utils_td_heuristics.py +++ b/torchci/scripts/td/utils.py @@ -6,8 +6,8 @@ import requests -from rockset_utils import query_rockset -from utils import cache_json, run_command +from torchci.scripts.rockset_utils import query_rockset +from torchci.scripts.utils import cache_json, run_command def list_past_year_shas(): diff --git a/torchci/scripts/test_calculate_file_test_rating.py b/torchci/scripts/test/test_calculate_file_test_rating.py similarity index 98% rename from torchci/scripts/test_calculate_file_test_rating.py rename to torchci/scripts/test/test_calculate_file_test_rating.py index 5064aad44c..b2e6ca6b28 100644 --- a/torchci/scripts/test_calculate_file_test_rating.py +++ b/torchci/scripts/test/test_calculate_file_test_rating.py @@ -1,6 +1,6 @@ from unittest import main, TestCase -from calculate_file_test_rating import ( +from torchci.scripts.td.calculate_file_test_rating import ( calculate_test_class_ratings, calculate_test_file_ratings, filter_tests, diff --git a/torchci/scripts/test_check_alerts.py b/torchci/scripts/test/test_check_alerts.py similarity index 98% rename from torchci/scripts/test_check_alerts.py rename to torchci/scripts/test/test_check_alerts.py index c0ecc2cbb6..73c41c3784 100644 --- a/torchci/scripts/test_check_alerts.py +++ b/torchci/scripts/test/test_check_alerts.py @@ -3,7 +3,7 @@ from unittest import main, TestCase from unittest.mock import patch -from check_alerts import ( +from torchci.scripts.check_alerts import ( fetch_alerts_filter, filter_job_names, gen_update_comment, @@ -183,9 +183,9 @@ def test_generate_no_flaky_tests_issue(self): issue = generate_no_flaky_tests_issue() self.assertListEqual(issue["labels"], ["no-flaky-tests-alert"]) - @patch("check_alerts.create_issue") - @patch("check_alerts.datetime") - @patch("check_alerts.get_num_issues_with_label") + @patch("torchci.scripts.check_alerts.create_issue") + @patch("torchci.scripts.check_alerts.datetime") + @patch("torchci.scripts.check_alerts.get_num_issues_with_label") def test_handle_flaky_tests_alert( self, mock_get_num_issues_with_label, mock_date, mock_create_issue ): diff --git a/torchci/scripts/test_queue_alert.py b/torchci/scripts/test/test_queue_alert.py similarity index 94% rename from torchci/scripts/test_queue_alert.py rename to torchci/scripts/test/test_queue_alert.py index c7a21329e5..19a21b4456 100644 --- a/torchci/scripts/test_queue_alert.py +++ b/torchci/scripts/test/test_queue_alert.py @@ -1,6 +1,10 @@ from unittest import main, TestCase -from queue_alert import filter_long_queues, gen_update_comment, QueueInfo +from torchci.scripts.queue_alert import ( + filter_long_queues, + gen_update_comment, + QueueInfo, +) class TestGitHubPR(TestCase): diff --git a/torchci/scripts/test_update_test_times.py b/torchci/scripts/test/test_update_test_times.py similarity index 98% rename from torchci/scripts/test_update_test_times.py rename to torchci/scripts/test/test_update_test_times.py index 062c9bbe71..2655d13c08 100644 --- a/torchci/scripts/test_update_test_times.py +++ b/torchci/scripts/test/test_update_test_times.py @@ -1,7 +1,6 @@ -import json import unittest -from update_test_times import gen_test_class_times, gen_test_file_times +from torchci.scripts.update_test_times import gen_test_class_times, gen_test_file_times class TestUpdateTestTimesFile(unittest.TestCase):