8000 Merge remote-tracking branch 'upstream/master' into fix_4610 · python/mypy@52a1191 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52a1191

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix_4610
2 parents 15b51fc + 11d4fb2 commit 52a1191

File tree

935 files changed

+65141
-7310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

935 files changed

+65141
-7310
lines changed

.github/workflows/mypy_primer.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Run mypy_primer
2+
3+
on:
4+
# Only run on PR, since we diff against master
5+
pull_request:
6+
paths-ignore:
7+
- 'docs/**'
8+
- '**/*.rst'
9+
- '**/*.md'
10+
- 'mypyc/**'
11+
12+
jobs:
13+
mypy_primer:
14+
name: Run
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
shard-index: [0, 1, 2]
19+
fail-fast: false
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
path: mypy_to_test
24+
fetch-depth: 0
25+
- uses: actions/setup-python@v2
26+
with:
27+
python-version: 3.8
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install -U pip
31+
pip install git+https://github.com/hauntsaninja/mypy_primer.git
32+
- name: Run mypy_primer
33+
shell: bash
34+
run: |
35+
cd mypy_to_test
36+
echo "new commit"
37+
git rev-list --format=%s --max-count=1 $GITHUB_SHA
38+
git checkout -b upstream_master origin/master
39+
echo "base commit"
40+
git rev-list --format=%s --max-count=1 upstream_master
41+
echo ''
42+
cd ..
43+
# fail action if exit code isn't zero or one
44+
(
45+
mypy_primer \
46+
--repo mypy_to_test \
47+
--new $GITHUB_SHA --old upstream_master \
48+
--num-shards 3 --shard-index ${{ matrix.shard-index }} \
49+
--debug \
50+
--output concise \
51+
| tee diff.txt
52+
) || [ $? -eq 1 ]
53+
- name: Upload mypy_primer diff
54+
uses: actions/upload-artifact@v2
55+
with:
56+
name: mypy_primer_diff_${{ matrix.shard-index }}
57+
path: diff.txt
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Comment with mypy_primer diff
2+
3+
on:
4+
# pull_request_target gives us access to a write token which we need to post a comment
5+
# The presence of a write token means that we can't run any untrusted code (i.e. malicious PRs),
6+
# which is why this its own workflow. Github Actions doesn't make it easy for workflows to talk to
7+
# each other, so the approach here is to poll for workflow runs, find the mypy_primer run for our
8+
# commit, wait till it's completed, and download and post the diff.
9+
pull_request_target:
10+
paths-ignore:
11+
- 'docs/**'
12+
- '**/*.rst'
13+
- '**/*.md'
14+
- 'mypyc/**'
15+
16+
jobs:
17+
mypy_primer:
18+
name: Comment
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Install dependencies
22+
run: npm install adm-zip
23+
- name: Post comment
24+
uses: actions/github-script@v3
25+
with:
26+
github-token: ${{secrets.GITHUB_TOKEN}}
27+
script: |
28+
const AdmZip = require(`${process.env.GITHUB_WORKSPACE}/node_modules/adm-zip`)
29+
30+
// Because of pull_request_target, context.sha is the PR base branch
31+
// So we need to ask Github for the SHA of the PR's head commit
32+
const pull_request = await github.pulls.get({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
pull_number: context.issue.number,
36+
})
37+
const pr_commit_sha = pull_request.data.head.sha
38+
console.log("Looking for mypy_primer run for commit:", pr_commit_sha)
39+
40+
// Find the mypy_primer run for our commit and wait till it's completed
41+
// We wait up to an hour before timing out
42+
async function check_mypy_primer() {
43+
// We're only looking at the first page, so in theory if we open enough PRs around
44+
// the same time, this will fail to find the run.
45+
const response = await github.actions.listWorkflowRuns({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
workflow_id: "mypy_primer.yml",
49+
})
50+
if (response) {
51+
return response.data.workflow_runs.find(run => run.head_sha == pr_commit_sha)
52+
}
53+
return undefined
54+
}
55+
56+
const end_time = Number(new Date()) + 60 * 60 * 1000
57+
let primer_run = await check_mypy_primer()
58+
while (!primer_run || primer_run.status != "completed") {
59+
if (Number(new Date()) > end_time) {
60+
throw Error("Timed out waiting for mypy_primer")
61+
}
62+
console.log("Waiting for mypy_primer to complete...")
63+
await new Promise(r => setTimeout(r, 10000))
64+
primer_run = await check_mypy_primer()
65+
}
66+
console.log("Found mypy_primer run!")
67+
console.log(primer_run)
68+
69+
// Download artifact(s) from the run
70+
const artifacts = await github.actions.listWorkflowRunArtifacts({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
run_id: primer_run.id,
74+
})
75+
const filtered_artifacts = artifacts.data.artifacts.filter(
76+
a => a.name.startsWith("mypy_primer_diff")
77+
)
78+
console.log("Artifacts from mypy_primer:")
79+
console.log(filtered_artifacts)
80+
81+
async function get_artifact_data(artifact) {
82+
const zip = await github.actions.downloadArtifact({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
artifact_id: artifact.id,
86+
archive_format: "zip",
87+
})
88+
const adm = new AdmZip(Buffer.from(zip.data))
89+
return adm.readAsText(adm.getEntry("diff.txt"))
90+
}
91+
92+
const all_data = await Promise.all(filtered_artifacts.map(get_artifact_data))
93+
const data = all_data.join("\n")
94+
95+
console.log("Diff from mypy_primer:")
96+
console.log(data)
97+
if (data.trim()) {
98+
await github.issues.createComment({
99+
issue_number: context.issue.number,
100+
owner: context.repo.owner,
101+
repo: context.repo.repo,
102+
body: 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
103+
})
104+
}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
python-version: ${{ matrix.python }}
4343
architecture: ${{ matrix.arch }}
4444
- name: install tox
45-
run: pip install --upgrade 'setuptools!=50' 'virtualenv<20' tox==3.9.0
45+
run: pip install --upgrade 'setuptools!=50' 'virtualenv<20' tox==3.20.1
4646
- name: setup tox environment
4747
run: tox -e ${{ matrix.toxenv }} --notest
4848
- name: test
49-
run: tox -e ${{ matrix.toxenv }}
49+
run: tox -e ${{ matrix.toxenv }} --skip-pkg-install

