Skip to content

Commit 5959e1a

Browse files
gaborbernatilevkivskyi
authored andcommitted
support for PyCharm test debugging, and add tox environment setup (#5189)
Most open source projects use tox as a way of automating project setup. It means the user can just invoke tox and that will setup automatically environments in what to develop and run tests. Additionally, PyCharm is a highly popular IDE, that allows users not that friendly to the command line to quickly become productive. This PR makes some changes to ensure that out of box clone of mypy allows running the tests from within PyCharm (and that they pass). Plus, it exposes targets that also run inside the CI locally (e.g. running tests for Python 3.4, 3.5, 3.6, 3.7). Once you have tox installed on a system or user level (``pip install tox``): ```bash cd mypy tox -av default environments: py34 -> run the test driver with python3.4 py35 -> run the test driver with python3.5 py36 -> run the test driver with python3.6 py37 -> run the test driver with python3.7 lint -> check the code style type -> type check ourselves docs -> invoke sphinx-build to build the HTML docs additional environments: dev -> generate a DEV environment, that has all project libraries ``` E.g. to generate the documentation locally all one needs to do is ``tox -e docs``, and can then view it by opening the HTML up from a browser inside ``.tox/docs_out`` folder. Tox is kinda like make, but cross-platform (https://tox.readthedocs.org), written in Python and built-in isolation and virtualenv creation.
1 parent ec47e84 commit 5959e1a

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dmypy.json
1919
# Packages
2020
*.egg
2121
*.egg-info
22+
*.eggs
2223

2324
# IDEs
2425
.idea
@@ -33,3 +34,5 @@ htmlcov
3334

3435
# pytest cache
3536
.pytest_cache/
37+
38+
.tox

mypy/test/testcmdline.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
5858
outb = process.stdout.read()
5959
# Split output into lines.
6060
out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()]
61+
62+
if "PYCHARM_HOSTED" in os.environ:
63+
pos = next((p for p, i in enumerate(out) if i.startswith('pydev debugger: ')), None)
64+
if pos is not None:
65+
del out[pos] # the attaching debugger message itself
66+
del out[pos] # plus the extra new line added
67+
6168
result = process.wait()
6269
# Remove temp file.
6370
os.remove(program_path)

pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ python_classes =
2020
python_functions =
2121

2222
# always run in parallel (requires pytest-xdist, see test-requirements.txt)
23-
addopts = -nauto --cov-append --cov-report=
23+
addopts = -nauto
24+

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ exclude =
2525
typeshed/*,
2626
# during runtests.py flake8 might be started when there's still examples in the temp dir
2727
tmp-test-dirs/*
28-
28+
.tox
29+
.eggs
2930

3031
# Things to ignore:
3132
# E251: spaces around default arg value (against our style)

tox.ini

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[tox]
2+
minversion = 2.9.1
3+
skip_missing_interpreters = true
4+
envlist = py34,
5+
py35,
6+
py36,
7+
py37,
8+
lint,
9+
type,
10+
docs
11+
12+
[testenv]
13+
description = run the test driver with {basepython}
14+
deps = -rtest-requirements.txt
15+
commands = python runtests.py -x lint -x self-check {posargs}
16+
17+
[testenv:lint]
18+
description = check the code style
19+
basepython = python3.6
20+
commands = python runtests.py lint {posargs}
21+
22+
[testenv:type]
23+
description = type check ourselves
24+
basepython = python3.6
25+
commands = python runtests.py self-check -p '-n0' -p '-v'
26+
27+
[testenv:docs]
28+
description = invoke sphinx-build to build the HTML docs
29+
basepython = python3.6
30+
deps = -rdocs/requirements-docs.txt
31+
commands = sphinx-build -d "{toxworkdir}/docs_doctree" docs/source "{toxworkdir}/docs_out" --color -W -bhtml {posargs}
32+
33+
[testenv:dev]
34+
description = generate a DEV environment, that has all project libraries
35+
usedevelop = True
36+
basepython = python3.6
37+
deps = -rtest-requirements.txt
38+
-rdocs/requirements-docs.txt
39+
commands = python -m pip list --format=columns
40+
python -c 'import sys; print(sys.executable)'

0 commit comments

Comments
 (0)