Skip to content

Commit

Permalink
Merge pull request python-trio#5 from smurfix/master
Browse files Browse the repository at this point in the history
Sniff for curio
  • Loading branch information
njsmith authored Nov 25, 2018
2 parents e3d3093 + 2f723cf commit 113123e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if [ "$TRAVIS_OS_NAME" = "osx" ]; then
sudo $PYTHON_EXE -m pip install virtualenv
$PYTHON_EXE -m virtualenv testenv
source testenv/bin/activate
https://github.com/dabeaz/curio
fi

if [ "$USE_PYPY_NIGHTLY" = "1" ]; then
Expand Down
1 change: 1 addition & 0 deletions newsfragments/5.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sniff for curio.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
extras_require={":python_version < '3.7'": ["contextvars>=2.1"]},
python_requires=">=3.5",
tests_require=['curio'],
classifiers=[
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: Apache Software License",
Expand Down
8 changes: 8 additions & 0 deletions sniffio/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def current_async_library():
Library Requires Magic string
================ =========== ============================
**Trio** Trio v0.6+ ``"trio"``
**Curio** - ``"curio"``
**asyncio** ``"asyncio"``
**Trio-asyncio** v0.8.2+ ``"trio"`` or ``"asyncio"``,
depending on current mode
Expand Down Expand Up @@ -53,6 +54,13 @@ async def generic_sleep(seconds):
value = current_async_library_cvar.get()
if value is not None:
return value

# Sniff for curio (for now)
if 'curio' in sys.modules:
from curio.meta import curio_running
if curio_running():
return 'curio'

# Need to sniff for asyncio
if "asyncio" in sys.modules:
import asyncio
Expand Down
21 changes: 21 additions & 0 deletions sniffio/_tests/test_sniffio.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ async def this_is_asyncio():

with pytest.raises(AsyncLibraryNotFoundError):
current_async_library()


def test_curio():
import curio

with pytest.raises(AsyncLibraryNotFoundError):
current_async_library()

ran = []

async def this_is_curio():
assert current_async_library() == "curio"
# Call it a second time to exercise the caching logic
assert current_async_library() == "curio"
ran.append(True)

curio.run(this_is_curio)
assert ran == [True]

with pytest.raises(AsyncLibraryNotFoundError):
current_async_library()
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
pytest-cov
curio

0 comments on commit 113123e

Please sign in to comment.