Skip to content

Commit e319813

Browse files
[primer] Parallelize primer workflow into package batches
1 parent d7baf5d commit e319813

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

.github/workflows/primer_comment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ jobs:
103103
. venv/bin/activate
104104
python tests/primer/__main__.py compare \
105105
--commit=${{ github.event.workflow_run.head_sha }} \
106-
--base-file=output_${{ steps.python.outputs.python-version }}_main.txt \
107-
--new-file=output_${{ steps.python.outputs.python-version }}_pr.txt
106+
--base-file=output_${{ steps.python.outputs.python-version }}_main_BATCHIDX.txt \
107+
--new-file=output_${{ steps.python.outputs.python-version }}_pr_BATCHIDX.txt \
108+
--batches=4
108109
- name: Post comment
109110
id: post-comment
110111
uses: actions/[email protected]

.github/workflows/primer_run_main.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ permissions:
2424

2525
jobs:
2626
run-primer:
27-
name: Run / ${{ matrix.python-version }}
27+
name: Run / ${{ matrix.python-version }} / batch index ${{ matrix.batchIdx }}
2828
runs-on: ubuntu-latest
29-
timeout-minutes: 120
29+
timeout-minutes: 45
3030
strategy:
3131
matrix:
3232
python-version: ["3.8", "3.11"]
33+
batches: [4]
34+
batchIdx: [0, 1, 2, 3]
3335
steps:
3436
- name: Check out code from GitHub
3537
uses: actions/[email protected]
@@ -91,7 +93,7 @@ jobs:
9193
run: |
9294
. venv/bin/activate
9395
pip install -e .
94-
python tests/primer/__main__.py run --type=main 2>warnings.txt
96+
python tests/primer/__main__.py run --type=main --batches=${{ matrix.batches }} --batchIdx=${{ matrix.batchIdx }} 2>warnings.txt
9597
WARNINGS=$(head -c 65000 < warnings.txt)
9698
if [[ $WARNINGS ]]
9799
then echo "::warning ::$WARNINGS"
@@ -102,4 +104,4 @@ jobs:
102104
name: primer_output
103105
path: >-
104106
tests/.pylint_primer_tests/output_${{ steps.python.outputs.python-version
105-
}}_main.txt
107+
}}_main_batch${{ matrix.batchIdx }}.txt

.github/workflows/primer_run_pr.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ permissions:
3333

3434
jobs:
3535
run-primer:
36-
name: Run / ${{ matrix.python-version }}
36+
name: Run / ${{ matrix.python-version }} / batch index ${{ matrix.batchIdx }}
3737
runs-on: ubuntu-latest
38-
timeout-minutes: 120
38+
timeout-minutes: 45
3939
strategy:
4040
matrix:
4141
python-version: ["3.8", "3.11"]
42+
batches: [4]
43+
batchIdx: [0, 1, 2, 3]
4244
steps:
4345
- name: Check out code from GitHub
4446
uses: actions/[email protected]
@@ -156,7 +158,7 @@ jobs:
156158
run: |
157159
. venv/bin/activate
158160
pip install -e .
159-
python tests/primer/__main__.py run --type=pr 2>warnings.txt
161+
python tests/primer/__main__.py run --type=pr --batches=${{ matrix.batches }} --batchIdx=${{ matrix.batchIdx }} 2>warnings.txt
160162
WARNINGS=$(head -c 65000 < warnings.txt)
161163
if [[ $WARNINGS ]]
162164
then echo "::warning ::$WARNINGS"
@@ -167,12 +169,12 @@ jobs:
167169
name: primer_output_pr
168170
path:
169171
tests/.pylint_primer_tests/output_${{ steps.python.outputs.python-version
170-
}}_pr.txt
172+
}}_pr_batch${{ matrix.batchIdx }}.txt
171173
- name: Upload output of 'main'
172174
uses: actions/[email protected]
173175
with:
174176
name: primer_output_main
175-
path: output_${{ steps.python.outputs.python-version }}_main.txt
177+
path: output_${{ steps.python.outputs.python-version }}_main_batch${{ matrix.batchIdx }}.txt
176178

177179
# Save PR number so we know which PR to comment on
178180
- name: Save PR number

pylint/testutils/_primer/primer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ def __init__(self, primer_directory: Path, json_path: Path) -> None:
5656
run_parser.add_argument(
5757
"--type", choices=["main", "pr"], required=True, help="Type of primer run."
5858
)
59+
run_parser.add_argument(
60+
"--batches",
61+
required=False,
62+
type=int,
63+
help="Number of batches",
64+
)
65+
run_parser.add_argument(
66+
"--batchIdx",
67+
required=False,
68+
type=int,
69+
help="Portion of primer packages to run.",
70+
)
5971

6072
# All arguments for the compare parser
6173
compare_parser = self._subparsers.add_parser("compare")
@@ -74,6 +86,12 @@ def __init__(self, primer_directory: Path, json_path: Path) -> None:
7486
required=True,
7587
help="Commit hash of the PR commit being checked.",
7688
)
89+
compare_parser.add_argument(
90+
"--batches",
91+
required=False,
92+
type=int,
93+
help="Number of batches (filepaths with the placeholder BATCHIDX will be numbered)",
94+
)
7795

7896
# Storing arguments
7997
self.config = self._argument_parser.parse_args()

pylint/testutils/_primer/primer_compare_command.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@
1818

1919
class CompareCommand(PrimerCommand):
2020
def run(self) -> None:
21-
main_data = self._load_json(self.config.base_file)
22-
pr_data = self._load_json(self.config.new_file)
21+
if self.config.batches is None:
22+
main_data = self._load_json(self.config.base_file)
23+
pr_data = self._load_json(self.config.new_file)
24+
else:
25+
main_data = {}
26+
pr_data = {}
27+
for idx in range(self.config.batches):
28+
main_data.update(
29+
self._load_json(self.config.base_file.replace("BATCHIDX", "batch" + str(idx)))
30+
)
31+
pr_data.update(
32+
self._load_json(self.config.new_file.replace("BATCHIDX", "batch" + str(idx)))
33+
)
34+
2335
missing_messages_data, new_messages_data = self._cross_reference(
2436
main_data, pr_data
2537
)

pylint/testutils/_primer/primer_run_command.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ class RunCommand(PrimerCommand):
3030
def run(self) -> None:
3131
packages: PackageMessages = {}
3232
fatal_msgs: list[Message] = []
33-
for package, data in self.packages.items():
33+
package_data_iter = (
34+
self.packages.items()
35+
if self.config.batches is None
36+
else list(self.packages.items())[self.config.batchIdx:: self.config.batches]
37+
)
38+
for package, data in package_data_iter:
3439
messages, p_fatal_msgs = self._lint_package(package, data)
3540
fatal_msgs += p_fatal_msgs
3641
local_commit = Repo(data.clone_directory).head.object.hexsha
3742
packages[package] = PackageData(commit=local_commit, messages=messages)
3843
path = (
3944
self.primer_directory
40-
/ f"output_{'.'.join(str(i) for i in sys.version_info[:3])}_{self.config.type}.txt"
45+
/ f"output_{'.'.join(str(i) for i in sys.version_info[:3])}_{self.config.type}_batch{self.config.batchIdx}.txt"
4146
)
4247
print(f"Writing result in {path}")
4348
with open(path, "w", encoding="utf-8") as f:

0 commit comments

Comments
 (0)