Skip to content

Commit 2e97f0a

Browse files
sobolevnpre-commit-ci[bot]flaeppe
authored
Add stubtest with lots of errors (currently) (#1560)
* Add stubtest with lots of errors * Update test.yml * Add -ignore-positional-only for now * Fix CI * Fix CI * [pre-commit.ci] auto fixes from pre-commit.com hooks * Fix CI * Address review * Update `allowlist_todo.txt` * Update CONTRIBUTING.md Co-authored-by: Petter Friberg <[email protected]> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Petter Friberg <[email protected]>
1 parent 8e7e470 commit 2e97f0a

File tree

5 files changed

+2387
-12
lines changed

5 files changed

+2387
-12
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ jobs:
6464
- name: Run tests
6565
run: PYTHONPATH='.' pytest
6666

67+
stubtest:
68+
runs-on: ubuntu-latest
69+
strategy:
70+
matrix:
71+
python-version: ['3.11']
72+
steps:
73+
- uses: actions/checkout@v3
74+
- name: Setup system dependencies
75+
run: |
76+
sudo apt-get update
77+
sudo apt-get install binutils libproj-dev gdal-bin
78+
- name: Set up Python ${{ matrix.python-version }}
79+
uses: actions/setup-python@v4
80+
with:
81+
python-version: ${{ matrix.python-version }}
82+
- name: Install dependencies
83+
run: |
84+
pip install -U pip setuptools wheel
85+
pip install -r ./requirements.txt
86+
87+
- name: Run stubtest
88+
run: bash ./scripts/stubtest.sh
89+
6790
matrix-test:
6891
runs-on: ubuntu-latest
6992
strategy:

CONTRIBUTING.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project is open source and community driven. As such we encourage code cont
77
3. Improve plugin code and extend its capabilities
88
4. Write tests
99
5. Update dependencies
10+
6. Fix and remove things from our `stubtest/allowlist_todo.txt`
1011

1112
## Tutorials
1213

@@ -76,23 +77,19 @@ If you get some unexpected results or want to be sure that tests run is not affe
7677
rm -r .mypy_cache
7778
```
7879

80+
### Testing stubs with `stubtest`
7981

80-
### Generating Stubs using Stubgen
82+
Run `bash ./scripts/stubtest.sh` to test that stubs and sources are in-line.
8183

82-
The stubs are based on auto-generated code created by Mypy's stubgen tool (see: [the stubgen docs](https://mypy.readthedocs.io/en/stable/stubgen.html)).
83-
To make life easier we have a helper script that auto generates these stubs. To use it you can run:
84+
We have two special files to allow errors:
85+
1. `scripts/stubtest/allowlist.txt` where we store things that we really don't care about: hacks, django internal utility modules, things that are handled by our plugin, things that are not representable by type system, etc
86+
2. `scripts/stubtest/allowlist_generate.txt` where we store all errors there are right now. Basically, this is a TODO list: we need to work through this list and fix things (or move entries to real `allowlist.txt`). In the end, ideally we can remove this file
8487

85-
```bash
86-
python ./scripts/stubgen-django.py --django_version 3.2
87-
```
88-
89-
You can also pass an optional commit hash as a second kwarg to checkout a specific commit, e.g.
88+
You might also want to disable `incremental` mode while working on `stubtest` changes.
89+
This mode leads to several known problems (stubs do not show up or have strange errors).
9090

91-
```bash
92-
python ./scripts/stubgen-django.py --django_version 3.2 --commit_sha <commit_sha>
93-
```
91+
**Important**: right now we only run `stubtest` on Python 3.11 (because it is the latest released version at the moment), any other versions might generate different outputs. Any work to create per-version allowlists is welcome.
9492

95-
The output for this is a gitignored folder called "stubgen" in the repo's root.
9693

9794
## Submission Guidelines
9895

scripts/stubtest.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
# Run this script as `bash ./scripts/stubtest.sh`
4+
5+
set -e
6+
7+
export MYPYPATH='.'
8+
9+
# TODO: remove `--ignore-positional-only` when ready
10+
stubtest django \
11+
--mypy-config-file mypy.ini \
12+
--ignore-positional-only \
13+
--allowlist scripts/stubtest/allowlist.txt \
14+
--allowlist scripts/stubtest/allowlist_todo.txt \
15+
--generate-allowlist

scripts/stubtest/allowlist.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This is a true allow list with things that we really don't care about.
2+
# `stubtest.generated.txt` is autogenerated by `stubtest --generate-allowlist`
3+
# and might cointain actual problems and things that we *do want* to fix.
4+
#
5+
# Please, move things here when you are sure that they really should be ignored.
6+
# Comments about why things are ignored are mandatory.
7+
8+
# We don't need locales:
9+
django.conf.locale.*
10+
11+
# We don't need migrations:
12+
django.contrib.admin.migrations.*
13+
django.contrib.auth.migrations.*
14+
django.contrib.flatpages.migrations.*
15+
django.contrib.contenttypes.migrations.*

0 commit comments

Comments
 (0)