Skip to content

Commit

Permalink
Modernize CI and rename trio.hazmat to trio.lowlevel
Browse files Browse the repository at this point in the history
  • Loading branch information
oremanj committed Oct 1, 2020
1 parent dab9fa3 commit 703035a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 97 deletions.
28 changes: 0 additions & 28 deletions .appveyor.yml

This file was deleted.

19 changes: 8 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ dist: xenial

matrix:
include:
- python: 3.6
env: CHECK_DOCS=1
- python: 3.6
env: CHECK_LINT=1
# The pypy tests are slow, so we list them first
# 'pypy3' on travis is currently 7.1-beta, which has an __init_subclass__ bug
# that we'd run into (fixed on 7.2)
#- python: pypy3
- python: pypy3.6-7.2.0
dist: bionic
- language: generic
env: PYPY_NIGHTLY_BRANCH=py3.6
- python: 3.6
- python: 3.7
- python: 3.8
# Nightly is disabled due to typed-ast not currently building for it
- python: 3.6-dev
- python: 3.7-dev
- python: 3.8-dev
- python: 3.9-dev
# Temporarily disabled during the high-churn period of 3.10
# E.g.: https://github.com/MagicStack/immutables/issues/46
#- python: nightly

script:
Expand Down
6 changes: 3 additions & 3 deletions test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ pytest-faulthandler

# Tools
black == 19.10b0; implementation_name == "cpython"
mypy >= 0.750; implementation_name == "cpython"
mypy >= 0.780; implementation_name == "cpython"
flake8

# Project dependencies
attrs >= 19.2.0
async_generator >= 1.9
trio >= 0.12.0
trio-typing >= 0.3.0
trio >= 0.15.0
trio-typing >= 0.5.0

