From fb8dc8f4499d4cbb38aa6d74a3500717faca043c Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 20:09:41 +1100 Subject: [PATCH 01/16] add mypy to ci --- .github/workflows/python.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index cfe5af2c34..0fdbf2ec77 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -37,7 +37,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel pytest + pip install setuptools wheel pytest mypy - name: Build wheel working-directory: ./photon-lib/py @@ -50,6 +50,12 @@ jobs: pip install --no-cache-dir dist/*.whl pytest + - name: Run mypy type checking + uses: liskin/gh-problem-matcher-wrap@v3 + with: + linters: mypy + run: mypy --show-column-numbers --exclude=build photon-lib + - name: Upload artifacts uses: actions/upload-artifact@master From fe3c562149d50f9dc23315b2af00180869dced98 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 20:17:07 +1100 Subject: [PATCH 02/16] add double up of definition --- photon-lib/py/photonlibpy/estimation/openCVHelp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/photon-lib/py/photonlibpy/estimation/openCVHelp.py b/photon-lib/py/photonlibpy/estimation/openCVHelp.py index 8a6f4911f5..eaf3106245 100644 --- a/photon-lib/py/photonlibpy/estimation/openCVHelp.py +++ b/photon-lib/py/photonlibpy/estimation/openCVHelp.py @@ -128,7 +128,6 @@ def solvePNP_Square( alt: Transform3d | None = None reprojectionError: cv.typing.MatLike | None = None best: Transform3d = Transform3d() - alt: Transform3d | None = None for tries in range(2): retval, rvecs, tvecs, reprojectionError = cv.solvePnPGeneric( From 97d166c1453b037faaf9f427d7c762a0b453cdb2 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 20:21:42 +1100 Subject: [PATCH 03/16] stop overriding iterator with different type --- photon-lib/py/photonlibpy/estimation/visionEstimation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/photon-lib/py/photonlibpy/estimation/visionEstimation.py b/photon-lib/py/photonlibpy/estimation/visionEstimation.py index 834df03d6b..eaa4b0d334 100644 --- a/photon-lib/py/photonlibpy/estimation/visionEstimation.py +++ b/photon-lib/py/photonlibpy/estimation/visionEstimation.py @@ -16,10 +16,10 @@ def getVisibleLayoutTags( id = tag.getFiducialId() maybePose = layout.getTagPose(id) if maybePose: - tag = AprilTag() - tag.ID = id - tag.pose = maybePose - retVal.append(tag) + aprilTag = AprilTag() + aprilTag.ID = id + aprilTag.pose = maybePose + retVal.append(aprilTag) return retVal @staticmethod From 2adfb8238dda16e1c0bdce15040eda0b4fb877ca Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 20:26:03 +1100 Subject: [PATCH 04/16] convince python we are doing the right thing with typing --- photon-lib/py/photonlibpy/simulation/simCameraProperties.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/photon-lib/py/photonlibpy/simulation/simCameraProperties.py b/photon-lib/py/photonlibpy/simulation/simCameraProperties.py index 3ae234b524..6869e594fe 100644 --- a/photon-lib/py/photonlibpy/simulation/simCameraProperties.py +++ b/photon-lib/py/photonlibpy/simulation/simCameraProperties.py @@ -49,6 +49,8 @@ def setCalibration( raise Exception("not a correct function sig") if has_fov_args: + # really convince python we are doing the right thing + assert fovDiag is not None if fovDiag.degrees() < 1.0 or fovDiag.degrees() > 179.0: fovDiag = Rotation2d.fromDegrees( max(min(fovDiag.degrees(), 179.0), 1.0) From c98d6b1214116908d88ea4ce3057130c54ab8e7d Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 20:34:17 +1100 Subject: [PATCH 05/16] fix up incorrect state checks --- .../py/photonlibpy/simulation/photonCameraSim.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/photon-lib/py/photonlibpy/simulation/photonCameraSim.py b/photon-lib/py/photonlibpy/simulation/photonCameraSim.py index fb2fd7d74f..14a59fbda4 100644 --- a/photon-lib/py/photonlibpy/simulation/photonCameraSim.py +++ b/photon-lib/py/photonlibpy/simulation/photonCameraSim.py @@ -41,7 +41,9 @@ def __init__( self.videoSimRawEnabled: bool = False self.videoSimWireframeEnabled: bool = False self.videoSimWireframeResolution: float = 0.1 - self.videoSimProcEnabled: bool = True + self.videoSimProcEnabled: bool = ( + False # TODO switch this back to default True when the functionality is enabled + ) self.heartbeatCounter: int = 0 self.nextNtEntryTime = int(wpilib.Timer.getFPGATimestamp() * 1e6) self.tagLayout = robotpy_apriltag.loadAprilTagLayoutField( @@ -193,19 +195,19 @@ def setMaxSightRange(self, range: meters) -> None: self.maxSightRange = range def enableRawStream(self, enabled: bool) -> None: + self.videoSimRawEnabled = enabled raise Exception("Raw stream not implemented") - # self.videoSimRawEnabled = enabled def enableDrawWireframe(self, enabled: bool) -> None: + self.videoSimWireframeEnabled = enabled raise Exception("Wireframe not implemented") - # self.videoSimWireframeEnabled = enabled def setWireframeResolution(self, resolution: float) -> None: self.videoSimWireframeResolution = resolution def enableProcessedStream(self, enabled: bool) -> None: + self.videoSimProcEnabled = enabled raise Exception("Processed stream not implemented") - # self.videoSimProcEnabled = enabled def process( self, latency: seconds, cameraPose: Pose3d, targets: list[VisionTargetSim] @@ -323,13 +325,13 @@ def distance(target: VisionTargetSim): ) # Video streams disabled for now - if self.enableRawStream: + if self.videoSimRawEnabled: # VideoSimUtil::UpdateVideoProp(videoSimRaw, prop); # cv::Size videoFrameSize{prop.GetResWidth(), prop.GetResHeight()}; # cv::Mat blankFrame = cv::Mat::zeros(videoFrameSize, CV_8UC1); # blankFrame.assignTo(videoSimFrameRaw); pass - if self.enableProcessedStream: + if self.videoSimProcEnabled: # VideoSimUtil::UpdateVideoProp(videoSimProcessed, prop); pass From 0bac39aee7dd3a1a2751a9542e8024526925c4c7 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 20:40:58 +1100 Subject: [PATCH 06/16] fix up type checking in test --- photon-lib/py/test/visionSystemSim_test.py | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/photon-lib/py/test/visionSystemSim_test.py b/photon-lib/py/test/visionSystemSim_test.py index 4851f81909..c9f4757e24 100644 --- a/photon-lib/py/test/visionSystemSim_test.py +++ b/photon-lib/py/test/visionSystemSim_test.py @@ -25,7 +25,7 @@ def setupCommon() -> None: setVersionCheckEnabled(False) -def test_VisibilityCupidShuffle(): +def test_VisibilityCupidShuffle() -> None: targetPose = Pose3d(Translation3d(15.98, 0.0, 2.0), Rotation3d(0, 0, math.pi)) @@ -83,7 +83,7 @@ def test_VisibilityCupidShuffle(): assert camera.getLatestResult().hasTargets() -def test_NotVisibleVert1(): +def test_NotVisibleVert1() -> None: targetPose = Pose3d(Translation3d(15.98, 0.0, 2.0), Rotation3d(0, 0, math.pi)) @@ -111,7 +111,7 @@ def test_NotVisibleVert1(): assert not camera.getLatestResult().hasTargets() -def test_NotVisibleVert2(): +def test_NotVisibleVert2() -> None: targetPose = Pose3d(Translation3d(15.98, 0.0, 2.0), Rotation3d(0, 0, math.pi)) @@ -138,7 +138,7 @@ def test_NotVisibleVert2(): assert not camera.getLatestResult().hasTargets() -def test_NotVisibleTargetSize(): +def test_NotVisibleTargetSize() -> None: targetPose = Pose3d(Translation3d(15.98, 0.0, 1.0), Rotation3d(0, 0, math.pi)) visionSysSim = VisionSystemSim("Test") @@ -161,7 +161,7 @@ def test_NotVisibleTargetSize(): assert not camera.getLatestResult().hasTargets() -def test_NotVisibleTooFarLeds(): +def test_NotVisibleTooFarLeds() -> None: targetPose = Pose3d(Translation3d(15.98, 0.0, 1.0), Rotation3d(0, 0, math.pi)) @@ -189,7 +189,7 @@ def test_NotVisibleTooFarLeds(): @pytest.mark.parametrize( "expected_yaw", [-10.0, -5.0, -2.0, -1.0, 0.0, 5.0, 7.0, 10.23] ) -def test_YawAngles(expected_yaw): +def test_YawAngles(expected_yaw) -> None: targetPose = Pose3d( Translation3d(15.98, 0.0, 1.0), Rotation3d(0.0, 0.0, 3.0 * math.pi / 4.0) @@ -211,14 +211,15 @@ def test_YawAngles(expected_yaw): result = camera.getLatestResult() - assert result.hasTargets() - assert result.getBestTarget().getYaw() == pytest.approx(expected_yaw, abs=0.25) + bestTarget = result.getBestTarget() + assert bestTarget is not None + assert bestTarget.getYaw() == pytest.approx(expected_yaw, abs=0.25) @pytest.mark.parametrize( "expected_pitch", [-10.0, -5.0, -2.0, -1.0, 0.0, 5.0, 7.0, 10.23] ) -def test_PitchAngles(expected_pitch): +def test_PitchAngles(expected_pitch) -> None: targetPose = Pose3d( Translation3d(15.98, 0.0, 0.0), Rotation3d(0, 0, 3.0 * math.pi / 4.0) @@ -245,8 +246,9 @@ def test_PitchAngles(expected_pitch): result = camera.getLatestResult() - assert result.hasTargets() - assert result.getBestTarget().getPitch() == pytest.approx(expected_pitch, abs=0.25) + bestTarget = result.getBestTarget() + assert bestTarget is not None + assert bestTarget.getPitch() == pytest.approx(expected_pitch, abs=0.25) @pytest.mark.parametrize( @@ -271,7 +273,7 @@ def test_PitchAngles(expected_pitch): (19.52, -15.98, 1.1), ], ) -def test_distanceCalc(distParam, pitchParam, heightParam): +def test_distanceCalc(distParam, pitchParam, heightParam) -> None: distParam = feetToMeters(distParam) pitchParam = math.radians(pitchParam) heightParam = feetToMeters(heightParam) @@ -301,10 +303,8 @@ def test_distanceCalc(distParam, pitchParam, heightParam): result = camera.getLatestResult() - assert result.hasTargets() - target = result.getBestTarget() - + assert target is not None assert target.getYaw() == pytest.approx(0.0, abs=0.5) # TODO Enable when PhotonUtils is ported @@ -314,7 +314,7 @@ def test_distanceCalc(distParam, pitchParam, heightParam): # assert dist == pytest.approx(distParam, abs=0.25) -def test_MultipleTargets(): +def test_MultipleTargets() -> None: targetPoseL = Pose3d(Translation3d(15.98, 2.0, 0.0), Rotation3d(0.0, 0.0, math.pi)) targetPoseC = Pose3d(Translation3d(15.98, 0.0, 0.0), Rotation3d(0.0, 0.0, math.pi)) targetPoseR = Pose3d(Translation3d(15.98, -2.0, 0.0), Rotation3d(0.0, 0.0, math.pi)) @@ -415,7 +415,7 @@ def test_MultipleTargets(): assert len(tgtList) == 11 -def test_PoseEstimation(): +def test_PoseEstimation() -> None: visionSysSim = VisionSystemSim("Test") camera = PhotonCamera("camera") cameraSim = PhotonCameraSim(camera) From 712a0162cfa9325c90992b3d38c6929881bc966c Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 21:22:54 +1100 Subject: [PATCH 07/16] touch up autogenerated shenanigans to handle type hinting --- .../generated/MultiTargetPNPResultSerde.py | 5 +++++ .../generated/PhotonPipelineMetadataSerde.py | 4 ++++ .../generated/PhotonPipelineResultSerde.py | 7 +++++++ .../generated/PhotonTrackedTargetSerde.py | 6 ++++++ .../py/photonlibpy/generated/PnpResultSerde.py | 4 ++++ .../py/photonlibpy/generated/TargetCornerSerde.py | 4 ++++ photon-lib/py/photonlibpy/targeting/TargetCorner.py | 4 ++-- .../photonlibpy/targeting/multiTargetPNPResult.py | 7 ++++--- .../photonlibpy/targeting/photonPipelineResult.py | 7 ++++--- .../py/photonlibpy/targeting/photonTrackedTarget.py | 4 ++-- photon-serde/templates/ThingSerde.py.jinja | 13 +++++++++++-- 11 files changed, 53 insertions(+), 12 deletions(-) diff --git a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py index 84bea55021..3008f45acc 100644 --- a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py @@ -22,6 +22,11 @@ from ..packet import Packet from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import MultiTargetPNPResult + from ..targeting import PnpResult class MultiTargetPNPResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py index be9ed5f2f8..7099d83523 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py @@ -22,6 +22,10 @@ from ..packet import Packet from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import PhotonPipelineMetadata class PhotonPipelineMetadataSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py index 45abf0b4d5..ec5ace2b4d 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py @@ -22,6 +22,13 @@ from ..packet import Packet from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import PhotonPipelineResult + from ..targeting import PhotonPipelineMetadata + from ..targeting import PhotonTrackedTarget + from ..targeting import MultiTargetPNPResult class PhotonPipelineResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py index 655147f085..eee9369f76 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py @@ -22,6 +22,12 @@ from ..packet import Packet from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import PhotonTrackedTarget + from ..targeting import TargetCorner + from ..targeting import TargetCorner class PhotonTrackedTargetSerde: diff --git a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py index 6312574223..e77fb1f3c8 100644 --- a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py @@ -22,6 +22,10 @@ from ..packet import Packet from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import PnpResult class PnpResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py index 6c60e0a235..85fb899d74 100644 --- a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py +++ b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py @@ -22,6 +22,10 @@ from ..packet import Packet from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import TargetCorner class TargetCornerSerde: diff --git a/photon-lib/py/photonlibpy/targeting/TargetCorner.py b/photon-lib/py/photonlibpy/targeting/TargetCorner.py index 849a586eb7..76e113eb46 100644 --- a/photon-lib/py/photonlibpy/targeting/TargetCorner.py +++ b/photon-lib/py/photonlibpy/targeting/TargetCorner.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, ClassVar if TYPE_CHECKING: - from .. import generated + from ..generated.TargetCornerSerde import TargetCornerSerde @dataclass @@ -10,4 +10,4 @@ class TargetCorner: x: float = 0 y: float = 9 - photonStruct: ClassVar["generated.TargetCornerSerde"] + photonStruct: ClassVar["TargetCornerSerde"] diff --git a/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py b/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py index 1eb03ea603..d4eaf7e41c 100644 --- a/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py +++ b/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py @@ -4,7 +4,8 @@ from wpimath.geometry import Transform3d if TYPE_CHECKING: - from .. import generated + from ..generated.PnpResultSerde import PnpResultSerde + from ..generated.MultiTargetPNPResultSerde import MultiTargetPNPResultSerde @dataclass @@ -15,7 +16,7 @@ class PnpResult: bestReprojErr: float = 0.0 altReprojErr: float = 0.0 - photonStruct: ClassVar["generated.PnpResultSerde"] + photonStruct: ClassVar["PnpResultSerde"] @dataclass @@ -25,4 +26,4 @@ class MultiTargetPNPResult: estimatedPose: PnpResult = field(default_factory=PnpResult) fiducialIDsUsed: list[int] = field(default_factory=list) - photonStruct: ClassVar["generated.MultiTargetPNPResultSerde"] + photonStruct: ClassVar["MultiTargetPNPResultSerde"] diff --git a/photon-lib/py/photonlibpy/targeting/photonPipelineResult.py b/photon-lib/py/photonlibpy/targeting/photonPipelineResult.py index 67e722456b..dc1ff2436d 100644 --- a/photon-lib/py/photonlibpy/targeting/photonPipelineResult.py +++ b/photon-lib/py/photonlibpy/targeting/photonPipelineResult.py @@ -5,7 +5,8 @@ from .photonTrackedTarget import PhotonTrackedTarget if TYPE_CHECKING: - from .. import generated + from ..generated.PhotonPipelineMetadataSerde import PhotonPipelineMetadataSerde + from ..generated.PhotonPipelineResultSerde import PhotonPipelineResultSerde @dataclass @@ -20,7 +21,7 @@ class PhotonPipelineMetadata: timeSinceLastPong: int = -1 - photonStruct: ClassVar["generated.PhotonPipelineMetadataSerde"] + photonStruct: ClassVar["PhotonPipelineMetadataSerde"] @dataclass @@ -69,4 +70,4 @@ def getBestTarget(self) -> Optional[PhotonTrackedTarget]: return None return self.getTargets()[0] - photonStruct: ClassVar["generated.PhotonPipelineResultSerde"] + photonStruct: ClassVar["PhotonPipelineResultSerde"] diff --git a/photon-lib/py/photonlibpy/targeting/photonTrackedTarget.py b/photon-lib/py/photonlibpy/targeting/photonTrackedTarget.py index 4ad3668a58..e3e253bb94 100644 --- a/photon-lib/py/photonlibpy/targeting/photonTrackedTarget.py +++ b/photon-lib/py/photonlibpy/targeting/photonTrackedTarget.py @@ -7,7 +7,7 @@ from .TargetCorner import TargetCorner if TYPE_CHECKING: - from .. import generated + from ..generated.PhotonTrackedTargetSerde import PhotonTrackedTargetSerde @dataclass @@ -63,4 +63,4 @@ def _decodeTargetList(self, packet: Packet, numTargets: int) -> list[TargetCorne retList.append(TargetCorner(cx, cy)) return retList - photonStruct: ClassVar["generated.PhotonTrackedTargetSerde"] + photonStruct: ClassVar["PhotonTrackedTargetSerde"] diff --git a/photon-serde/templates/ThingSerde.py.jinja b/photon-serde/templates/ThingSerde.py.jinja index f6e441b47c..a50893a702 100644 --- a/photon-serde/templates/ThingSerde.py.jinja +++ b/photon-serde/templates/ThingSerde.py.jinja @@ -20,11 +20,20 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..targeting import * from ..packet import Packet +from ..targeting import * +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from ..targeting import {{ name }} +{%- for field in fields -%} +{%- if not field.type | is_shimmed and not field.type | is_intrinsic %} + from ..targeting import {{ field.type }} +{%- endif %} +{%- endfor%} -class {{ name }}Serde: +class {{ name }}Serde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "{{ message_hash }}" MESSAGE_FORMAT = "{{ message_fmt }}" From 082f7850bc87979e8f4ac91ab67b26f612f4db6d Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 21:29:33 +1100 Subject: [PATCH 08/16] fix late assignment of type hint --- photon-lib/py/photonlibpy/estimation/targetModel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/photon-lib/py/photonlibpy/estimation/targetModel.py b/photon-lib/py/photonlibpy/estimation/targetModel.py index e9006b50b7..6853849d09 100644 --- a/photon-lib/py/photonlibpy/estimation/targetModel.py +++ b/photon-lib/py/photonlibpy/estimation/targetModel.py @@ -17,6 +17,8 @@ def __init__( diameter: meters | None = None, verts: List[Translation3d] | None = None ): + + self.vertices: List[Translation3d] = [] if ( width is not None @@ -88,7 +90,7 @@ def __init__( self.isSpherical = False if len(verts) <= 2: - self.vertices: List[Translation3d] = [] + self.vertices = [] self.isPlanar = False else: cornersPlaner = True From d4f853bd198fc20262bcf11f3a1b6a62fbdcebcf Mon Sep 17 00:00:00 2001 From: James Ward Date: Wed, 13 Nov 2024 21:33:58 +1100 Subject: [PATCH 09/16] Rename variable to avoid mypy confusion --- .../py/photonlibpy/simulation/visionSystemSim.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/photon-lib/py/photonlibpy/simulation/visionSystemSim.py b/photon-lib/py/photonlibpy/simulation/visionSystemSim.py index 0c5903d621..70ffd6609b 100644 --- a/photon-lib/py/photonlibpy/simulation/visionSystemSim.py +++ b/photon-lib/py/photonlibpy/simulation/visionSystemSim.py @@ -20,9 +20,9 @@ def __init__(self, visionSystemName: str): self.bufferLength: seconds = 1.5 self.camSimMap: typing.Dict[str, PhotonCameraSim] = {} - self.camTrfMap: typing.Dict[PhotonCameraSim, TimeInterpolatablePose3dBuffer] = ( - {} - ) + self.camTrfMap: typing.Dict[ + PhotonCameraSim, TimeInterpolatablePose3dBuffer + ] = {} self.robotPoseBuffer: TimeInterpolatablePose3dBuffer = ( TimeInterpolatablePose3dBuffer(self.bufferLength) ) @@ -228,8 +228,8 @@ def update(self, robotPose: Pose2d | Pose3d) -> None: camResult = camSim.process(latency, lateCameraPose, allTargets) camSim.submitProcessedFrame(camResult, timestampNt) - for target in camResult.getTargets(): - trf = target.getBestCameraToTarget() + for tgt in camResult.getTargets(): + trf = tgt.getBestCameraToTarget() if trf == Transform3d(): continue From 4cf0787345b6b93c6bb359764306590f4a4f6ab8 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 21:35:49 +1100 Subject: [PATCH 10/16] try changing job to only run in python lib --- .github/workflows/python.yml | 4 +++- photon-lib/py/pyproject.toml | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 photon-lib/py/pyproject.toml diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 0fdbf2ec77..bf30904b15 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -54,7 +54,9 @@ jobs: uses: liskin/gh-problem-matcher-wrap@v3 with: linters: mypy - run: mypy --show-column-numbers --exclude=build photon-lib + run: | + cd photon-lib/py + mypy --show-column-numbers --exclude=build . - name: Upload artifacts diff --git a/photon-lib/py/pyproject.toml b/photon-lib/py/pyproject.toml new file mode 100644 index 0000000000..dfd1c36da3 --- /dev/null +++ b/photon-lib/py/pyproject.toml @@ -0,0 +1,2 @@ +[tool.mypy] +exclude = ["build","setup.py"] \ No newline at end of file From 83018bcd7895ed19accef49f1141e4626892da87 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 21:53:27 +1100 Subject: [PATCH 11/16] update mypy to look for package version of pyproject.toml --- .github/workflows/python.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index bf30904b15..24b1def225 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -55,8 +55,7 @@ jobs: with: linters: mypy run: | - cd photon-lib/py - mypy --show-column-numbers --exclude=build . + mypy --show-column-numbers --config-file photon-lib/py/pyproject.toml photon-lib - name: Upload artifacts From 5f6fec28ca5b069e63a9fe95438928ff38fe4675 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 22:02:46 +1100 Subject: [PATCH 12/16] wpiformat --- photon-lib/py/photonlibpy/estimation/targetModel.py | 2 +- .../generated/MultiTargetPNPResultSerde.py | 9 +++++---- .../generated/PhotonPipelineMetadataSerde.py | 7 ++++--- .../generated/PhotonPipelineResultSerde.py | 13 +++++++------ .../generated/PhotonTrackedTargetSerde.py | 11 ++++++----- .../py/photonlibpy/generated/PnpResultSerde.py | 7 ++++--- .../py/photonlibpy/generated/TargetCornerSerde.py | 7 ++++--- .../py/photonlibpy/simulation/visionSystemSim.py | 6 +++--- photon-lib/py/pyproject.toml | 2 +- photon-serde/templates/ThingSerde.py.jinja | 9 +++++---- .../struct/PhotonPipelineResultSerde.java | 2 +- 11 files changed, 41 insertions(+), 34 deletions(-) diff --git a/photon-lib/py/photonlibpy/estimation/targetModel.py b/photon-lib/py/photonlibpy/estimation/targetModel.py index 6853849d09..652863403c 100644 --- a/photon-lib/py/photonlibpy/estimation/targetModel.py +++ b/photon-lib/py/photonlibpy/estimation/targetModel.py @@ -17,7 +17,7 @@ def __init__( diameter: meters | None = None, verts: List[Translation3d] | None = None ): - + self.vertices: List[Translation3d] = [] if ( diff --git a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py index 3008f45acc..53e381351b 100644 --- a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py @@ -20,13 +20,14 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import MultiTargetPNPResult - from ..targeting import PnpResult + from ..targeting import MultiTargetPNPResult # noqa + from ..targeting import PnpResult # noqa class MultiTargetPNPResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py index 7099d83523..af4914aaac 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py @@ -20,12 +20,13 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import PhotonPipelineMetadata + from ..targeting import PhotonPipelineMetadata # noqa class PhotonPipelineMetadataSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py index ec5ace2b4d..a8130fe13e 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py @@ -20,15 +20,16 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import PhotonPipelineResult - from ..targeting import PhotonPipelineMetadata - from ..targeting import PhotonTrackedTarget - from ..targeting import MultiTargetPNPResult + from ..targeting import PhotonPipelineResult # noqa + from ..targeting import PhotonPipelineMetadata # noqa + from ..targeting import PhotonTrackedTarget # noqa + from ..targeting import MultiTargetPNPResult # noqa class PhotonPipelineResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py index eee9369f76..e102776e90 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py @@ -20,14 +20,15 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import PhotonTrackedTarget - from ..targeting import TargetCorner - from ..targeting import TargetCorner + from ..targeting import PhotonTrackedTarget # noqa + from ..targeting import TargetCorner # noqa + from ..targeting import TargetCorner # noqa class PhotonTrackedTargetSerde: diff --git a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py index e77fb1f3c8..ac83f16913 100644 --- a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py @@ -20,12 +20,13 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import PnpResult + from ..targeting import PnpResult # noqa class PnpResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py index 85fb899d74..250ababf07 100644 --- a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py +++ b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py @@ -20,12 +20,13 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import TargetCorner + from ..targeting import TargetCorner # noqa class TargetCornerSerde: diff --git a/photon-lib/py/photonlibpy/simulation/visionSystemSim.py b/photon-lib/py/photonlibpy/simulation/visionSystemSim.py index 70ffd6609b..ca42004c07 100644 --- a/photon-lib/py/photonlibpy/simulation/visionSystemSim.py +++ b/photon-lib/py/photonlibpy/simulation/visionSystemSim.py @@ -20,9 +20,9 @@ def __init__(self, visionSystemName: str): self.bufferLength: seconds = 1.5 self.camSimMap: typing.Dict[str, PhotonCameraSim] = {} - self.camTrfMap: typing.Dict[ - PhotonCameraSim, TimeInterpolatablePose3dBuffer - ] = {} + self.camTrfMap: typing.Dict[PhotonCameraSim, TimeInterpolatablePose3dBuffer] = ( + {} + ) self.robotPoseBuffer: TimeInterpolatablePose3dBuffer = ( TimeInterpolatablePose3dBuffer(self.bufferLength) ) diff --git a/photon-lib/py/pyproject.toml b/photon-lib/py/pyproject.toml index dfd1c36da3..4dd0d50787 100644 --- a/photon-lib/py/pyproject.toml +++ b/photon-lib/py/pyproject.toml @@ -1,2 +1,2 @@ [tool.mypy] -exclude = ["build","setup.py"] \ No newline at end of file +exclude = ["build","setup.py"] diff --git a/photon-serde/templates/ThingSerde.py.jinja b/photon-serde/templates/ThingSerde.py.jinja index a50893a702..97564de518 100644 --- a/photon-serde/templates/ThingSerde.py.jinja +++ b/photon-serde/templates/ThingSerde.py.jinja @@ -20,15 +20,16 @@ ## --> DO NOT MODIFY <-- ############################################################################### -from ..packet import Packet -from ..targeting import * from typing import TYPE_CHECKING +from ..packet import Packet +from ..targeting import * # noqa + if TYPE_CHECKING: - from ..targeting import {{ name }} + from ..targeting import {{ name }} # noqa {%- for field in fields -%} {%- if not field.type | is_shimmed and not field.type | is_intrinsic %} - from ..targeting import {{ field.type }} + from ..targeting import {{ field.type }} # noqa {%- endif %} {%- endfor%} diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java index d0ed4f9ab0..9bac6213c8 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java @@ -78,7 +78,7 @@ public PhotonPipelineResult unpack(Packet packet) { @Override public PacketSerde[] getNestedPhotonMessages() { return new PacketSerde[] { - MultiTargetPNPResult.photonStruct,PhotonTrackedTarget.photonStruct,PhotonPipelineMetadata.photonStruct + MultiTargetPNPResult.photonStruct,PhotonPipelineMetadata.photonStruct,PhotonTrackedTarget.photonStruct }; } From 92e4ccdd69020dc0ea7afab2a6ce1838739f29a1 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 22:55:53 +1100 Subject: [PATCH 13/16] learn more about jinja than I ever wanted to --- .../generated/MultiTargetPNPResultSerde.py | 4 ++-- .../generated/PhotonPipelineMetadataSerde.py | 2 +- .../generated/PhotonPipelineResultSerde.py | 8 ++++---- .../generated/PhotonTrackedTargetSerde.py | 5 ++--- .../py/photonlibpy/generated/PnpResultSerde.py | 2 +- .../py/photonlibpy/generated/TargetCornerSerde.py | 2 +- photon-serde/templates/ThingSerde.py.jinja | 12 ++++++++---- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py index 53e381351b..c55b7c4ab6 100644 --- a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py @@ -26,8 +26,8 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import MultiTargetPNPResult # noqa - from ..targeting import PnpResult # noqa + from ..targeting import MultiTargetPNPResult + from ..targeting import PnpResult class MultiTargetPNPResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py index af4914aaac..7253a3b813 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py @@ -26,7 +26,7 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PhotonPipelineMetadata # noqa + from ..targeting import PhotonPipelineMetadata class PhotonPipelineMetadataSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py index a8130fe13e..1797bf7769 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py @@ -26,10 +26,10 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PhotonPipelineResult # noqa - from ..targeting import PhotonPipelineMetadata # noqa - from ..targeting import PhotonTrackedTarget # noqa - from ..targeting import MultiTargetPNPResult # noqa + from ..targeting import MultiTargetPNPResult + from ..targeting import PhotonPipelineMetadata + from ..targeting import PhotonPipelineResult + from ..targeting import PhotonTrackedTarget class PhotonPipelineResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py index e102776e90..16d4dbfd54 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py @@ -26,9 +26,8 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PhotonTrackedTarget # noqa - from ..targeting import TargetCorner # noqa - from ..targeting import TargetCorner # noqa + from ..targeting import PhotonTrackedTarget + from ..targeting import TargetCorner class PhotonTrackedTargetSerde: diff --git a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py index ac83f16913..2dedeef8e2 100644 --- a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py @@ -26,7 +26,7 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PnpResult # noqa + from ..targeting import PnpResult class PnpResultSerde: diff --git a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py index 250ababf07..1abaf848b2 100644 --- a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py +++ b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py @@ -26,7 +26,7 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import TargetCorner # noqa + from ..targeting import TargetCorner class TargetCornerSerde: diff --git a/photon-serde/templates/ThingSerde.py.jinja b/photon-serde/templates/ThingSerde.py.jinja index 97564de518..c4eac2e05c 100644 --- a/photon-serde/templates/ThingSerde.py.jinja +++ b/photon-serde/templates/ThingSerde.py.jinja @@ -26,10 +26,14 @@ from ..packet import Packet from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import {{ name }} # noqa -{%- for field in fields -%} -{%- if not field.type | is_shimmed and not field.type | is_intrinsic %} - from ..targeting import {{ field.type }} # noqa +{%- set ns = namespace(types=[]) -%} +{%- for field in fields|unique(attribute="type")-%} + {%- set _ = ns.types.append(field.type) -%} +{%- endfor -%} +{% set _ = ns.types.append(name) -%} +{%- for type in ns.types|sort%} +{%- if not type | is_shimmed and not type | is_intrinsic %} + from ..targeting import {{ type }} {%- endif %} {%- endfor%} From 624271292ac2f489ae3d7f2712d7428e5e4d1fdc Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 22:57:48 +1100 Subject: [PATCH 14/16] add noqa tag --- .../generated/MultiTargetPNPResultSerde.py | 11 ++++++----- .../generated/PhotonPipelineMetadataSerde.py | 9 +++++---- .../generated/PhotonPipelineResultSerde.py | 19 +++++++++---------- .../generated/PhotonTrackedTargetSerde.py | 11 ++++++----- .../photonlibpy/generated/PnpResultSerde.py | 9 +++++---- .../generated/TargetCornerSerde.py | 9 +++++---- photon-serde/templates/ThingSerde.py.jinja | 2 +- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py index c55b7c4ab6..5674849c30 100644 --- a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py @@ -26,8 +26,8 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import MultiTargetPNPResult - from ..targeting import PnpResult + from ..targeting import MultiTargetPNPResult # noqa + from ..targeting import PnpResult # noqa class MultiTargetPNPResultSerde: @@ -36,7 +36,7 @@ class MultiTargetPNPResultSerde: MESSAGE_FORMAT = "PnpResult:ae4d655c0a3104d88df4f5db144c1e86 estimatedPose;int16 fiducialIDsUsed[?];" @staticmethod - def pack(value: "MultiTargetPNPResult") -> "Packet": + def pack(value: 'MultiTargetPNPResult' ) -> 'Packet': ret = Packet() # estimatedPose is of non-intrinsic type PnpResult @@ -46,8 +46,9 @@ def pack(value: "MultiTargetPNPResult") -> "Packet": ret.encodeShortList(value.fiducialIDsUsed) return ret + @staticmethod - def unpack(packet: "Packet") -> "MultiTargetPNPResult": + def unpack(packet: 'Packet') -> 'MultiTargetPNPResult': ret = MultiTargetPNPResult() # estimatedPose is of non-intrinsic type PnpResult @@ -60,4 +61,4 @@ def unpack(packet: "Packet") -> "MultiTargetPNPResult": # Hack ourselves into the base class -MultiTargetPNPResult.photonStruct = MultiTargetPNPResultSerde() +MultiTargetPNPResult.photonStruct = MultiTargetPNPResultSerde() \ No newline at end of file diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py index 7253a3b813..79f5f11bb8 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py @@ -26,7 +26,7 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PhotonPipelineMetadata + from ..targeting import PhotonPipelineMetadata # noqa class PhotonPipelineMetadataSerde: @@ -35,7 +35,7 @@ class PhotonPipelineMetadataSerde: MESSAGE_FORMAT = "int64 sequenceID;int64 captureTimestampMicros;int64 publishTimestampMicros;int64 timeSinceLastPong;" @staticmethod - def pack(value: "PhotonPipelineMetadata") -> "Packet": + def pack(value: 'PhotonPipelineMetadata' ) -> 'Packet': ret = Packet() # sequenceID is of intrinsic type int64 @@ -51,8 +51,9 @@ def pack(value: "PhotonPipelineMetadata") -> "Packet": ret.encodeLong(value.timeSinceLastPong) return ret + @staticmethod - def unpack(packet: "Packet") -> "PhotonPipelineMetadata": + def unpack(packet: 'Packet') -> 'PhotonPipelineMetadata': ret = PhotonPipelineMetadata() # sequenceID is of intrinsic type int64 @@ -71,4 +72,4 @@ def unpack(packet: "Packet") -> "PhotonPipelineMetadata": # Hack ourselves into the base class -PhotonPipelineMetadata.photonStruct = PhotonPipelineMetadataSerde() +PhotonPipelineMetadata.photonStruct = PhotonPipelineMetadataSerde() \ No newline at end of file diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py index 1797bf7769..374722e684 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py @@ -26,10 +26,10 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import MultiTargetPNPResult - from ..targeting import PhotonPipelineMetadata - from ..targeting import PhotonPipelineResult - from ..targeting import PhotonTrackedTarget + from ..targeting import MultiTargetPNPResult # noqa + from ..targeting import PhotonPipelineMetadata # noqa + from ..targeting import PhotonPipelineResult # noqa + from ..targeting import PhotonTrackedTarget # noqa class PhotonPipelineResultSerde: @@ -38,13 +38,11 @@ class PhotonPipelineResultSerde: MESSAGE_FORMAT = "PhotonPipelineMetadata:ac0a45f686457856fb30af77699ea356 metadata;PhotonTrackedTarget:cc6dbb5c5c1e0fa808108019b20863f1 targets[?];optional MultiTargetPNPResult:541096947e9f3ca2d3f425ff7b04aa7b multitagResult;" @staticmethod - def pack(value: "PhotonPipelineResult") -> "Packet": + def pack(value: 'PhotonPipelineResult' ) -> 'Packet': ret = Packet() # metadata is of non-intrinsic type PhotonPipelineMetadata - ret.encodeBytes( - PhotonPipelineMetadata.photonStruct.pack(value.metadata).getData() - ) + ret.encodeBytes(PhotonPipelineMetadata.photonStruct.pack(value.metadata).getData()) # targets is a custom VLA! ret.encodeList(value.targets, PhotonTrackedTarget.photonStruct) @@ -53,8 +51,9 @@ def pack(value: "PhotonPipelineResult") -> "Packet": ret.encodeOptional(value.multitagResult, MultiTargetPNPResult.photonStruct) return ret + @staticmethod - def unpack(packet: "Packet") -> "PhotonPipelineResult": + def unpack(packet: 'Packet') -> 'PhotonPipelineResult': ret = PhotonPipelineResult() # metadata is of non-intrinsic type PhotonPipelineMetadata @@ -70,4 +69,4 @@ def unpack(packet: "Packet") -> "PhotonPipelineResult": # Hack ourselves into the base class -PhotonPipelineResult.photonStruct = PhotonPipelineResultSerde() +PhotonPipelineResult.photonStruct = PhotonPipelineResultSerde() \ No newline at end of file diff --git a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py index 16d4dbfd54..509b04105f 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py @@ -26,8 +26,8 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PhotonTrackedTarget - from ..targeting import TargetCorner + from ..targeting import PhotonTrackedTarget # noqa + from ..targeting import TargetCorner # noqa class PhotonTrackedTargetSerde: @@ -36,7 +36,7 @@ class PhotonTrackedTargetSerde: MESSAGE_FORMAT = "float64 yaw;float64 pitch;float64 area;float64 skew;int32 fiducialId;int32 objDetectId;float32 objDetectConf;Transform3d bestCameraToTarget;Transform3d altCameraToTarget;float64 poseAmbiguity;TargetCorner:16f6ac0dedc8eaccb951f4895d9e18b6 minAreaRectCorners[?];TargetCorner:16f6ac0dedc8eaccb951f4895d9e18b6 detectedCorners[?];" @staticmethod - def pack(value: "PhotonTrackedTarget") -> "Packet": + def pack(value: 'PhotonTrackedTarget' ) -> 'Packet': ret = Packet() # yaw is of intrinsic type float64 @@ -74,8 +74,9 @@ def pack(value: "PhotonTrackedTarget") -> "Packet": ret.encodeList(value.detectedCorners, TargetCorner.photonStruct) return ret + @staticmethod - def unpack(packet: "Packet") -> "PhotonTrackedTarget": + def unpack(packet: 'Packet') -> 'PhotonTrackedTarget': ret = PhotonTrackedTarget() # yaw is of intrinsic type float64 @@ -116,4 +117,4 @@ def unpack(packet: "Packet") -> "PhotonTrackedTarget": # Hack ourselves into the base class -PhotonTrackedTarget.photonStruct = PhotonTrackedTargetSerde() +PhotonTrackedTarget.photonStruct = PhotonTrackedTargetSerde() \ No newline at end of file diff --git a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py index 2dedeef8e2..6f405f8920 100644 --- a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py @@ -26,7 +26,7 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import PnpResult + from ..targeting import PnpResult # noqa class PnpResultSerde: @@ -35,7 +35,7 @@ class PnpResultSerde: MESSAGE_FORMAT = "Transform3d best;Transform3d alt;float64 bestReprojErr;float64 altReprojErr;float64 ambiguity;" @staticmethod - def pack(value: "PnpResult") -> "Packet": + def pack(value: 'PnpResult' ) -> 'Packet': ret = Packet() ret.encodeTransform(value.best) @@ -52,8 +52,9 @@ def pack(value: "PnpResult") -> "Packet": ret.encodeDouble(value.ambiguity) return ret + @staticmethod - def unpack(packet: "Packet") -> "PnpResult": + def unpack(packet: 'Packet') -> 'PnpResult': ret = PnpResult() ret.best = packet.decodeTransform() @@ -73,4 +74,4 @@ def unpack(packet: "Packet") -> "PnpResult": # Hack ourselves into the base class -PnpResult.photonStruct = PnpResultSerde() +PnpResult.photonStruct = PnpResultSerde() \ No newline at end of file diff --git a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py index 1abaf848b2..9c6c847230 100644 --- a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py +++ b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py @@ -26,7 +26,7 @@ from ..targeting import * # noqa if TYPE_CHECKING: - from ..targeting import TargetCorner + from ..targeting import TargetCorner # noqa class TargetCornerSerde: @@ -35,7 +35,7 @@ class TargetCornerSerde: MESSAGE_FORMAT = "float64 x;float64 y;" @staticmethod - def pack(value: "TargetCorner") -> "Packet": + def pack(value: 'TargetCorner' ) -> 'Packet': ret = Packet() # x is of intrinsic type float64 @@ -45,8 +45,9 @@ def pack(value: "TargetCorner") -> "Packet": ret.encodeDouble(value.y) return ret + @staticmethod - def unpack(packet: "Packet") -> "TargetCorner": + def unpack(packet: 'Packet') -> 'TargetCorner': ret = TargetCorner() # x is of intrinsic type float64 @@ -59,4 +60,4 @@ def unpack(packet: "Packet") -> "TargetCorner": # Hack ourselves into the base class -TargetCorner.photonStruct = TargetCornerSerde() +TargetCorner.photonStruct = TargetCornerSerde() \ No newline at end of file diff --git a/photon-serde/templates/ThingSerde.py.jinja b/photon-serde/templates/ThingSerde.py.jinja index c4eac2e05c..82cedc4354 100644 --- a/photon-serde/templates/ThingSerde.py.jinja +++ b/photon-serde/templates/ThingSerde.py.jinja @@ -33,7 +33,7 @@ if TYPE_CHECKING: {% set _ = ns.types.append(name) -%} {%- for type in ns.types|sort%} {%- if not type | is_shimmed and not type | is_intrinsic %} - from ..targeting import {{ type }} + from ..targeting import {{ type }} # noqa {%- endif %} {%- endfor%} From a06516cdc115cae7cc9009f3fe779efd70b055f6 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 23:07:05 +1100 Subject: [PATCH 15/16] format --- .../generated/MultiTargetPNPResultSerde.py | 7 +++---- .../generated/PhotonPipelineMetadataSerde.py | 7 +++---- .../generated/PhotonPipelineResultSerde.py | 11 ++++++----- .../photonlibpy/generated/PhotonTrackedTargetSerde.py | 7 +++---- photon-lib/py/photonlibpy/generated/PnpResultSerde.py | 7 +++---- .../py/photonlibpy/generated/TargetCornerSerde.py | 7 +++---- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py index 5674849c30..53e381351b 100644 --- a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py @@ -36,7 +36,7 @@ class MultiTargetPNPResultSerde: MESSAGE_FORMAT = "PnpResult:ae4d655c0a3104d88df4f5db144c1e86 estimatedPose;int16 fiducialIDsUsed[?];" @staticmethod - def pack(value: 'MultiTargetPNPResult' ) -> 'Packet': + def pack(value: "MultiTargetPNPResult") -> "Packet": ret = Packet() # estimatedPose is of non-intrinsic type PnpResult @@ -46,9 +46,8 @@ def pack(value: 'MultiTargetPNPResult' ) -> 'Packet': ret.encodeShortList(value.fiducialIDsUsed) return ret - @staticmethod - def unpack(packet: 'Packet') -> 'MultiTargetPNPResult': + def unpack(packet: "Packet") -> "MultiTargetPNPResult": ret = MultiTargetPNPResult() # estimatedPose is of non-intrinsic type PnpResult @@ -61,4 +60,4 @@ def unpack(packet: 'Packet') -> 'MultiTargetPNPResult': # Hack ourselves into the base class -MultiTargetPNPResult.photonStruct = MultiTargetPNPResultSerde() \ No newline at end of file +MultiTargetPNPResult.photonStruct = MultiTargetPNPResultSerde() diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py index 79f5f11bb8..af4914aaac 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py @@ -35,7 +35,7 @@ class PhotonPipelineMetadataSerde: MESSAGE_FORMAT = "int64 sequenceID;int64 captureTimestampMicros;int64 publishTimestampMicros;int64 timeSinceLastPong;" @staticmethod - def pack(value: 'PhotonPipelineMetadata' ) -> 'Packet': + def pack(value: "PhotonPipelineMetadata") -> "Packet": ret = Packet() # sequenceID is of intrinsic type int64 @@ -51,9 +51,8 @@ def pack(value: 'PhotonPipelineMetadata' ) -> 'Packet': ret.encodeLong(value.timeSinceLastPong) return ret - @staticmethod - def unpack(packet: 'Packet') -> 'PhotonPipelineMetadata': + def unpack(packet: "Packet") -> "PhotonPipelineMetadata": ret = PhotonPipelineMetadata() # sequenceID is of intrinsic type int64 @@ -72,4 +71,4 @@ def unpack(packet: 'Packet') -> 'PhotonPipelineMetadata': # Hack ourselves into the base class -PhotonPipelineMetadata.photonStruct = PhotonPipelineMetadataSerde() \ No newline at end of file +PhotonPipelineMetadata.photonStruct = PhotonPipelineMetadataSerde() diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py index 374722e684..5023bfe2a4 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py @@ -38,11 +38,13 @@ class PhotonPipelineResultSerde: MESSAGE_FORMAT = "PhotonPipelineMetadata:ac0a45f686457856fb30af77699ea356 metadata;PhotonTrackedTarget:cc6dbb5c5c1e0fa808108019b20863f1 targets[?];optional MultiTargetPNPResult:541096947e9f3ca2d3f425ff7b04aa7b multitagResult;" @staticmethod - def pack(value: 'PhotonPipelineResult' ) -> 'Packet': + def pack(value: "PhotonPipelineResult") -> "Packet": ret = Packet() # metadata is of non-intrinsic type PhotonPipelineMetadata - ret.encodeBytes(PhotonPipelineMetadata.photonStruct.pack(value.metadata).getData()) + ret.encodeBytes( + PhotonPipelineMetadata.photonStruct.pack(value.metadata).getData() + ) # targets is a custom VLA! ret.encodeList(value.targets, PhotonTrackedTarget.photonStruct) @@ -51,9 +53,8 @@ def pack(value: 'PhotonPipelineResult' ) -> 'Packet': ret.encodeOptional(value.multitagResult, MultiTargetPNPResult.photonStruct) return ret - @staticmethod - def unpack(packet: 'Packet') -> 'PhotonPipelineResult': + def unpack(packet: "Packet") -> "PhotonPipelineResult": ret = PhotonPipelineResult() # metadata is of non-intrinsic type PhotonPipelineMetadata @@ -69,4 +70,4 @@ def unpack(packet: 'Packet') -> 'PhotonPipelineResult': # Hack ourselves into the base class -PhotonPipelineResult.photonStruct = PhotonPipelineResultSerde() \ No newline at end of file +PhotonPipelineResult.photonStruct = PhotonPipelineResultSerde() diff --git a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py index 509b04105f..f39f73a3ba 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py @@ -36,7 +36,7 @@ class PhotonTrackedTargetSerde: MESSAGE_FORMAT = "float64 yaw;float64 pitch;float64 area;float64 skew;int32 fiducialId;int32 objDetectId;float32 objDetectConf;Transform3d bestCameraToTarget;Transform3d altCameraToTarget;float64 poseAmbiguity;TargetCorner:16f6ac0dedc8eaccb951f4895d9e18b6 minAreaRectCorners[?];TargetCorner:16f6ac0dedc8eaccb951f4895d9e18b6 detectedCorners[?];" @staticmethod - def pack(value: 'PhotonTrackedTarget' ) -> 'Packet': + def pack(value: "PhotonTrackedTarget") -> "Packet": ret = Packet() # yaw is of intrinsic type float64 @@ -74,9 +74,8 @@ def pack(value: 'PhotonTrackedTarget' ) -> 'Packet': ret.encodeList(value.detectedCorners, TargetCorner.photonStruct) return ret - @staticmethod - def unpack(packet: 'Packet') -> 'PhotonTrackedTarget': + def unpack(packet: "Packet") -> "PhotonTrackedTarget": ret = PhotonTrackedTarget() # yaw is of intrinsic type float64 @@ -117,4 +116,4 @@ def unpack(packet: 'Packet') -> 'PhotonTrackedTarget': # Hack ourselves into the base class -PhotonTrackedTarget.photonStruct = PhotonTrackedTargetSerde() \ No newline at end of file +PhotonTrackedTarget.photonStruct = PhotonTrackedTargetSerde() diff --git a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py index 6f405f8920..ac83f16913 100644 --- a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py @@ -35,7 +35,7 @@ class PnpResultSerde: MESSAGE_FORMAT = "Transform3d best;Transform3d alt;float64 bestReprojErr;float64 altReprojErr;float64 ambiguity;" @staticmethod - def pack(value: 'PnpResult' ) -> 'Packet': + def pack(value: "PnpResult") -> "Packet": ret = Packet() ret.encodeTransform(value.best) @@ -52,9 +52,8 @@ def pack(value: 'PnpResult' ) -> 'Packet': ret.encodeDouble(value.ambiguity) return ret - @staticmethod - def unpack(packet: 'Packet') -> 'PnpResult': + def unpack(packet: "Packet") -> "PnpResult": ret = PnpResult() ret.best = packet.decodeTransform() @@ -74,4 +73,4 @@ def unpack(packet: 'Packet') -> 'PnpResult': # Hack ourselves into the base class -PnpResult.photonStruct = PnpResultSerde() \ No newline at end of file +PnpResult.photonStruct = PnpResultSerde() diff --git a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py index 9c6c847230..250ababf07 100644 --- a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py +++ b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py @@ -35,7 +35,7 @@ class TargetCornerSerde: MESSAGE_FORMAT = "float64 x;float64 y;" @staticmethod - def pack(value: 'TargetCorner' ) -> 'Packet': + def pack(value: "TargetCorner") -> "Packet": ret = Packet() # x is of intrinsic type float64 @@ -45,9 +45,8 @@ def pack(value: 'TargetCorner' ) -> 'Packet': ret.encodeDouble(value.y) return ret - @staticmethod - def unpack(packet: 'Packet') -> 'TargetCorner': + def unpack(packet: "Packet") -> "TargetCorner": ret = TargetCorner() # x is of intrinsic type float64 @@ -60,4 +59,4 @@ def unpack(packet: 'Packet') -> 'TargetCorner': # Hack ourselves into the base class -TargetCorner.photonStruct = TargetCornerSerde() \ No newline at end of file +TargetCorner.photonStruct = TargetCornerSerde() From 6ce15a15a03fc59f996f2a524c8d21d323c3fc3b Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Wed, 13 Nov 2024 23:15:41 +1100 Subject: [PATCH 16/16] fix import order --- photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py b/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py index d4eaf7e41c..985158db57 100644 --- a/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py +++ b/photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py @@ -4,8 +4,8 @@ from wpimath.geometry import Transform3d if TYPE_CHECKING: - from ..generated.PnpResultSerde import PnpResultSerde from ..generated.MultiTargetPNPResultSerde import MultiTargetPNPResultSerde + from ..generated.PnpResultSerde import PnpResultSerde @dataclass