Skip to content

Commit

Permalink
support for PyCharm test debugging, and add tox environment setup (#5189
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
gaborbernat authored and ilevkivskyi committed Jun 14, 2018
1 parent ec47e84 commit 5959e1a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dmypy.json
# Packages
*.egg
*.egg-info
*.eggs

# IDEs
.idea
Expand All @@ -33,3 +34,5 @@ htmlcov

# pytest cache
.pytest_cache/

.tox
7 changes: 7 additions & 0 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
outb = process.stdout.read()
# Split output into lines.
out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()]

if "PYCHARM_HOSTED" in os.environ:
pos = next((p for p, i in enumerate(out) if i.startswith('pydev debugger: ')), None)
if pos is not None:
del out[pos] # the attaching debugger message itself
del out[pos] # plus the extra new line added

result = process.wait()
# Remove temp file.
os.remove(program_path)
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ python_classes =
python_functions =

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

3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ exclude =
typeshed/*,
# during runtests.py flake8 might be started when there's still examples in the temp dir
tmp-test-dirs/*

.tox
.eggs

# Things to ignore:
# E251: spaces around default arg value (against our style)
Expand Down
40 changes: 40 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[tox]
minversion = 2.9.1
skip_missing_interpreters = true
envlist = py34,
py35,
py36,
py37,
lint,
type,
docs

[testenv]
description = run the test driver with {basepython}
deps = -rtest-requirements.txt
commands = python runtests.py -x lint -x self-check {posargs}

[testenv:lint]
description = check the code style
basepython = python3.6
commands = python runtests.py lint {posargs}

[testenv:type]
description = type check ourselves
basepython = python3.6
commands = python runtests.py self-check -p '-n0' -p '-v'

[testenv:docs]
description = invoke sphinx-build to build the HTML docs
basepython = python3.6
deps = -rdocs/requirements-docs.txt
commands = sphinx-build -d "{toxworkdir}/docs_doctree" docs/source "{toxworkdir}/docs_out" --color -W -bhtml {posargs}

[testenv:dev]
description = generate a DEV environment, that has all project libraries
usedevelop = True
basepython = python3.6
deps = -rtest-requirements.txt
-rdocs/requirements-docs.txt
commands = python -m pip list --format=columns
python -c 'import sys; print(sys.executable)'

0 comments on commit 5959e1a

Please sign in to comment.