Skip to content

Commit

Permalink
Move current_async_library to different PR
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusSintonen committed Jun 10, 2024
1 parent 81a49c9 commit 0239c8c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 58 deletions.
4 changes: 2 additions & 2 deletions httpcore/_backends/auto.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import typing
from typing import Optional

from .._synchronization import current_async_library
from .._synchronization import current_async_backend
from .base import SOCKET_OPTION, AsyncNetworkBackend, AsyncNetworkStream


class AutoBackend(AsyncNetworkBackend):
async def _init_backend(self) -> None:
if not (hasattr(self, "_backend")):
backend = current_async_library()
backend = current_async_backend()
if backend == "trio":
from .trio import TrioBackend

Expand Down
19 changes: 5 additions & 14 deletions httpcore/_synchronization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import os
import threading
from types import TracebackType
from typing import (
Expand Down Expand Up @@ -31,7 +30,6 @@


AsyncBackend = Literal["asyncio", "trio"]
AsyncLibrary = Literal["asyncio", "trio", "anyio"]


def current_async_backend() -> AsyncBackend:
Expand All @@ -47,6 +45,11 @@ def current_async_backend() -> AsyncBackend:
if environment not in ("asyncio", "trio"): # pragma: nocover
raise RuntimeError("Running under an unsupported async environment.")

if environment == "asyncio" and anyio is None: # pragma: nocover
raise RuntimeError(
"Running with asyncio requires installation of 'httpcore[asyncio]'."
)

if environment == "trio" and trio is None: # pragma: nocover
raise RuntimeError(
"Running with trio requires installation of 'httpcore[trio]'."
Expand All @@ -55,18 +58,6 @@ def current_async_backend() -> AsyncBackend:
return environment


def current_async_library() -> AsyncLibrary:
if current_async_backend() == "trio":
return "trio"

if anyio is not None:
anyio_env = os.environ.get("HTTPCORE_PREFER_ANYIO", "true").lower()
if anyio_env in ("true", "1"):
return "anyio"

return "asyncio"


class _LockProto(Protocol):
async def acquire(self) -> Any: ...
def release(self) -> None: ...
Expand Down
42 changes: 0 additions & 42 deletions tests/test_synchronization.py

This file was deleted.

0 comments on commit 0239c8c

Please sign in to comment.