Skip to content
Merged
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
1 change: 0 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ serialize =
[bumpversion:file:docs/includes/introduction.txt]

[bumpversion:file:README.rst]

1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ Paste the full traceback (if there is any)
* Python version
* Mode version
* Operating system

30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/ambv/black
rev: 21.9b0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.9.3
hooks:
- id: isort
name: isort (python)

- repo: local
hooks:
- id: flake8
name: flake8
stages: [commit]
language: python
entry: flake8
types: [python]
23 changes: 15 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ matrix:
- python: 3.8.6
env: TOXENV=flake8
os: linux
dist: focal
dist: bionic
stage: lint
- python: 3.8.6
env: TOXENV=typecheck
os: linux
dist: focal
dist: bionic
stage: lint
- python: 3.8.6
env: TOXENV=apicheck
os: linux
dist: focal
dist: bionic
stage: lint
- python: 3.8.6
env: TOXENV=docstyle
os: linux
dist: focal
dist: bionic
stage: lint
- python: 3.8.6
env: TOXENV=bandit
os: linux
dist: focal
dist: bionic
stage: lint
- python: 3.6.3
env: TOXENV=3.6 RUN_SUITE=y
Expand Down Expand Up @@ -142,10 +142,17 @@ matrix:
os: linux
dist: focal
stage: test
- python: 3.9.1
env: TOXENV=3.9 IDENT="3.9.1" RUN_SUITE=y
- name: Latest python-3.9
python: 3.9
env: TOXENV=3.9 IDENT="3.9" RUN_SUITE=y
os: linux
dist: xenial
dist: bionic
stage: test
- name: Latest python-3.10
python: 3.10.0
env: TOXENV=3.10 IDENT="3.10" RUN_SUITE=y
os: linux
dist: bionic
stage: test

before_install:
Expand Down
1 change: 0 additions & 1 deletion CODE_OF_CONDUCT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ reported by opening an issue or contacting one or more of the project maintainer

This Code of Conduct is adapted from the Contributor Covenant,
version 1.2.0 available at http://contributor-covenant.org/version/1/2/0/.

1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,3 @@ version 1.2.0 available at http://contributor-covenant.org/version/1/2/0/.
.. |pyimp| image:: https://img.shields.io/pypi/implementation/mode-streaming.svg
:alt: Supported Python implementations.
:target: http://pypi.org/project/mode-streaming/

1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

1 change: 0 additions & 1 deletion docs/reference/mode.loop.eventlet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@

Importing this module directly will set the global event loop.
See :mod:`faust.loop` for more information.

1 change: 0 additions & 1 deletion docs/reference/mode.loop.gevent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@

Importing this module directly will set the global event loop.
See :mod:`faust.loop` for more information.

1 change: 0 additions & 1 deletion docs/reference/mode.loop.uvloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@

Importing this module directly will set the global event loop.
See :mod:`faust.loop` for more information.

2 changes: 1 addition & 1 deletion extra/bandit/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,4 @@
"test_name": "try_except_pass"
}
]
}
}
1 change: 0 additions & 1 deletion extra/bandit/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,3 @@ weak_cryptographic_key:
weak_key_size_ec_medium: 224
weak_key_size_rsa_high: 1024
weak_key_size_rsa_medium: 2048

8 changes: 4 additions & 4 deletions mode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import re
import sys
import typing

# Lazy loading.
# - See werkzeug/__init__.py for the rationale behind this.
from types import ModuleType # noqa
from typing import Any, Mapping, NamedTuple, Sequence

__version__ = "0.1.0"
Expand Down Expand Up @@ -89,10 +93,6 @@ class version_info_t(NamedTuple):
]


# Lazy loading.
# - See werkzeug/__init__.py for the rationale behind this.
from types import ModuleType # noqa