.github/workflows/test_stubgenc.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test stubgenc on pybind11-mypy-demo
2+
3+
on:
4+
push:
5+
branches: [master]
6+
tags: ['*']
7+
pull_request:
8+
paths:
9+
- 'misc/test-stubgenc.sh'
10+
- 'mypy/stubgenc.py'
11+
- 'mypy/stubdoc.py'
12+
- 'test-data/stubgen/**'
13+
14+
jobs:
15+
stubgenc:
16+
# Check stub file generation for a small pybind11 project
17+
# (full text match is required to pass)
18+
runs-on: ubuntu-latest
19+
steps:
20+
21+
- uses: actions/checkout@v2
22+
23+
- name: initialize submodules
24+
run: git submodule update --init
25+
26+
- name: Setup 🐍 3.8
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: 3.8
30+
31+
- name: Test stubgenc
32+
run: misc/test-stubgenc.sh

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ build/
22
__pycache__
33
*.py[cod]
44
*~
5-
@*
65
/build
76
/env*/
87
docs/build/

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "typeshed"]
2-
path = mypy/typeshed
3-
url = https://github.com/python/typeshed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: "run test suite with python 3.8"
4343
python: 3.8
4444
- name: "run test suite with python 3.9"
45-
python: 3.9-dev
45+
python: 3.9
4646
- name: "run mypyc runtime tests with python 3.6 debug build"
4747
language: generic
4848
env:
@@ -82,20 +82,21 @@ jobs:
8282
# - EXTRA_ARGS=
8383

8484
install:
85-
- pip install -U pip setuptools
85+
# pip 21.0 no longer works on Python 3.5
86+
- pip install -U pip==20.3.4 setuptools
8687
- pip install -U 'virtualenv<20'
87-
- pip install -U tox==3.9.0
88+
- pip install -U tox==3.20.1
8889
- python2 -m pip install --user -U typing
8990
- tox --notest
9091

9192
# This is a big hack and only works because the layout of our directories
9293
# means that tox picks up the mypy from the source directories instead of
9394
# the version it installed into a venv. This is also *why* we need to do this,
9495
# since if we arranged for tox to build with mypyc, pytest wouldn't use it.
95-
- if [[ $TEST_MYPYC == 1 ]]; then pip install -r mypy-requirements.txt; CC=clang MYPYC_OPT_LEVEL=0 python3 setup.py --use-mypyc build_ext --inplace; fi
96+
- if [[ $TEST_MYPYC == 1 ]]; then pip install -r test-requirements.txt; CC=clang MYPYC_OPT_LEVEL=0 python3 setup.py --use-mypyc build_ext --inplace; fi
9697

9798
script:
98-
- tox -- $EXTRA_ARGS
99+
- tox --skip-pkg-install -- $EXTRA_ARGS
99100

100101
# Getting our hands on a debug build or the right OS X build is
101102
# annoying, unfortunately.

LICENSE

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ DEALINGS IN THE SOFTWARE.
2828

2929
Portions of mypy and mypyc are licensed under different licenses. The
3030
files under stdlib-samples as well as the files
31-
mypyc/lib-rt/pythonsupport.h and mypyc/lib-rt/getargs.c are licensed
32-
under the PSF 2 License, reproduced below.
31+
mypyc/lib-rt/pythonsupport.h, mypyc/lib-rt/getargs.c and
32+
mypyc/lib-rt/getargsfast.c are licensed under the PSF 2 License, reproduced
33+
below.
3334

