Skip to content

Commit

Permalink
Hotfix for the broken build on master (#195)
Browse files Browse the repository at this point in the history
* Replace the MyPy re-export workaround with the recommended solution (see linked issue)

* Robustify a fragile test by removing the hard-coded UDP port number
  • Loading branch information
pavel-kirienko committed Dec 10, 2021
1 parent e0ec0fb commit 99ef434
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pyuavcan/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
23 changes: 12 additions & 11 deletions pyuavcan/application/file.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Copyright (c) 2021 UAVCAN Consortium
# This software is distributed under the terms of the MIT License.
# Author: Pavel Kirienko <pavel@uavcan.org>
#
# Workaround for the odd behavior of MyPy https://github.com/python/mypy/issues/11706
# mypy: implicit_reexport=True

from __future__ import annotations
import os
Expand All @@ -16,14 +13,18 @@
import numpy as np
import pyuavcan
import pyuavcan.application
from uavcan.file import Path_2 as Path
from uavcan.file import Error_1 as Error
from uavcan.file import Read_1 as Read
from uavcan.file import Write_1 as Write
from uavcan.file import List_0 as List
from uavcan.file import GetInfo_0 as GetInfo
from uavcan.file import Modify_1 as Modify
from uavcan.primitive import Unstructured_1 as Unstructured
import uavcan.file
import uavcan.primitive

# import X as Y is not an accepted form; see https://github.com/python/mypy/issues/11706
Path = uavcan.file.Path_2
Error = uavcan.file.Error_1
Read = uavcan.file.Read_1
Write = uavcan.file.Write_1
List = uavcan.file.List_0
GetInfo = uavcan.file.GetInfo_0
Modify = uavcan.file.Modify_1
Unstructured = uavcan.primitive.Unstructured_1


class FileServer:
Expand Down
7 changes: 3 additions & 4 deletions pyuavcan/application/plug_and_play.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Copyright (c) 2020 UAVCAN Consortium
# This software is distributed under the terms of the MIT License.
# Author: Pavel Kirienko <pavel@uavcan.org>
#
# Workaround for the odd behavior of MyPy https://github.com/python/mypy/issues/11706
# mypy: implicit_reexport=True

"""
Plug-and-play node-ID allocation logic. See the class documentation for usage info.
Expand All @@ -22,12 +19,14 @@
import pathlib
import logging
import sqlite3
import uavcan.node
from uavcan.pnp import NodeIDAllocationData_1 as NodeIDAllocationData_1
from uavcan.pnp import NodeIDAllocationData_2 as NodeIDAllocationData_2
from uavcan.node import ID_1 as ID
import pyuavcan
import pyuavcan.application

# import X as Y is not an accepted form; see https://github.com/python/mypy/issues/11706
ID = uavcan.node.ID_1

_PSEUDO_UNIQUE_ID_MASK = (
2 ** pyuavcan.dsdl.get_model(NodeIDAllocationData_1)["unique_id_hash"].data_type.bit_length_set.max - 1
Expand Down
39 changes: 21 additions & 18 deletions pyuavcan/application/register/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
# Copyright (C) 2021 UAVCAN Consortium <uavcan.org>
# This software is distributed under the terms of the MIT License.
# Author: Pavel Kirienko <pavel@uavcan.org>
#
# Workaround for the odd behavior of MyPy https://github.com/python/mypy/issues/11706
# mypy: implicit_reexport=True

# pylint: disable=wrong-import-position

"""
Implementation of the UAVCAN register interface as defined in the UAVCAN Specification
(section 5.3 *Application-layer functions*).
"""

from uavcan.primitive import Empty_1 as Empty
from uavcan.primitive import String_1 as String
from uavcan.primitive import Unstructured_1 as Unstructured
from uavcan.primitive.array import Bit_1 as Bit
from uavcan.primitive.array import Integer64_1 as Integer64
from uavcan.primitive.array import Integer32_1 as Integer32
from uavcan.primitive.array import Integer16_1 as Integer16
from uavcan.primitive.array import Integer8_1 as Integer8
from uavcan.primitive.array import Natural64_1 as Natural64
from uavcan.primitive.array import Natural32_1 as Natural32
from uavcan.primitive.array import Natural16_1 as Natural16
from uavcan.primitive.array import Natural8_1 as Natural8
from uavcan.primitive.array import Real64_1 as Real64
from uavcan.primitive.array import Real32_1 as Real32
from uavcan.primitive.array import Real16_1 as Real16
import uavcan.primitive
import uavcan.primitive.array

# import X as Y is not an accepted form; see https://github.com/python/mypy/issues/11706
Empty = uavcan.primitive.Empty_1
String = uavcan.primitive.String_1
Unstructured = uavcan.primitive.Unstructured_1
Bit = uavcan.primitive.array.Bit_1
Integer64 = uavcan.primitive.array.Integer64_1
Integer32 = uavcan.primitive.array.Integer32_1
Integer16 = uavcan.primitive.array.Integer16_1
Integer8 = uavcan.primitive.array.Integer8_1
Natural64 = uavcan.primitive.array.Natural64_1
Natural32 = uavcan.primitive.array.Natural32_1
Natural16 = uavcan.primitive.array.Natural16_1
Natural8 = uavcan.primitive.array.Natural8_1
Real64 = uavcan.primitive.array.Real64_1
Real32 = uavcan.primitive.array.Real32_1
Real16 = uavcan.primitive.array.Real16_1

from ._value import Value as Value
from ._value import ValueProxy as ValueProxy
Expand Down
6 changes: 4 additions & 2 deletions tests/transport/udp/_socket_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


async def _unittest_socket_reader(caplog: typing.Any) -> None:
destination_endpoint = "127.100.0.100", 58724
destination_address = "127.100.0.100"

ts = Timestamp.now()

Expand All @@ -31,7 +31,9 @@ def check_timestamp(t: pyuavcan.transport.Timestamp) -> bool:
return s and m

sock_rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock_rx.bind(destination_endpoint)
sock_rx.bind((destination_address, 0)) # Choose ephemeral port
destination_endpoint = sock_rx.getsockname()
print("Ephemeral destination endpoint:", destination_endpoint)

def make_sock_tx(source_ip_address: str) -> socket.socket:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down

0 comments on commit 99ef434

Please sign in to comment.