Skip to content

Commit 088faa0

Browse files
Run pyright via tox (#1134)
1 parent d039456 commit 088faa0

File tree

7 files changed

+64
-113
lines changed

7 files changed

+64
-113
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,59 +60,49 @@ jobs:
6060
path: dist/
6161

6262
test:
63-
name: Test
6463
# Specific ubuntu version to support python 3.6 testing
6564
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877 for details
6665
# move to ubuntu-latest when we drop 3.6
6766
runs-on: ubuntu-20.04
6867
strategy:
68+
fail-fast: false
6969
matrix:
70-
python-version:
71-
[
72-
"3.6",
73-
"3.7",
74-
"3.8",
75-
"3.9",
76-
"3.10",
77-
"3.11",
78-
"3.12",
79-
"pypy-3.7",
80-
"pypy-3.8",
81-
"pypy-3.9",
82-
"pypy-3.10",
83-
]
84-
70+
python:
71+
- { version: "3.6" , env: "py36" }
72+
- { version: "3.7" , env: "py37" }
73+
- { version: "3.8" , env: "py38" }
74+
- { version: "3.9" , env: "py39" }
75+
- { version: "3.10" , env: "py310" }
76+
- { version: "3.11" , env: "py311" }
77+
- { version: "3.12" , env: "py312" }
78+
- { version: "pypy-3.7" , env: "py3.7" }
79+
- { version: "pypy-3.8" , env: "py3.8" }
80+
- { version: "pypy-3.9" , env: "py3.9" }
81+
- { version: "pypy-3.10" , env: "py3.10" }
82+
name: Test (${{ matrix.python.version }})
8583
steps:
8684
- uses: actions/checkout@v3
8785

88-
- name: Set up Python ${{ matrix.python-version }}
86+
- name: Set up Python ${{ matrix.python.version }} and 3.10
8987
uses: actions/setup-python@v4
9088
with:
91-
python-version: ${{ matrix.python-version }}
92-
cache: "pip"
93-
cache-dependency-path: "setup.py"
94-
95-
- name: Upgrade pip and virtualenv to latest
96-
run: pip install --upgrade pip virtualenv
89+
python-version: |
90+
${{ matrix.python.version }}
91+
3.10
9792
9893
- uses: stripe/openapi/actions/stripe-mock@master
9994

10095
- name: Typecheck with pyright
101-
run: make pyright
102-
# Pip won't install newer versions of pyright on python 3.6 (odd, because pyright is a node module)
103-
# so we skip running pyright, and do double duty on python 3.7 using the --pythonversion flag.
104-
if: matrix.python-version != '3.6'
105-
106-
- name: Typecheck with pyright
107-
run: make pyright PYRIGHT_ARGS="--pythonversion 3.6"
108-
if: matrix.python-version == '3.7'
96+
run: PYRIGHT_ARGS="-- --pythonversion ${{ matrix.python.version }}" make pyright
97+
# Skip typecheking in pypy legs
98+
if: ${{ !contains(matrix.python.version, 'pypy') }}
10999

110100
- name: Test with pytest
111-
run: make ci-test
101+
run: TOX_ARGS="-e ${{ matrix.python.env }}" make ci-test
112102

113103
- name: Calculate and publish coverage
114104
run: make coveralls
115-
if: env.COVERALLS_REPO_TOKEN && matrix.python-version == '3.10'
105+
if: env.COVERALLS_REPO_TOKEN && matrix.python.version == '3.10'
116106
env:
117107
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118108
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

Makefile

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
VENV_NAME?=venv
22
PIP?=pip
3-
PYTHON?=python3
3+
PYTHON?=python3.10
4+
DEFAULT_TEST_ENV?=py310
45

56
venv: $(VENV_NAME)/bin/activate
67

@@ -9,8 +10,8 @@ $(VENV_NAME)/bin/activate: setup.py requirements.txt
910
${VENV_NAME}/bin/python -m pip install -r requirements.txt
1011
@touch $(VENV_NAME)/bin/activate
1112

12-
test: venv
13-
@${VENV_NAME}/bin/tox -p auto $(TOX_ARGS)
13+
test: venv pyright lint
14+
@${VENV_NAME}/bin/tox -p auto -e $(DEFAULT_TEST_ENV) $(TOX_ARGS)
1415

1516
test-nomock: venv
1617
@${VENV_NAME}/bin/tox -p auto -- --nomock $(TOX_ARGS)
@@ -22,17 +23,7 @@ coveralls: venv
2223
@${VENV_NAME}/bin/tox -e coveralls
2324

2425
pyright: venv
25-
# In order for pyright to be able to follow imports, we need "editable_mode=compat" to force setuptools to do
26-
# an editable install via a .pth file mechanism and not "import hooks". See
27-
# the "editable installs" section of https://github.com/microsoft/pyright/blob/main/docs/import-resolution.md#editable-installs
28-
29-
# This command might fail if we're on python 3.6, as versions of pip that
30-
# support python 3.6 don't know about "--config-settings", but in this case
31-
# we don't need to pass config-settings anyway because "editable_mode=compat" just
32-
# means to perform as these old versions of pip already do.
33-
pip install -e . --config-settings editable_mode=compat || pip install -e .
34-
@${VENV_NAME}/bin/pyright --version
35-
@${VENV_NAME}/bin/pyright $(PYRIGHT_ARGS)
26+
@${VENV_NAME}/bin/tox -e pyright $(PYRIGHT_ARGS)
3627

3728
fmt: venv
3829
@${VENV_NAME}/bin/tox -e fmt

pyproject.toml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[tool.black]
2-
line-length=79
2+
line-length = 79
33
target-version = [
44
"py35",
55
"py36",
66
"py37",
77
"py38",
88
"py39",
99
"py310",
10-
# "py311", # black 21.12b0 doesn't
11-
# "py312", # support these targets
10+
# "py311", # black 21.12b0 doesn't
11+
# "py312", # support these targets
1212
]
1313
exclude = '''
1414
/(
@@ -23,14 +23,10 @@ exclude = '''
2323
)
2424
'''
2525
[tool.pyright]
26-
executionEnvironments=[
27-
{"root" = "stripe"},
28-
{"root" = "tests"}
29-
]
30-
include=["stripe", "tests/test_generated_examples.py"]
31-
exclude=["build", "**/__pycache__"]
32-
reportMissingTypeArgument=true
33-
reportUnnecessaryCast=true
34-
reportUnnecessaryComparison=true
35-
reportUnnecessaryContains=true
36-
reportUnnecessaryIsInstance=true
26+
include = ["stripe", "tests/test_generated_examples.py"]
27+
exclude = ["build", "**/__pycache__"]
28+
reportMissingTypeArgument = true
29+
reportUnnecessaryCast = true
30+
reportUnnecessaryComparison = true
31+
reportUnnecessaryContains = true
32+
reportUnnecessaryIsInstance = true

requirements.txt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# cryptography 40.0.0 deprecates support for Python 3.6 and PyPy3 < 7.3.10
2-
cryptography<40
3-
tox
1+
# These requirements must be installable only on py3.10 +
42
twine
5-
pyright
6-
pytest-cov >= 2.8.1, < 2.11.0
7-
pytest-mock >= 2.0.0
8-
pytest-xdist >= 1.31.0
9-
pytest >= 6.0.0
3+
# 4.5.0 is the last version that works with virtualenv<20.22.0
4+
tox == 4.5.0
5+
#Virtualenv 20.22.0 dropped support for all Python versions smaller or equal to Python 3.6.
6+
virtualenv<20.22.0
7+
pyright == 1.1.336
108
black == 22.8.0
119
flake8
12-
coverage >= 4.5.3, < 5
13-
coveralls
14-
tox-gh-actions
10+
11+
-r test-requirements.txt

test-requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# These requirements must be installable on all our supported versions
2+
pytest-cov >= 2.8.1, < 2.11.0
3+
pytest-mock >= 2.0.0
4+
pytest-xdist >= 1.31.0
5+
pytest >= 6.0.0
6+
coverage >= 4.5.3, < 5
7+
coveralls

tests/conftest.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import atexit
22
import os
33
import sys
4-
from distutils.version import StrictVersion
5-
64
import pytest
75

86
import stripe
9-
from urllib.request import urlopen
10-
from urllib.error import HTTPError
7+
import requests
118

129
from tests.request_mock import RequestMock
1310
from tests.stripe_mock import StripeMock
@@ -30,21 +27,7 @@ def stop_stripe_mock():
3027
def pytest_configure(config):
3128
if not config.getoption("--nomock"):
3229
try:
33-
resp = urlopen("http://localhost:%s/" % MOCK_PORT)
34-
info = resp.info()
35-
version = info.get("Stripe-Mock-Version")
36-
if version != "master" and StrictVersion(version) < StrictVersion(
37-
MOCK_MINIMUM_VERSION
38-
):
39-
sys.exit(
40-
"Your version of stripe-mock (%s) is too old. The minimum "
41-
"version to run this test suite is %s. Please "
42-
"see its repository for upgrade instructions."
43-
% (version, MOCK_MINIMUM_VERSION)
44-
)
45-
46-
except HTTPError as e:
47-
info = e.info()
30+
requests.get("http://localhost:%s/" % MOCK_PORT)
4831
except Exception:
4932
sys.exit(
5033
"Couldn't reach stripe-mock at `localhost:%s`. Is "

tox.ini

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@
77
envlist =
88
fmt
99
lint
10+
pyright
1011
py{312,311,310,39,38,37,36,py3}
11-
skip_missing_interpreters = true
12-
13-
[gh-actions]
14-
python =
15-
3.12: py312
16-
3.11: py311
17-
3.10: py310
18-
3.9: py39
19-
3.8: py38
20-
3.7: py37
21-
3.6: py36
22-
pypy-3: pypy3
12+
ignore_base_python_conflict = false
2313

2414
[tool:pytest]
2515
testpaths = tests
@@ -31,7 +21,7 @@ description = run the unit tests under {basepython}
3121
setenv =
3222
COVERAGE_FILE = {toxworkdir}/.coverage.{envname}
3323
deps =
34-
-r requirements.txt
24+
-r test-requirements.txt
3525

3626
# ignore stripe directory as all tests are inside ./tests
3727
commands = pytest --cov {posargs:-n auto} --ignore stripe
@@ -42,18 +32,15 @@ commands = pytest --cov {posargs:-n auto} --ignore stripe
4232
# CFLAGS="-I$(brew --prefix [email protected])/include"
4333
passenv = LDFLAGS,CFLAGS
4434

45-
[testenv:fmt]
46-
description = run code formatting using black
35+
[testenv:{lint,fmt,pyright}]
4736
basepython = python3.10
48-
commands = black . {posargs}
4937
skip_install = true
50-
51-
[testenv:lint]
52-
description = run static analysis and style check using flake8
53-
basepython = python3.10
5438
commands =
55-
python -m flake8 --show-source stripe tests setup.py
56-
skip_install = true
39+
pyright: pyright {posargs}
40+
lint: python -m flake8 --show-source stripe tests setup.py
41+
fmt: black . {posargs}
42+
deps =
43+
-r requirements.txt
5744

5845
[testenv:coveralls]
5946
description = upload coverage to coveralls.io

0 commit comments

Comments
 (0)