all_by_module: Mapping[str, Sequence[str]] = {
"mode.services": ["Service", "task", "timer"],
"mode.signals": ["BaseSignal", "Signal", "SyncSignal"],
Expand Down
2 changes: 1 addition & 1 deletion mode/loop/eventlet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Enable :pypi:`eventlet` support for :mod:`asyncio`."""
import asyncio # noqa: E402,I100,I202
import os

os.environ["GEVENT_LOOP"] = "mode.loop._gevent_loop.Loop"
Expand All @@ -18,7 +19,6 @@
"Eventlet loop requires the aioeventlet library: " "pip install aioeventlet"
) from None

import asyncio # noqa: E402,I100,I202

if asyncio._get_running_loop() is not None:
raise RuntimeError("Event loop created before importing eventlet loop!")
Expand Down
4 changes: 2 additions & 2 deletions mode/loop/gevent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Enable :pypi:`gevent` support for :mod:`asyncio`."""
import asyncio # noqa: E402,I100,I202
import os
import warnings
from typing import Optional, cast # noqa: F401,E402

os.environ["GEVENT_LOOP"] = "mode.loop._gevent_loop.Loop"
try:
Expand All @@ -11,7 +13,6 @@
"Gevent loop requires the gevent library: " "pip install gevent"
) from None
gevent.monkey.patch_all()
from typing import Optional, cast # noqa: F401,E402

try:
import psycopg2 # noqa: F401
Expand All @@ -33,7 +34,6 @@
"Gevent loop requires the aiogevent library: " "pip install aiogevent"
) from None

import asyncio # noqa: E402,I100,I202

if asyncio._get_running_loop() is not None:
raise RuntimeError("Event loop created before importing gevent loop!")
Expand Down
5 changes: 0 additions & 5 deletions mode/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ async def sleep(
await asyncio.wait_for(
self._stopped.wait(),
timeout=want_seconds(n),
loop=loop or self.loop,
)
except asyncio.TimeoutError:
pass
Expand All @@ -716,7 +715,6 @@ async def wait_many(
cast(Iterable[Awaitable[Any]], coros),
return_when=asyncio.ALL_COMPLETED,
timeout=want_seconds(timeout),
loop=self.loop,
)
return await self._wait_one(coro, timeout=timeout)

Expand Down Expand Up @@ -747,7 +745,6 @@ async def wait_first(
futures.values(),
return_when=asyncio.FIRST_COMPLETED,
timeout=timeout,
loop=self.loop,
)
for f in done:
if f.done() and f.exception() is not None:
Expand Down Expand Up @@ -784,7 +781,6 @@ async def _wait_stopped(self, timeout: Seconds = None) -> None:
[stopped, crashed],
return_when=asyncio.FIRST_COMPLETED,
timeout=timeout,
loop=self.loop,
)
for fut in done:
fut.result() # propagate exceptions
Expand Down Expand Up @@ -971,7 +967,6 @@ async def _wait_for_futures(self, *, timeout: float = None) -> None:
await asyncio.wait(
self._futures,
return_when=asyncio.ALL_COMPLETED,
loop=self.loop,
timeout=timeout,
)

Expand Down
1 change: 0 additions & 1 deletion mode/supervisors.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ async def stop_services(self, services: List[ServiceT]) -> None:
# Stop them all simultaneously.
await asyncio.gather(
*[service.stop() for service in services],
loop=self.loop,
)

async def restart_service(self, service: ServiceT) -> None:
Expand Down
6 changes: 2 additions & 4 deletions mode/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,9 @@ class MethodQueue(Service):

mundane_level = "debug"

def __init__(
self, loop: asyncio.AbstractEventLoop, num_workers: int = 2, **kwargs: Any
) -> None:
def __init__(self, num_workers: int = 2, **kwargs: Any) -> None:
super().__init__(**kwargs)
self._queue = asyncio.Queue(loop=self.loop)
self._queue = asyncio.Queue()
self._queue_ready = Event(loop=self.loop)
self.num_workers = num_workers
self._workers = []
Expand Down
4 changes: 2 additions & 2 deletions mode/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def format(self, record: logging.LogRecord) -> str:
return super().format(record)


