Skip to content

Commit a1ae72c

Browse files
committed
Second steps
1 parent a010380 commit a1ae72c

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.github/workflows/primer.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Primer
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
primer-run:
11+
name: Run
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out code from GitHub
15+
uses: actions/[email protected]
16+
with:
17+
fetch-depth: 2
18+
- name: Set up Python 3.10
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: "3.10"
22+
- name: Install dependencies
23+
run: pip install -U -r requirements-test.txt
24+
- name: Run primer
25+
run: python pydocstringformatter/testutils/primer.py
26+
- name: Post comment
27+
id: post-comment
28+
uses: actions/github-script@v3
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
script: |
32+
const fs = require('fs')
33+
const data = fs.readFileSync('.pydocstringformatter_primer_tests/fulldiff.txt', { encoding: 'utf8' })
34+
console.log("Diff from primer:")
35+
console.log(data)
36+
let body
37+
if (data.trim()) {
38+
body = 'Diff from the primer, showing the effect of this PR on the pylint source code:\n' + data
39+
} else {
40+
body = 'According to the primer, this change has no effect on the checked pylint source code. 🤖🎉'
41+
}
42+
await github.issues.createComment({
43+
issue_number: ${{ github.event.pull_request.number }},
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
body
47+
})
48+
- name: Hide old comments
49+
# Taken from mypy primer
50+
# v0.3.0
51+
uses: kanga333/comment-hider@bbdf5b562fbec24e6f60572d8f712017428b92e0
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
leave_visible: 1
55+
issue_number: ${{ steps.post-comment.outputs.result }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import subprocess
2+
import sys
3+
from pathlib import Path
4+
from typing import List
5+
6+
from pydocstringformatter.testutils.primer.const import PRIMER_DIRECTORY_PATH
7+
from pydocstringformatter.testutils.primer.packages import PACKAGES
8+
9+
10+
def _fix_diff(output: str) -> str:
11+
"""Make the diff a lil' prettier."""
12+
new_output: List[str] = []
13+
for index, line in enumerate(output.splitlines()):
14+
if line.startswith("--- "):
15+
if index:
16+
new_output.append("```\n")
17+
new_output.append(
18+
line.replace(
19+
"--- .pydocstringformatter_primer_tests/PyCQA/pylint/",
20+
"https://github.com/PyCQA/pylint/blob/main/",
21+
)
22+
)
23+
new_output.append("```diff")
24+
new_output.append(line)
25+
26+
return "\n".join(new_output)
27+
28+
29+
def _run_primer() -> None:
30+
"""Run the primer test."""
31+
for package in PACKAGES.values():
32+
package.lazy_clone()
33+
34+
for package in PACKAGES.values():
35+
# Run the program
36+
process = subprocess.run(
37+
[sys.executable, "-m", "pydocstringformatter"] + package.paths_to_lint,
38+
cwd=Path(__file__).parent.parent.parent,
39+
capture_output=True,
40+
text=True,
41+
check=False,
42+
)
43+
44+
# Write file
45+
46+
with open(PRIMER_DIRECTORY_PATH / "fulldiff.txt", "w", encoding="utf-8") as file:
47+
output = _fix_diff(process.stdout)
48+
file.write(output)
49+
50+
51+
if __name__ == "__main__":
52+
_run_primer()

0 commit comments

Comments
 (0)