# typed-ast is required by black + mypy and doesn't build on PyPy;
# it will be unconstrained in requirements.txt if we don't
Expand Down
30 changes: 13 additions & 17 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
# pip-compile test-requirements.in
#
appdirs==1.4.3 # via black
async-generator==1.10
attrs==19.3.0
black==19.10b0 ; implementation_name == "cpython"
async-generator==1.10 # via -r test-requirements.in, pytest-trio, trio
attrs==19.3.0 # via -r test-requirements.in, black, outcome, pytest, trio
black==19.10b0 ; implementation_name == "cpython" # via -r test-requirements.in
click==7.0 # via black
contextvars==2.4 # via sniffio, trio
coverage==4.5.4 # via pytest-cov
entrypoints==0.3 # via flake8
flake8==3.7.9
flake8==3.7.9 # via -r test-requirements.in
idna==2.8 # via trio
immutables==0.11 # via contextvars
importlib-metadata==1.3.0 # via pluggy, pytest
mccabe==0.6.1 # via flake8
more-itertools==8.0.2 # via pytest, zipp
more-itertools==8.0.2 # via pytest
mypy-extensions==0.4.3 # via mypy, trio-typing
mypy==0.750 ; implementation_name == "cpython"
mypy==0.782 ; implementation_name == "cpython" # via -r test-requirements.in, trio-typing
outcome==1.0.1 # via trio
packaging==19.2 # via pytest
pathspec==0.6.0 # via black
Expand All @@ -28,18 +25,17 @@ py==1.8.0 # via pytest
pycodestyle==2.5.0 # via flake8
pyflakes==2.1.1 # via flake8
pyparsing==2.4.5 # via packaging
pytest-cov==2.8.1
pytest-faulthandler==2.0.1
pytest-trio==0.5.2
pytest==5.3.1
pytest-cov==2.8.1 # via -r test-requirements.in
pytest-faulthandler==2.0.1 # via -r test-requirements.in
pytest-trio==0.5.2 # via -r test-requirements.in
pytest==5.3.1 # via -r test-requirements.in, pytest-cov, pytest-faulthandler, pytest-trio
regex==2019.12.9 # via black
six==1.13.0 # via packaging
sniffio==1.1.0 # via trio
sortedcontainers==2.1.0 # via trio
toml==0.10.0 # via black
trio-typing>=0.3.0
trio==0.13.0
typed-ast==1.4.0 ; implementation_name == "cpython"
trio-typing==0.5.0 # via -r test-requirements.in
trio==0.17.0 # via -r test-requirements.in, pytest-trio, trio-typing
typed-ast==1.4.0 ; implementation_name == "cpython" # via -r test-requirements.in, black, mypy
typing-extensions==3.7.4.1 # via mypy, trio-typing
wcwidth==0.1.7 # via pytest
zipp==0.6.0 # via importlib-metadata
2 changes: 1 addition & 1 deletion tricycle/_meta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import functools
from async_generator import asynccontextmanager
from trio_typing import Nursery
from trio import Nursery
from typing import (
Any,
AsyncIterator,
Expand Down
48 changes: 24 additions & 24 deletions tricycle/_rwlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
@attr.s(auto_attribs=True)
class _RWLockStatistics:
locked: str
readers: FrozenSet[trio.hazmat.Task]
writer: Optional[trio.hazmat.Task]
readers: FrozenSet[trio.lowlevel.Task]
writer: Optional[trio.lowlevel.Task]
readers_waiting: int
writers_waiting: int

Expand Down Expand Up @@ -52,9 +52,9 @@ class RWLock:
"""

_writer: Optional[trio.hazmat.Task] = attr.ib(default=None, init=False)
_readers: Set[trio.hazmat.Task] = attr.ib(factory=set, init=False)
_waiting: "OrderedDict[trio.hazmat.Task, bool]" = attr.ib(
_writer: Optional[trio.lowlevel.Task] = attr.ib(default=None, init=False)
_readers: Set[trio.lowlevel.Task] = attr.ib(factory=set, init=False)
_waiting: "OrderedDict[trio.lowlevel.Task, bool]" = attr.ib(
factory=OrderedDict, init=False
)
_waiting_writers_count: int = attr.ib(default=0, init=False)
Expand Down Expand Up @@ -92,7 +92,7 @@ def locked(self) -> str:
"""
return "read" if self._readers else "write" if self._writer else ""

@trio.hazmat.enable_ki_protection
@trio.lowlevel.enable_ki_protection
def acquire_nowait(self, *, for_write: bool) -> None:
"""Attempt to acquire the lock, without blocking.
Expand All @@ -106,7 +106,7 @@ def acquire_nowait(self, *, for_write: bool) -> None:
RuntimeError: if the current task already holds the lock (in either
read or write mode)
"""
task = trio.hazmat.current_task()
task = trio.lowlevel.current_task()
if self._writer is task or task in self._readers:
raise RuntimeError("attempt to re-acquire an already held RWLock")
if self._writer is not None:
Expand All @@ -119,7 +119,7 @@ def acquire_nowait(self, *, for_write: bool) -> None:
else:
raise trio.WouldBlock

@trio.hazmat.enable_ki_protection
@trio.lowlevel.enable_ki_protection
async def acquire(self, *, for_write: bool) -> None:
"""Acquire the lock, blocking if necessary.
Expand All @@ -132,32 +132,32 @@ async def acquire(self, *, for_write: bool) -> None:
RuntimeError: if the current task already holds the lock (in either
read or write mode)
"""
await trio.hazmat.checkpoint_if_cancelled()
await trio.lowlevel.checkpoint_if_cancelled()
try:
self.acquire_nowait(for_write=for_write)
except trio.WouldBlock:
task = trio.hazmat.current_task()
task = trio.lowlevel.current_task()
self._waiting[task] = for_write
self._waiting_writers_count += for_write

def abort_fn(_: object) -> trio.hazmat.Abort:
def abort_fn(_: object) -> trio.lowlevel.Abort:
del self._waiting[task]
self._waiting_writers_count -= for_write
return trio.hazmat.Abort.SUCCEEDED
return trio.lowlevel.Abort.SUCCEEDED

await trio.hazmat.wait_task_rescheduled(abort_fn)
await trio.lowlevel.wait_task_rescheduled(abort_fn)
else:
await trio.hazmat.cancel_shielded_checkpoint()
await trio.lowlevel.cancel_shielded_checkpoint()

@trio.hazmat.enable_ki_protection
@trio.lowlevel.enable_ki_protection
def release(self) -> None:
"""Release the lock.
Raises:
RuntimeError: if the current task does not hold the lock (in either
read or write mode)
"""
task = trio.hazmat.current_task()
task = trio.lowlevel.current_task()
if task is self._writer:
self._writer = None
elif task in self._readers:
Expand All @@ -173,7 +173,7 @@ def release(self) -> None:
# Next task is a reader: since we haven't woken
# a writer yet, we can wake it,
self._readers.add(task)
trio.hazmat.reschedule(task)
trio.lowlevel.reschedule(task)
# In read-biased mode we can continue to wake
# all other readers.
if self._read_biased:
Expand All @@ -187,7 +187,7 @@ def release(self) -> None:
# wake the writer and we're done.
self._writer = task
self._waiting_writers_count -= 1
trio.hazmat.reschedule(task)
trio.lowlevel.reschedule(task)
break
else:
# Next task is a writer, but can't be woken because
Expand All @@ -202,7 +202,7 @@ def _wake_all_readers(self) -> None:
if not for_write:
del self._waiting[task]
self._readers.add(task)
trio.hazmat.reschedule(task)
trio.lowlevel.reschedule(task)

# https://github.com/python/mypy/issues/1362: mypy doesn't support
# decorated properties yet
Expand All @@ -215,7 +215,7 @@ def read_biased(self) -> bool:
return self._read_biased

@read_biased.setter
@trio.hazmat.enable_ki_protection
@trio.lowlevel.enable_ki_protection
def read_biased(self, new_value: bool) -> None:
if new_value and not self._read_biased:
self._wake_all_readers()
Expand All @@ -237,7 +237,7 @@ async def acquire_write(self) -> None:
"""Equivalent to ``acquire(for_write=True)``."""
return await self.acquire(for_write=True)

@trio.hazmat.enable_ki_protection
@trio.lowlevel.enable_ki_protection
@asynccontextmanager
async def read_locked(self) -> AsyncIterator[None]:
"""Returns an async context manager whose ``__aenter__`` blocks
Expand All @@ -250,7 +250,7 @@ async def read_locked(self) -> AsyncIterator[None]:
finally:
self.release()

@trio.hazmat.enable_ki_protection
@trio.lowlevel.enable_ki_protection
@asynccontextmanager
async def write_locked(self) -> AsyncIterator[None]:
"""Returns an async context manager whose ``__aenter__`` blocks
Expand All @@ -272,9 +272,9 @@ def statistics(self) -> _RWLockStatistics:
* ``state``: string with one of the values ``"read"`` (held by one
or more readers), ``"write"`` (held by one writer),
or ``"unlocked"`` (held by no one)
* ``readers``: a frozenset of the :class:`~trio.hazmat.Task`\s
* ``readers``: a frozenset of the :class:`~trio.lowlevel.Task`\s
currently holding the lock in read mode (may be empty)
* ``writer``: the :class:`trio.hazmat.Task` currently holding
* ``writer``: the :class:`trio.lowlevel.Task` currently holding
the lock in write mode, or None if the lock is not held in write mode
* ``readers_waiting``: the number of tasks blocked waiting to acquire
the lock in read mode
Expand Down
4 changes: 2 additions & 2 deletions tricycle/_service_nursery.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _get_coroutine_or_flag_problem(
# If we're not happy with this async_fn, trio won't be either,
# and will tell us why in much greater detail.
try:
trio.hazmat.spawn_system_task(probe_fn, *args)
trio.lowlevel.spawn_system_task(probe_fn, *args)
except TypeError as ex:
problem_with_async_fn = ex
else:
Expand Down Expand Up @@ -101,7 +101,7 @@ async def wrap_child(*, task_status: TaskStatus[Any]) -> None:

def wrap_started(value: object = None) -> None:
type(task_status).started(task_status, value) # type: ignore
if trio.hazmat.current_task().parent_nursery is not nursery:
if trio.lowlevel.current_task().parent_nursery is not nursery:
# started() didn't move the task due to a cancellation,
# so it doesn't get the shield
return
Expand Down
6 changes: 3 additions & 3 deletions tricycle/_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def receive(self, num_bytes: int) -> bytes:
break # EOF
self._buffer.extend(data)
else:
await trio.hazmat.checkpoint()
await trio.lowlevel.checkpoint()

data = self._buffer[self._receive_pos : self._receive_pos + num_bytes]
self._receive_pos += len(data)
Expand Down Expand Up @@ -272,7 +272,7 @@ async def receive_line(self, max_chars: int = -1) -> str:
"""

await trio.hazmat.checkpoint_if_cancelled()
await trio.lowlevel.checkpoint_if_cancelled()

got_more = False
line_end_pos = None
Expand Down Expand Up @@ -356,7 +356,7 @@ async def receive_line(self, max_chars: int = -1) -> str:
if not got_more:
# If we never called receive_some(), we only did half a checkpoint,
# and need to do the other half before returning.
await trio.hazmat.cancel_shielded_checkpoint()
await trio.lowlevel.cancel_shielded_checkpoint()

ret = self._chunk[self._chunk_pos : line_end_pos]
self._chunk_pos = line_end_pos
Expand Down
8 changes: 4 additions & 4 deletions tricycle/_tests/test_multi_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ async def shield_child_when_parent_shielded() -> None:

async def shield_child_after_parent_unshielded() -> None:
with parent.open_child(shield=True) as child:
this_task = trio.hazmat.current_task()
this_task = trio.lowlevel.current_task()

def abort_fn(_): # type: ignore
trio.hazmat.reschedule(this_task)
return trio.hazmat.Abort.FAILED
trio.lowlevel.reschedule(this_task)
return trio.lowlevel.Abort.FAILED

await trio.hazmat.wait_task_rescheduled(abort_fn)
await trio.lowlevel.wait_task_rescheduled(abort_fn)
child.shield = True
await trio.sleep(0.5)
assert not child.cancelled_caught
Expand Down
8 changes: 4 additions & 4 deletions tricycle/_tests/test_rwlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ async def test_rwlock(autojump_clock: trio.testing.MockClock) -> None:
acquire_times: List[Optional[float]] = [None] * 10

async def holder_task(
for_write: bool, task_status: TaskStatus[trio.hazmat.Task]
for_write: bool, task_status: TaskStatus[trio.lowlevel.Task]
) -> None:
my_slot = next(start_order)
repr(lock) # smoke test
task_status.started(trio.hazmat.current_task())
task_status.started(trio.lowlevel.current_task())
await lock.acquire(for_write=for_write)
acquire_times[my_slot] = trio.current_time()
try:
Expand Down Expand Up @@ -150,9 +150,9 @@ async def test_read_biased(autojump_clock: trio.testing.MockClock) -> None:
assert lock.read_biased

async def holder_task(
for_write: bool, task_status: TaskStatus[trio.hazmat.Task]
for_write: bool, task_status: TaskStatus[trio.lowlevel.Task]
) -> None:
task_status.started(trio.hazmat.current_task())
task_status.started(trio.lowlevel.current_task())
await lock.acquire(for_write=for_write)
try:
await trio.sleep(1)
Expand Down

0 comments on commit 703035a

Please sign in to comment.