class ExtensionFormatter(colorlog.TTYColoredFormatter): # type: ignore
class ExtensionFormatter(colorlog.TTYColoredFormatter):
"""Formatter that can register callbacks to format args.

Extends :pypi:`colorlog`.
Expand All @@ -331,7 +331,7 @@ def __init__(self, stream: IO = None, **kwargs: Any) -> None:
def format(self, record: logging.LogRecord) -> str:
self._format_args(record)
record.extra = _format_extra(record) # type: ignore
return cast(str, super().format(record))
return cast(str, super().format(record)) # type: ignore

def _format_args(self, record: logging.LogRecord) -> None:
format_arg = self.format_arg
Expand Down
2 changes: 1 addition & 1 deletion mode/utils/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def __aenter__(self) -> "Bucket":
if self.raises:
raise self.raises()
expected_time = self.expected_time()
await asyncio.sleep(expected_time, loop=self.loop)
await asyncio.sleep(expected_time)
return self

async def __aexit__(
Expand Down
2 changes: 1 addition & 1 deletion mode/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _shutdown_loop(self) -> None:
raise self.crash_reason from self.crash_reason

async def _sentinel_task(self) -> None:
await asyncio.sleep(1.0, loop=self.loop)
await asyncio.sleep(1.0)

def _gather_all(self) -> None:
# sleeps for at most 10 * 0.1s
Expand Down
3 changes: 1 addition & 2 deletions requirements/flakes.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
flake8>=2.5.4
flake8>=4.0.0
flake8-bandit
flake8-bugbear
flake8-builtins-unleashed
flake8-comprehensions
flake8-debugger
flake8-isort
flake8-logging-format
flake8-mock
flake8-pep3101
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ universal = 1
ignore = N806, N802, N801, N803, I100, I201, I202, B008, W504, G200, S101, E203, E266, E501, W503
enable-extensions = G
max-line-length = 88
per-file-ignores =
t/*: S301,S403


#[pep257]
#ignore = D102,D104,D203,D105,D213
Expand Down Expand Up @@ -82,3 +85,4 @@ warn_unused_ignores = True

[isort]
profile=black
known_first_party=mode
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def _pyimp():

NAME = "mode-streaming"
EXTENSIONS = {"eventlet", "gevent", "uvloop"}
E_UNSUPPORTED_PYTHON = "%s 1.0 requires %%s %%s or later!" % (NAME,)
E_UNSUPPORTED_PYTHON = "%s 1.0 requires %%s %%s or later!" % (NAME,) # noqa: S001

PYIMP = _pyimp()
if sys.version_info < (3, 6):
raise Exception(E_UNSUPPORTED_PYTHON % (PYIMP, "3.6"))
raise Exception(E_UNSUPPORTED_PYTHON % (PYIMP, "3.6")) # noqa: S001

from pathlib import Path # noqa

Expand Down
2 changes: 1 addition & 1 deletion t/functional/utils/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def test_suspend_resume__clear_on_resume(self):
time_now = monotonic()
await queue.put(2)
assert monotonic() - time_now > 0.1
await queue.get() == 2
assert await queue.get() == 2

@pytest.mark.asyncio
async def test_suspend_resume__initially_suspended(self):
Expand Down
5 changes: 1 addition & 4 deletions t/unit/test_services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
from time import sleep
from typing import ContextManager

import pytest
Expand Down Expand Up @@ -123,7 +122,7 @@ class ATaskService(Service):
values = []

def __post_init__(self):
self.event = asyncio.Event(loop=self.loop)
self.event = asyncio.Event()

@Service.task
async def _background_task(self):
Expand Down Expand Up @@ -343,7 +342,6 @@ async def test__wait_stopped(self, *, service):
],
return_when=asyncio.FIRST_COMPLETED,
timeout=1.0,
loop=service.loop,
)

for fut in done:
Expand Down Expand Up @@ -553,7 +551,6 @@ async def test_wait_many(self, *, service):
[m1, m2],
return_when=asyncio.ALL_COMPLETED,
timeout=3.34,
loop=service.loop,
)

service._wait_one.assert_called_once_with(ANY, timeout=3.34)
Expand Down
Loading