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

add mypy to ci #1570

Merged
merged 16 commits into from
Nov 13, 2024
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
9 changes: 8 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,6 +50,13 @@ 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 --config-file photon-lib/py/pyproject.toml photon-lib


- name: Upload artifacts
uses: actions/upload-artifact@master
Expand Down
1 change: 0 additions & 1 deletion photon-lib/py/photonlibpy/estimation/openCVHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion photon-lib/py/photonlibpy/estimation/targetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def __init__(
verts: List[Translation3d] | None = None
):

self.vertices: List[Translation3d] = []

if (
width is not None
and height is not None
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions photon-lib/py/photonlibpy/estimation/visionEstimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
## --> DO NOT MODIFY <--
###############################################################################

from typing import TYPE_CHECKING

from ..packet import Packet
from ..targeting import *
from ..targeting import * # noqa

if TYPE_CHECKING:
from ..targeting import MultiTargetPNPResult # noqa
from ..targeting import PnpResult # noqa


class MultiTargetPNPResultSerde:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
## --> DO NOT MODIFY <--
###############################################################################

from typing import TYPE_CHECKING

from ..packet import Packet
from ..targeting import *
from ..targeting import * # noqa

if TYPE_CHECKING:
from ..targeting import PhotonPipelineMetadata # noqa


class PhotonPipelineMetadataSerde:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
## --> DO NOT MODIFY <--
###############################################################################

from typing import TYPE_CHECKING

from ..packet import Packet
from ..targeting import *
from ..targeting import * # noqa

if TYPE_CHECKING:
from ..targeting import MultiTargetPNPResult # noqa
from ..targeting import PhotonPipelineMetadata # noqa
from ..targeting import PhotonPipelineResult # noqa
from ..targeting import PhotonTrackedTarget # noqa


class PhotonPipelineResultSerde:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
## --> DO NOT MODIFY <--
###############################################################################

from typing import TYPE_CHECKING

from ..packet import Packet
from ..targeting import *
from ..targeting import * # noqa

if TYPE_CHECKING:
from ..targeting import PhotonTrackedTarget # noqa
from ..targeting import TargetCorner # noqa


class PhotonTrackedTargetSerde:
Expand Down
7 changes: 6 additions & 1 deletion photon-lib/py/photonlibpy/generated/PnpResultSerde.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
## --> DO NOT MODIFY <--
###############################################################################

from typing import TYPE_CHECKING

from ..packet import Packet
from ..targeting import *
from ..targeting import * # noqa

if TYPE_CHECKING:
from ..targeting import PnpResult # noqa


class PnpResultSerde:
Expand Down
7 changes: 6 additions & 1 deletion photon-lib/py/photonlibpy/generated/TargetCornerSerde.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
## --> DO NOT MODIFY <--
###############################################################################

from typing import TYPE_CHECKING

from ..packet import Packet
from ..targeting import *
from ..targeting import * # noqa

if TYPE_CHECKING:
from ..targeting import TargetCorner # noqa


class TargetCornerSerde:
Expand Down
14 changes: 8 additions & 6 deletions photon-lib/py/photonlibpy/simulation/photonCameraSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions photon-lib/py/photonlibpy/simulation/simCameraProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions photon-lib/py/photonlibpy/simulation/visionSystemSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions photon-lib/py/photonlibpy/targeting/TargetCorner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import TYPE_CHECKING, ClassVar

if TYPE_CHECKING:
from .. import generated
from ..generated.TargetCornerSerde import TargetCornerSerde


@dataclass
class TargetCorner:
x: float = 0
y: float = 9

photonStruct: ClassVar["generated.TargetCornerSerde"]
photonStruct: ClassVar["TargetCornerSerde"]
7 changes: 4 additions & 3 deletions photon-lib/py/photonlibpy/targeting/multiTargetPNPResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from wpimath.geometry import Transform3d

if TYPE_CHECKING:
from .. import generated
from ..generated.MultiTargetPNPResultSerde import MultiTargetPNPResultSerde
from ..generated.PnpResultSerde import PnpResultSerde


@dataclass
Expand All @@ -15,7 +16,7 @@ class PnpResult:
bestReprojErr: float = 0.0
altReprojErr: float = 0.0

photonStruct: ClassVar["generated.PnpResultSerde"]
photonStruct: ClassVar["PnpResultSerde"]


@dataclass
Expand All @@ -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"]
7 changes: 4 additions & 3 deletions photon-lib/py/photonlibpy/targeting/photonPipelineResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +21,7 @@ class PhotonPipelineMetadata:

timeSinceLastPong: int = -1

photonStruct: ClassVar["generated.PhotonPipelineMetadataSerde"]
photonStruct: ClassVar["PhotonPipelineMetadataSerde"]


@dataclass
Expand Down Expand Up @@ -69,4 +70,4 @@ def getBestTarget(self) -> Optional[PhotonTrackedTarget]:
return None
return self.getTargets()[0]

photonStruct: ClassVar["generated.PhotonPipelineResultSerde"]
photonStruct: ClassVar["PhotonPipelineResultSerde"]
4 changes: 2 additions & 2 deletions photon-lib/py/photonlibpy/targeting/photonTrackedTarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .TargetCorner import TargetCorner

if TYPE_CHECKING:
from .. import generated
from ..generated.PhotonTrackedTargetSerde import PhotonTrackedTargetSerde


@dataclass
Expand Down Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions photon-lib/py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.mypy]
exclude = ["build","setup.py"]
Loading
Loading