3435
= = = = =
3536

MANIFEST.in

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
recursive-include scripts *
2-
recursive-include test-data *
3-
recursive-include extensions *
4-
recursive-include docs *
5-
recursive-include misc proper_plugin.py
6-
recursive-include mypy/typeshed *.py *.pyi
7-
recursive-include mypy/xml *.xsd *.xslt *.css
8-
recursive-include mypyc/lib-rt *.c *.h *.tmpl *.py *.cc
9-
recursive-include mypyc/ir *.py
10-
recursive-include mypyc/codegen *.py
11-
recursive-include mypyc/irbuild *.py
12-
recursive-include mypyc/primitives *.py
13-
recursive-include mypyc/transform *.py
14-
recursive-include mypyc/external *.cc *.h Makefile *.pump LICENSE README
15-
recursive-include mypyc/test *.py
16-
recursive-include mypyc/test-data *.test
17-
recursive-include mypyc/test-data/fixtures *.py *.pyi
18-
recursive-include mypyc/doc *.rst *.py *.md Makefile *.bat
1+
# some of the prunes here are so that check-manifest doesn't complain about their exclusion
2+
# as such, be judicious in your use of prune
3+
4+
# stubs
5+
prune mypy/typeshed
6+
include mypy/typeshed/stdlib/VERSIONS
7+
recursive-include mypy/typeshed *.pyi
8+
9+
# mypy and mypyc
10+
include mypy/py.typed
11+
recursive-include mypy *.py
12+
recursive-include mypyc *.py
13+
14+
# random
1915
include mypy_bootstrap.ini
16+
graft mypy/xml
17+
graft scripts
18+
19+
# docs
20+
graft docs
21+
prune docs/build
22+
prune docs/source/_build
23+
24+
# assorted mypyc requirements
25+
graft mypyc/external
26+
graft mypyc/lib-rt
27+
graft mypyc/test-data
28+
graft mypyc/doc
29+
30+
# files necessary for testing sdist
31+
include mypy-requirements.txt
32+
include test-requirements.txt
2033
include mypy_self_check.ini
21-
include LICENSE
34+
prune misc
35+
include misc/proper_plugin.py
36+
graft test-data
37+
include conftest.py
2238
include runtests.py
2339
include pytest.ini
40+
41+
include LICENSE mypyc/README.md
42+
exclude .gitmodules CONTRIBUTING.md CREDITS ROADMAP.md tox.ini
43+
44+
global-exclude *.py[cod]
45+
global-exclude .DS_Store

README.md

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,7 @@ Quick start for contributing to mypy
184184

185185
If you want to contribute, first clone the mypy git repository:
186186

187-
$ git clone --recurse-submodules https://github.com/python/mypy.git
188-
189-
If you've already cloned the repo without `--recurse-submodules`,
190-
you need to pull in the typeshed repo as follows:
191-
192-
$ git submodule init
193-
$ git submodule update
194-
195-
Either way you should now have a subdirectory `typeshed` inside your mypy repo,
196-
your folders tree should be like `mypy/mypy/typeshed`, containing a
197-
clone of the typeshed repo (`https://github.com/python/typeshed`).
187+
$ git clone https://github.com/python/mypy.git
198188

199189
From the mypy directory, use pip to install mypy:
200190

@@ -209,22 +199,8 @@ the above as root. For example, in Ubuntu:
209199
Now you can use the `mypy` program just as above. In case of trouble
210200
see "Troubleshooting" above.
211201

212-
> NOTE: Installing with sudo can be a security risk, please try with flag `--user` first.
213-
$ python3 -m pip install --user -U .
214-
215-
Working with the git version of mypy
216-
------------------------------------
217-
218-
mypy contains a submodule, "typeshed". See https://github.com/python/typeshed.
219-
This submodule contains types for the Python standard library.
220-
221-
Due to the way git submodules work, you'll have to do
222-
```
223-
git submodule update mypy/typeshed
224-
```
225-
whenever you change branches, merge, rebase, or pull.
226-
227-
(It's possible to automate this: Search Google for "git hook update submodule")
202+
> NOTE: Installing with sudo can be a security risk. Please try with the `--user` flag first.
203+
$ python3 -m pip install --user -U .
228204

229205

230206
Tests
@@ -244,7 +220,8 @@ Development status
244220
------------------
245221

246222
Mypy is beta software, but it has already been used in production
247-
for several years at Dropbox, and it has an extensive test suite.
223+
for several years at Dropbox and in many other organizations, and
224+
it has an extensive test suite.
248225

249226
See [the roadmap](ROADMAP.md) if you are interested in plans for the
250227
future.

0 commit comments

Comments
 (0)
0