Skip to content
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

Linting & Testing #9

Merged
merged 11 commits into from
Jan 17, 2022
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
27 changes: 26 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# The following rules are incompatible with or enforced by black:
# E203 whitespace before ':' -- scripts only
# E301 expected 1 blank line -- stubs only
# E302 expected 2 blank lines -- stubs only
# E305 expected 2 blank lines -- stubs only
# E501 line too long

# Some rules are considered irrelevant to stub files:
# E701 multiple statements on one line (colon) -- disallows "..." on the same line
# F401 imported but unused -- does not recognize re-exports
# https://github.com/PyCQA/pyflakes/issues/474
# F822 undefined name in __all__ -- flake8 does not recognize 'foo: Any'
# https://github.com/PyCQA/pyflakes/issues/533

# Rules that are out of the control of stub authors:
# E741 ambiguous variable name
# F403 import *' used; unable to detect undefined names
# F405 defined from star imports

[flake8]
max-line-length = 99
per-file-ignores =
*.py: E203, E501
*.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822
typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822

exclude =
.venv,
.idea,
.mypy_cache,
.git
48 changes: 27 additions & 21 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,35 @@ on: [push, pull_request]

jobs:
check:
name: Run tests

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Perform checks
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
flake8 pika-stubs
mypy -p pika-stubs --strict
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements-dev.txt'

- name: Update pip
run: python -m pip install -U pip

- name: Install dependencies
run: pip install -r requirements-dev.txt .[dev]

- name: Lint with flake8
run: flake8

- name: Check stub files with mypy
run: mypy --strict -p pika-stubs

- name: Stubtest
run: stubtest --concise pika
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ warn_unused_ignores = True
warn_unused_configs = True
warn_unreachable = True

show_error_codes = True

files =
pika-stubs
12 changes: 5 additions & 7 deletions pika-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from .connection import ConnectionParameters as ConnectionParameters
from .connection import SSLOptions as SSLOptions
from .connection import URLParameters as URLParameters
from .credentials import PlainCredentials as PlainCredentials
from .spec import BasicProperties as BasicProperties

from . import adapters
from .adapters import BaseConnection as BaseConnection
from .adapters import BlockingConnection as BlockingConnection
from .adapters import SelectConnection as SelectConnection

from .adapters.utils.connection_workflow import AMQPConnectionWorkflow as AMQPConnectionWorkflow
from .connection import ConnectionParameters as ConnectionParameters
from .connection import SSLOptions as SSLOptions
from .connection import URLParameters as URLParameters
from .credentials import PlainCredentials as PlainCredentials
from .spec import BasicProperties as BasicProperties
7 changes: 4 additions & 3 deletions pika-stubs/adapters/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .base_connection import BaseConnection as BaseConnection # noqa: F401
from .blocking_connection import BlockingConnection as BlockingConnection # noqa: F401
from .select_connection import IOLoop as IOLoop, SelectConnection as SelectConnection # noqa: F401
from .base_connection import BaseConnection as BaseConnection
from .blocking_connection import BlockingConnection as BlockingConnection
from .select_connection import IOLoop as IOLoop
from .select_connection import SelectConnection as SelectConnection
38 changes: 18 additions & 20 deletions pika-stubs/adapters/asyncio_connection.pyi
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
from __future__ import annotations

import asyncio
from typing import Callable, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Callable

from .. import connection
from . import base_connection
from .utils import connection_workflow

_OnCloseCallback = Callable[['AsyncioConnection', Exception], None]
_OnOpenCallback = Callable[['AsyncioConnection'], None]
_OnOpenErrorCallback = Callable[['AsyncioConnection', Union[str, Exception]], None]

_OnCloseCallback = Callable[[AsyncioConnection, Exception], None]
_OnOpenCallback = Callable[[AsyncioConnection], None]
_OnOpenErrorCallback = Callable[[AsyncioConnection, str | Exception], None]

class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop]):

