Skip to content

Commit b53d9d4

Browse files
committed
Add more CI
1 parent 29c1ab6 commit b53d9d4

File tree

4 files changed

+151
-4
lines changed

4 files changed

+151
-4
lines changed

.github/actionlint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Configuration for the actionlint tool, which we run via pre-commit
2+
# to verify the correctness of the syntax in our GitHub Actions workflows.
3+
4+
self-hosted-runner:
5+
# Various runners we use that aren't recognized out-of-the-box by actionlint:
6+
labels:
7+
- depot-ubuntu-22.04-32
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Script that attempts to invoke docstring-adder on all third-party typeshed stubs."""
2+
3+
import argparse
4+
import subprocess
5+
import tempfile
6+
from pathlib import Path
7+
8+
9+
def add_docstrings(typeshed_dir: Path, docstring_adder_dir: Path) -> None:
10+
"""Add docstrings to third-party typeshed stubs."""
11+
12+
for path in (typeshed_dir / "stubs").iterdir():
13+
with tempfile.TemporaryDirectory() as td:
14+
venv_dir = f"{td}-venv"
15+
subprocess.run(["uv", "venv", "--python", "3.13", venv_dir], check=True)
16+
17+
# seems to fail with an internal assertion when you try to import it...?
18+
if path.name == "keyboard":
19+
continue
20+
21+
try:
22+
subprocess.run(
23+
[
24+
"uvx",
25+
"--python",
26+
f"{venv_dir}/bin/python",
27+
"--from",
28+
docstring_adder_dir,
29+
"add-docstrings",
30+
"--typeshed-packages",
31+
path,
32+
],
33+
check=True,
34+
)
35+
except subprocess.CalledProcessError as e:
36+
if e.returncode == 10:
37+
print(f"\nFailed to install runtime package for `{path.name}\n`")
38+
continue
39+
else:
40+
raise
41+
42+
43+
if __name__ == "__main__":
44+
45+
def absolute_path(path: str) -> Path:
46+
"""Convert a string path to an absolute Path."""
47+
return Path(path).absolute()
48+
49+
parser = argparse.ArgumentParser(__doc__)
50+
parser.add_argument(
51+
"--typeshed-dir",
52+
type=absolute_path,
53+
help="Path to the typeshed directory.",
54+
required=True,
55+
)
56+
parser.add_argument(
57+
"--docstring-adder-dir",
58+
type=absolute_path,
59+
help="Path to docstring-adder.",
60+
required=True,
61+
)
62+
args = parser.parse_args()
63+
add_docstrings(
64+
typeshed_dir=args.typeshed_dir, docstring_adder_dir=args.docstring_adder_dir
65+
)

.github/workflows/check.yaml

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- main
77
pull_request:
88
workflow_dispatch:
9+
schedule:
10+
- cron: "0 12 * * *"
911

1012
permissions:
1113
contents: read
@@ -14,14 +16,15 @@ env:
1416
FORCE_COLOR: 1 # Request colored output from CLI tools supporting it
1517
CLICOLOR_FORCE: 1 # recognized by uv
1618
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
DEFAULT_PYTHON_VERSION: "3.13" # Default Python version for uvx
1720

1821
concurrency:
1922
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
2023
cancel-in-progress: true
2124

2225
jobs:
23-
check:
24-
name: Check
26+
stdlib:
27+
name: Check typeshed stdlib
2528
runs-on: ${{ matrix.platform }}
2629
strategy:
2730
fail-fast: false
@@ -39,7 +42,7 @@ jobs:
3942
- name: Check a basic run doesn't fail
4043
run: uvx --python=${{ matrix.python-version }} --force-reinstall --from=./docstring-adder add-docstrings --stdlib-path ./typeshed/stdlib
4144
- name: Check typeshed's mypy_test.py passes
42-
run: uv run --directory=typeshed --no-project --python=3.13 --with-requirements=requirements-tests.txt python tests/mypy_test.py stdlib -p "${{ matrix.python-version }}"
45+
run: uv run --directory=typeshed --no-project --python="${DEFAULT_PYTHON_VERSION}" --with-requirements=requirements-tests.txt python tests/mypy_test.py stdlib -p "${{ matrix.python-version }}"
4346
- name: Check running it again doesn't produce any changes
4447
# Some weird thing with distutils means that it does actually add docstrings
4548
# when run the second time that it didn't add when run the first time.
@@ -51,10 +54,55 @@ jobs:
5154
cd typeshed
5255
git config --global user.email "you@example.com"
5356
git config --global user.name "Your Name"
57+
test -n "$(git status --porcelain)"
5458
git commit -am "."
5559
uvx --python=${{ matrix.python-version }} --force-reinstall --from=../docstring-adder add-docstrings --stdlib-path ./stdlib
5660
test -z "$(git status --porcelain)"
5761
62+
typeshed-third-party:
63+
name: Check typeshed third-party stubs
64+
runs-on: depot-ubuntu-22.04-32
65+
steps:
66+
- uses: actions/checkout@v4
67+
with:
68+
path: docstring-adder
69+
persist-credentials: false
70+
- name: Checkout typeshed
71+
run: git clone --depth=1 https://github.com/python/typeshed.git || git clone --depth=1 https://github.com/python/typeshed.git
72+
- uses: astral-sh/setup-uv@v6
73+
- name: Check a basic run doesn't fail
74+
run: uvx --python="${DEFAULT_PYTHON_VERSION}" python ./docstring-adder/.github/scripts/typeshed_third_party.py --typeshed-dir ./typeshed --docstring-adder-dir ./docstring-adder
75+
- name: Check typeshed's mypy_test.py passes
76+
run: uv run --directory=typeshed --no-project --python="${DEFAULT_PYTHON_VERSION}" --with-requirements=requirements-tests.txt python tests/mypy_test.py stubs -p "${DEFAULT_PYTHON_VERSION}"
77+
# Ideally we'd now check that running it again doesn't produce any changes, but it fails for some third-party packages.
78+
# I believe this is because some badly-behaved packages make persistent changes to the Python environment when they're imported.
79+
# Stubs packages for which this fails are: `Authlib`, `aws-xray-sdk`, `beautifulsoup4`, `html5lib`, `python-jose`, `qrcode`
80+
81+
# A fairly arbitrary check, but it's good to enforce that it works on a non-typeshed stubs package.
82+
pandas-stubs:
83+
name: Check running on pandas-stubs
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
with:
88+
path: docstring-adder
89+
persist-credentials: false
90+
- name: Checkout typeshed
91+
run: git clone --depth=1 https://github.com/pandas-dev/pandas-stubs.git || git clone --depth=1 https://github.com/pandas-dev/pandas-stubs.git
92+
- uses: astral-sh/setup-uv@v6
93+
- name: Check a basic run doesn't fail
94+
run: uvx --python="${DEFAULT_PYTHON_VERSION}" --force-reinstall --with=pandas --from=./docstring-adder add-docstrings --packages ./pandas-stubs
95+
- name: Check running it again doesn't produce any changes
96+
shell: bash
97+
run: |
98+
git config --global user.email "you@example.com"
99+
git config --global user.name "Your Name"
100+
cd pandas-stubs
101+
test -n "$(git status --porcelain)"
102+
git commit -am "."
103+
uvx --python="${DEFAULT_PYTHON_VERSION}" --force-reinstall --with=pandas --from=../docstring-adder add-docstrings --packages .
104+
test -z "$(git status --porcelain)"
105+
58106
mypy:
59107
name: Run mypy
60108
runs-on: ubuntu-latest
@@ -73,3 +121,28 @@ jobs:
73121
persist-credentials: false
74122
- uses: actions/setup-python@v5
75123
- uses: pre-commit/action@v3.0.1
124+
125+
create-issue-on-failure:
126+
name: Create an issue if the daily test run failed
127+
runs-on: ubuntu-latest
128+
needs:
129+
- stdlib
130+
- typeshed-third-party
131+
- mypy
132+
- pre-commit
133+
- pandas-stubs
134+
if: ${{ github.repository == 'astral-sh/docstring-adder' && always() && github.event_name == 'schedule' && ((needs.stdlib.result == 'failure') || (needs.typeshed-third-party.result == 'failure') || (needs.mypy.result == 'failure') || (needs.pre-commit.result == 'failure') || (needs.pandas-stubs.result == 'failure')) }}
135+
permissions:
136+
issues: write
137+
steps:
138+
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
139+
with:
140+
github-token: ${{ secrets.GITHUB_TOKEN }}
141+
script: |
142+
await github.rest.issues.create({
143+
owner: "astral-sh",
144+
repo: "docstring-adder",
145+
title: `Daily test run failed on ${new Date().toDateString()}`,
146+
body: "Run listed here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
147+
labels: ["bug"],
148+
})

add_docstrings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
Some miscellaneous details:
3333
- The tool should be idempotent. It should add docstrings where possible, but it should
3434
never remove or alter docstrings that were already present in the stub file.
35+
Idempotency cannot be guaranteed, however, if importing the package at runtime causes
36+
persistent changes to be made to your Python environment.
3537
- Because it is a libcst-based codemod, it should not make spurious changes to formatting
3638
or comments in the stub file. `type: ignore` comments should be preserved; mypy and
3739
other type checkers should still be able to type-check the stub file after
@@ -910,7 +912,7 @@ def _main() -> None:
910912
add_docstrings_to_stub(module, context, stdlib_blacklist)
911913
elif any(path.is_relative_to(p) for p in package_paths):
912914
add_docstrings_to_stub(module, context, combined_blacklist)
913-
m = "\n--- Successfully codemodded typeshed ---"
915+
m = "\n--- Successfully completed the codemod ---"
914916
print(colored(m, "green"))
915917
sys.exit(0)
916918

0 commit comments

Comments
 (0)