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
34 changes: 15 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
name: nox

on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
on: push

jobs:
build_linux:
nox_linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
pipx install nox uv
- name: nox
run: |
nox
- run: pipx install nox uv
- run: nox

build_windows:
nox_windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
pipx install nox uv
- name: nox
run: |
nox
- run: pipx install nox uv
- run: nox -p 3.13 # Only test on 3.13 because Windows CI is so slow.

nox_macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- run: pipx install nox uv
- run: nox
20 changes: 6 additions & 14 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nox
import sys

nox.options.default_venv_backend = "uv|virtualenv"
py_versions = ("3.10", "3.11", "3.12", "3.13")
Expand All @@ -7,21 +8,12 @@
@nox.session(python=py_versions)
def tests(session):
session.install(".")
session.install(
"complexipy",
"cryptography",
"mypy",
"pytest",
"pytest-cov",
"pytest-mock",
"pyyaml",
"ruff",
"typing_extensions",
"typos",
)
session.install("--group", "dev")
session.run("ruff", "check")
session.run("typos")
session.run("mypy")
session.run("complexipy", "-d", "low", "ohmqtt", "examples")
if sys.platform != "win32":
session.run("complexipy", "-d", "low", "ohmqtt", "examples")
else:
session.log("Skipping complexipy check on Windows: https://github.com/rohaquinlop/complexipy/issues/67")
session.run("pytest", "--cov-report=term-missing")

6 changes: 3 additions & 3 deletions ohmqtt/connection/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Final, Mapping
from urllib.parse import urlparse, ParseResult

from ..platform import HAS_AF_UNIX
from ..platform import AF_UNIX, HAS_AF_UNIX


DEFAULT_PORTS: Final[Mapping[str, int]] = {
Expand All @@ -25,7 +25,7 @@ def is_ipv6(hostname: str) -> bool:
def _get_family(parsed: ParseResult) -> socket.AddressFamily:
"""Get the address family based on the parsed URL scheme."""
if HAS_AF_UNIX and parsed.scheme == "unix":
return socket.AF_UNIX
return AF_UNIX
elif parsed.scheme in ("mqtt", "mqtts"):
if not parsed.hostname:
raise ValueError("Hostname is required for mqtt and mqtts schemes")
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, address: str = "") -> None:
object.__setattr__(self, "host", parsed.hostname or parsed.path)
if not self.host:
raise ValueError("No path in address")
if HAS_AF_UNIX and self.family == socket.AF_UNIX and self.host == "/":
if HAS_AF_UNIX and self.family == AF_UNIX and self.host == "/":
raise ValueError("'/' is not a valid Unix socket path")
object.__setattr__(self, "port", parsed.port if parsed.port is not None else DEFAULT_PORTS[parsed.scheme])
object.__setattr__(self, "username", parsed.username)
Expand Down
4 changes: 2 additions & 2 deletions ohmqtt/connection/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..logger import get_logger
from ..mqtt_spec import MQTTPacketType, MQTTReasonCode
from ..packet import MQTTConnectPacket, MQTTConnAckPacket, MQTTDisconnectPacket, PING, PONG
from ..platform import HAS_AF_UNIX
from ..platform import AF_UNIX, HAS_AF_UNIX

logger: Final = get_logger("connection.states")

Expand Down Expand Up @@ -48,7 +48,7 @@ def handle(cls, fsm: FSM, state_data: StateData, env: StateEnvironment, params:

try:
address = params.address
if HAS_AF_UNIX and address.family == socket.AF_UNIX:
if HAS_AF_UNIX and address.family == AF_UNIX:
state_data.sock.connect(address.host)
else:
state_data.sock.connect((address.host, address.port))
Expand Down
10 changes: 8 additions & 2 deletions ohmqtt/platform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import socket
from typing import Final
import sys
from typing import cast, Final


HAS_AF_UNIX: Final = hasattr(socket, "AF_UNIX")
HAS_AF_UNIX: Final = sys.platform != "win32"

if sys.platform == "win32":
AF_UNIX: Final = cast(socket.AddressFamily, 1)
else:
AF_UNIX: Final = socket.AF_UNIX
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ dependencies = [

[dependency-groups]
dev = [
"complexipy>=2.1.1",
"complexipy>=2.1.1; platform_system != 'Windows'",
"cryptography>=44.0.2",
"mypy>=1.15.0",
"pympler>=1.1",
"pytest>=8.3.5",
"pytest-cov>=6.0.0",
"pytest-mock>=3.14.0",
"pyyaml>=6.0.2",
"ruff>=0.11.2",
"typos>=1.31.1",
"yappi>=1.6.10",
]

[tool.mypy]
Expand Down