def __init__(
self,
parameters: Optional[connection.Parameters] = None,
on_open_callback: Optional[_OnOpenCallback] = None,
on_open_error_callback: Optional[_OnOpenErrorCallback] = None,
on_close_callback: Optional[_OnCloseCallback] = None,
custom_ioloop: Optional[asyncio.AbstractEventLoop] = None,
parameters: connection.Parameters | None = ...,
on_open_callback: _OnOpenCallback | None = ...,
on_open_error_callback: _OnOpenErrorCallback | None = ...,
on_close_callback: _OnCloseCallback | None = ...,
custom_ioloop: asyncio.AbstractEventLoop | None = ...,
internal_connection_workflow: bool = ...,
) -> None: ...

@classmethod
def create_connection(
cls,
connection_configs: Sequence[connection.Parameters],
on_done: Callable[
[
Union[
connection.Connection,
connection_workflow.AMQPConnectionWorkflowFailed,
connection_workflow.AMQPConnectionWorkflowAborted,
],
connection.Connection
| connection_workflow.AMQPConnectionWorkflowFailed
| connection_workflow.AMQPConnectionWorkflowAborted
],
None
None,
],
custom_ioloop: Optional[asyncio.AbstractEventLoop] = ...,
workflow: Optional[connection_workflow.AbstractAMQPConnectionWorkflow] = ...,
custom_ioloop: asyncio.AbstractEventLoop | None = ...,
workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ...,
) -> connection_workflow.AbstractAMQPConnectionWorkflow: ...
44 changes: 22 additions & 22 deletions pika-stubs/adapters/base_connection.pyi
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
from __future__ import annotations

import abc
from typing import Callable, Generic, Optional, Sequence, TypeVar, Union
from collections.abc import Sequence
from typing import Callable
from typing import Generic
from typing import TypeVar

from .. import connection
from .utils import connection_workflow, nbio_interface

_OnCloseCallback = Callable[['BaseConnection', Exception], None]
_OnOpenCallback = Callable[['BaseConnection'], None]
_OnOpenErrorCallback = Callable[['BaseConnection', Union[str, Exception]], None]
from .utils import connection_workflow
from .utils import nbio_interface

_IOLoop = TypeVar('_IOLoop')
_OnCloseCallback = Callable[[BaseConnection, Exception], None]
_OnOpenCallback = Callable[[BaseConnection], None]
_OnOpenErrorCallback = Callable[[BaseConnection, str | Exception], None]

_IOLoop = TypeVar("_IOLoop")

class BaseConnection(Generic[_IOLoop], connection.Connection):

def __init__(
self,
parameters: Optional[connection.Parameters],
on_open_callback: Optional[_OnOpenCallback],
on_open_error_callback: Optional[_OnOpenErrorCallback],
on_close_callback: Optional[_OnCloseCallback],
parameters: connection.Parameters | None,
on_open_callback: _OnOpenCallback | None,
on_open_error_callback: _OnOpenErrorCallback | None,
on_close_callback: _OnCloseCallback | None,
nbio: nbio_interface.AbstractIOServices,
internal_connection_workflow: bool,
) -> None: ...

@classmethod
@abc.abstractmethod
def create_connection(
cls,
connection_configs: Sequence[connection.Parameters],
on_done: Callable[
[
Union[
connection.Connection,
connection_workflow.AMQPConnectionWorkflowFailed,
connection_workflow.AMQPConnectionWorkflowAborted,
],
connection.Connection
| connection_workflow.AMQPConnectionWorkflowFailed
| connection_workflow.AMQPConnectionWorkflowAborted
],
None
None,
],
custom_ioloop: Optional[_IOLoop] = ...,
workflow: Optional[connection_workflow.AbstractAMQPConnectionWorkflow] = ...,
custom_ioloop: _IOLoop | None = ...,
workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ...,
) -> connection_workflow.AbstractAMQPConnectionWorkflow: ...

@property
def ioloop(self) -> _IOLoop: ...
Loading