From 9c956e5a34e2844abae115c0375572ea2c747fa2 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Tue, 16 Apr 2024 16:16:22 +0000 Subject: [PATCH] ci: make sure to generate _version.py with version metadata --- .gitignore | 8 ++++++++ asyncirc/__init__.py | 9 +++++++-- asyncirc/protocol.py | 10 +++++----- asyncirc/server.py | 2 +- pyproject.toml | 20 ++++++-------------- tests/test_protocol.py | 11 +++++------ 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 7eb69c4..0baa9a3 100644 --- a/.gitignore +++ b/.gitignore @@ -175,3 +175,11 @@ Session.vim .netrwhist # auto-generated tag files tags + +asyncirc/_version.py + +.mypy_cache/ +.pytest_cache/ +.ruff_cache/ +coverage.* +.coverage.* diff --git a/asyncirc/__init__.py b/asyncirc/__init__.py index 69d0866..b3c59dc 100644 --- a/asyncirc/__init__.py +++ b/asyncirc/__init__.py @@ -2,6 +2,11 @@ Async IRC Interface Library """ -__all__ = ("protocol", "server") +from asyncirc._version import ( + __version__, + __version_tuple__, + version, + version_tuple, +) -__version__ = "0.1.8" +__all__ = ("version", "version_tuple", "__version__", "__version_tuple__") diff --git a/asyncirc/protocol.py b/asyncirc/protocol.py index d229915..a5cbd43 100644 --- a/asyncirc/protocol.py +++ b/asyncirc/protocol.py @@ -33,7 +33,7 @@ from asyncio import AbstractEventLoop, Transport from logging import Logger - from asyncirc.server import BaseServer, Server + from asyncirc.server import BaseServer __all__ = ("SASLMechanism", "IrcProtocol") @@ -161,7 +161,7 @@ async def _do_sasl(conn: "IrcProtocol", cap: Cap) -> None: conn.send(f"AUTHENTICATE {auth_line}") # Wait for SASL to complete - # TODO log SASL response + # TODO(linuxdaemon): log SASL response await conn.wait_for( "902", "903", "904", "905", "906", "907", "908", timeout=30 ) @@ -205,7 +205,7 @@ class IrcProtocol(Protocol): def __init__( self, - servers: Sequence["Server"], + servers: Sequence["BaseServer"], nick: str, user: Optional[str] = None, realname: Optional[str] = None, @@ -344,10 +344,10 @@ async def _connect(self, server: "BaseServer") -> bool: ) return False - except (ConnectionError, socket.gaierror) as e: + except (ConnectionError, socket.gaierror): if self.logger: self.logger.exception( - "Error occurred while connecting to %s (%s)", self.server, e + "Error occurred while connecting to %s", self.server ) return False diff --git a/asyncirc/server.py b/asyncirc/server.py index 928d12d..ec52aa9 100644 --- a/asyncirc/server.py +++ b/asyncirc/server.py @@ -29,7 +29,7 @@ def __init__( is_ssl: bool = False, ssl_ctx: Optional[ssl.SSLContext] = None, certpath: Optional[str] = None, - ): + ) -> None: if is_ssl: if ssl_ctx is None: ssl_ctx = ssl.create_default_context() diff --git a/pyproject.toml b/pyproject.toml index aa6bd27..8c77e68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,16 +9,8 @@ description = "A simple asyncio.Protocol implementation designed for IRC" readme = "README.md" license = "MIT" requires-python = ">=3.8" -authors = [ - { name = "linuxdaemon", email = "linuxdaemon@snoonet.org" }, -] -keywords = [ - "async-irc", - "asyncio", - "asyncirc", - "irc", - "irc-framework", -] +authors = [{ name = "linuxdaemon", email = "linuxdaemon.irc@gmail.com" }] +keywords = ["async-irc", "asyncio", "asyncirc", "irc", "irc-framework"] classifiers = [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", @@ -29,10 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] -dependencies = [ - "py-irclib>=0.4.0", - "typing_extensions", -] +dependencies = ["py-irclib>=0.4.0", "typing_extensions"] [project.urls] Homepage = "https://github.com/TotallyNotRobots/async-irc" @@ -46,6 +35,9 @@ exclude = ["/.github"] [tool.hatch.build.targets.wheel] packages = ["asyncirc"] +[tool.hatch.build.hooks.vcs] +version-file = "asyncirc/_version.py" + [tool.hatch.env] requires = ["hatch-containers"] diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 647fbaa..79d3c0e 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -61,8 +61,6 @@ def write(self, data: bytes) -> None: self._server.send_line(Message.parse(":irc.example.com 903")) elif msg.command == "QUIT": self._protocol.connection_lost(None) - else: - print(f"unhandled command: {msg}") if not self._registered: if ( @@ -99,9 +97,10 @@ def __init__( ) self.lines: List[Tuple[str, str]] = [] self.in_buffer = b"" - self.transport = None + self.transport: Optional[MockTransport] = None - def send_line(self, msg: Message): + def send_line(self, msg: Message) -> None: + assert self.transport is not None self.transport.get_protocol().data_received(str(msg).encode() + b"\r\n") async def connect( @@ -118,9 +117,9 @@ async def connect( async def test_sasl() -> None: - fut = asyncio.Future() + fut: "asyncio.Future[None]" = asyncio.Future() - async def _on_001(conn, msg): + async def _on_001(_conn: "IrcProtocol", _msg: "Message") -> None: fut.set_result(None) server = MockServer()