Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE?] Move torchci pythons scripts to tools #4703

Merged
merged 4 commits into from
Nov 7, 2023
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
28 changes: 10 additions & 18 deletions .github/workflows/check-alerts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
pull_request:
paths:
- .github/workflows/check-alerts.yml
- torchci/scripts/check_alerts.py
- torchci/scripts/queue_alert.py
- tools/torchci/check_alerts.py
- tools/torchci/queue_alert.py
schedule:
# Every 5 minutes
- cron: "*/5 * * * *"
Expand Down Expand Up @@ -40,16 +40,12 @@ jobs:
steps:
- name: Checkout
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
- name: Install Dependencies
run: pip3 install requests setuptools==61.2.0
- name: Check for alerts and creates issue
run: |
python3 torchci/scripts/check_alerts.py
cd tools
python3 -m torchci.check_alerts
env:
# NOTE: Should be a blank string for pull requests
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -62,16 +58,12 @@ jobs:
steps:
- name: Checkout
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
- name: Install Dependencies
run: 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
cd tools
python3 -m torchci.queue_alert
env:
# NOTE: Should be a blank string for pull requests
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 17 additions & 4 deletions .github/workflows/torchci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ on:
pull_request:
paths:
- "torchci/**"
- "tools/torchci/**"
- ".github/workflows/torchci.yml"
push:
branches:
- main

defaults:
run:
working-directory: torchci

jobs:
test:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: torchci
steps:
- uses: actions/checkout@v3
- run: yarn install --frozen-lockfile
Expand All @@ -27,3 +27,16 @@ jobs:
- run: yarn node scripts/checkRockset.mjs
env:
ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }}

python-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools/torchci
steps:
- uses: actions/checkout@v3
- run: |
pip3 install --upgrade pip
pip3 install -r requirements.txt
pip3 install -e .
pytest tests
18 changes: 6 additions & 12 deletions .github/workflows/update-test-times.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ on:
workflow_dispatch:
pull_request:
paths:
- "torchci/scripts/test_update_test_times.yml"
- "torchci/scripts/update_test_times.py"
- "tools/torchci/update_test_times.py"
- ".github/workflows/update-test-times.yml"

defaults:
run:
working-directory: torchci
working-directory: tools
jobs:
update-test-time-stats:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: |
pip3 install boto3==1.19.12
pip3 install rockset==1.0.3

- name: Run tests
run: python3 scripts/test_update_test_times.py
run: pip3 install boto3==1.19.12 rockset==1.0.3

- name: Update test times
run: |
python3 scripts/update_test_times.py
python3 -m torchci.update_test_times
env:
ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }}

Expand All @@ -41,7 +35,7 @@ jobs:
env:
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
with:
source_file: 'torchci/test-times.json'
source_file: 'tools/test-times.json'
destination_repo: 'pytorch/test-infra'
destination_folder: 'stats'
destination_branch: generated-stats
Expand All @@ -55,7 +49,7 @@ jobs:
env:
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
with:
source_file: 'torchci/test-class-times.json'
source_file: 'tools/test-class-times.json'
destination_repo: 'pytorch/test-infra'
destination_folder: 'stats'
destination_branch: generated-stats
Expand Down
23 changes: 9 additions & 14 deletions .github/workflows/update_test_file_ratings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
- "tools/torchci/td"
schedule:
- cron: 5 11 * * * # At 11:05 UTC every day or about 4am PT

Expand All @@ -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/tools/torchci
pip3 install -e .

- name: Get merge base info
run: |
python3 test-infra/torchci/scripts/get_merge_base_info.py
python3 test-infra/tools/torchci/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/tools/torchci/td/calculate_file_test_rating.py
python3 test-infra/tools/torchci/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/tools/torchci/td/td_heuristic_profiling.py

