Skip to content

[wip] experimenting with type hint generation (pyannotate) #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def main():
install_requires=["py>=1.4.17", "pluggy>=0.3.0,<1.0", "six", "virtualenv>=1.11.2"],
extras_require={
"testing": [
"pytest >= 3.0.0", "pytest-cov", "pytest-mock", "pytest-timeout", "pytest-xdist"
"pytest >= 3.0.0",
"pytest-cov",
"pytest-mock",
"pytest-timeout",
"pytest-xdist",
"pyannotate",
],
"docs": ["sphinx >= 1.6.3, < 2", "towncrier >= 17.8.0"],
"lint": ["pre-commit == 1.8.2"],
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ include_trailing_comma = True
force_grid_wrap = 0
line_length = 99
known_first_party = tox
known_third_party = pkg_resources,pluggy,py,pytest,setuptools,six
known_third_party = pkg_resources,pluggy,py,pyannotate_runtime,pytest,setuptools,six
26 changes: 26 additions & 0 deletions tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ def pytest_report_header():
return "tox comes from: {!r}".format(tox.__file__)


def pytest_collection_finish():
"""Handle the pytest collection finish hook: configure pyannotate.
Explicitly delay importing `collect_types` until all tests have
been collected. This gives gevent a chance to monkey patch the
world before importing pyannotate.
"""
from pyannotate_runtime import collect_types

collect_types.init_types_collection()


@pytest.fixture(autouse=True)
def collect_types_fixture():
from pyannotate_runtime import collect_types

collect_types.resume()
yield
collect_types.pause()


def pytest_sessionfinish():
from pyannotate_runtime import collect_types

collect_types.dump_stats("type_info.json")


@pytest.fixture
def work_in_clean_dir(tmpdir):
with tmpdir.as_cwd():
Expand Down