env:
ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ init_command = [
[[linter]]
code = 'UFMT'
include_patterns = [
'torchci/**/*.py',
'tools/torchci/**/*.py',
]
command = [
'python3',
Expand Down
10 changes: 10 additions & 0 deletions tools/torchci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This is meant to contain all the random python scripts we make for things like
TD, alerting, revert tracking, etc.

It was originally located in torchci/scripts but moved to here to separate the
python "packaging" from the javascript/typescript.

To run these files without needing to modify `sys.path` in each file, either
1. Run `pip install -e .` from within `tools/torchci`. Run python files as normal, from anywhere.
2. Add to your `PYTHONPATH` env var via `export PYTHONPATH="${PYTHONPATH}:<repo root>/tools"`. Run python files as normal, from anywhere.
3. Run every file as a module from within `tools`, ex `cd tools && python -m torchci.td.td_rockset_analysis`.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions tools/torchci/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" = "../torchci"
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

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.check_alerts import clear_alerts, create_issue, fetch_alerts, update_issue

REPO_ROOT = Path(__file__).resolve().parent.parent.parent

Expand Down
5 changes: 5 additions & 0 deletions tools/torchci/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setuptools==61.2.0
requests
rockset==1.0.3
boto3==1.19.12
pytest==7.2.0
2 changes: 1 addition & 1 deletion torchci/scripts/reverts.py → tools/torchci/reverts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Dict, List, Optional, Tuple

from rockset import RocksetClient # type: ignore[import]
from torchci.scripts.github_analyze import GitCommit, GitRepo # type: ignore[import]
from torchci.github_analyze import GitCommit, GitRepo # type: ignore[import]

# Should match the contents produced by trymerge on revert
RE_REVERT_COMMIT_BODY = r"Reverted .* on behalf of .* due to .* \(\[comment\]\((.*)\)\)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Any, Dict, List, Optional

import rockset

from utils import cache_json # type: ignore[import]
from torchci.utils import cache_json # type: ignore[import]


@lru_cache
Expand Down
Original file line number Diff line number Diff line change
@@ -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.rockset_utils import query_rockset

FAILED_TESTS_QUERY = """
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
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.rockset_utils import query_rockset, remove_from_rockset, upload_to_rockset
from torchci.td.utils import list_past_year_shas, run_command

REPO_ROOT = Path(__file__).resolve().parent.parent.parent

REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent

FAILED_TEST_SHAS_QUERY = """
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict
from typing import Dict

from utils_td_heuristics import (
from torchci.td.utils import (
cache_json,
evaluate,
get_all_invoking_files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import requests

from utils_td_heuristics import (
evaluate,
get_filtered_failed_tests,
get_merge_bases_dict,
)
from torchci.td.utils import evaluate, get_filtered_failed_tests, get_merge_bases_dict


def get_profiling_dict():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import matplotlib.pyplot as plt

from rockset_utils import query_rockset
from torchci.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 = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import requests

from rockset_utils import query_rockset
from utils import cache_json, run_command
from torchci.rockset_utils import query_rockset
from torchci.utils import cache_json, run_command


def list_past_year_shas():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import main, TestCase

from calculate_file_test_rating import (
from torchci.td.calculate_file_test_rating import (
calculate_test_class_ratings,
calculate_test_file_ratings,
filter_tests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import main, TestCase
from unittest.mock import patch

from check_alerts import (
from torchci.check_alerts import (
fetch_alerts_filter,
filter_job_names,
gen_update_comment,
Expand Down Expand Up @@ -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.check_alerts.create_issue")
@patch("torchci.check_alerts.datetime")
@patch("torchci.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
):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import main, TestCase

from queue_alert import filter_long_queues, gen_update_comment, QueueInfo
from torchci.queue_alert import filter_long_queues, gen_update_comment, QueueInfo


class TestGitHubPR(TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import unittest

from update_test_times import gen_test_class_times, gen_test_file_times
from torchci.update_test_times import gen_test_class_times, gen_test_file_times


class TestUpdateTestTimesFile(unittest.TestCase):
Expand Down
File renamed without changes.