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
14 changes: 13 additions & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,26 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8 pytest mypy # Add mypy here
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Generate and Test Stubs (stubtest)
run: |
if [ -d dobotWrapperPy ]; then # Check if the directory exists
pip install -e .
fi

mkdir -p stubs/

stubgen -p dobotWrapperPy -o stubs/

stubtest dobotWrapperPy

- name: Test with pytest
run: |
pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,5 @@ cython_debug/

py_env
test_docs

stubs/
3 changes: 1 addition & 2 deletions dobotWrapperPy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .dobot import Dobot
from .dobotapi import DobotApi
from .dobotConnection import DobotConnection
from .dobotasync import DobotAsync

__all__ = ["Dobot", "DobotApi", "DobotConnection", "DobotAsync"]
__all__ = ["DobotApi", "DobotConnection", "DobotAsync"]
67 changes: 0 additions & 67 deletions dobotWrapperPy/dobot.py

This file was deleted.

2 changes: 1 addition & 1 deletion dobotWrapperPy/dobotConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class DobotConnection:

serial_conn: serial.Serial
serial_conn: serial.SerialBase

def __init__(
self, port: Optional[str] = None, serial_conn: Optional[serial.Serial] = None
Expand Down
13 changes: 7 additions & 6 deletions dobotWrapperPy/dobotControlGUI.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .dobotasync import DobotAsync
import asyncio
import tkinter as tk
from typing import Callable, Awaitable, Any, Dict
from typing import Callable
import typing
import threading


Expand Down Expand Up @@ -76,10 +77,10 @@ def create_styled_button(
btn.pack(side="left", padx=10, pady=5, ipadx=5, ipady=2)

# Explicitly typed event handlers for hover effects
def on_enter(event: Any) -> None:
def on_enter(event: typing.Any) -> None:
btn.config(bg="#0056b3")

def on_leave(event: Any) -> None:
def on_leave(event: typing.Any) -> None:
btn.config(bg="#007bff")

btn.bind("<Enter>", on_enter)
Expand Down Expand Up @@ -140,10 +141,10 @@ def create_styled_button_grid(
)

# Basic hover effect
def on_enter(event: Any) -> None:
def on_enter(event: typing.Any) -> None:
btn.config(bg="#0056b3")

def on_leave(event: Any) -> None:
def on_leave(event: typing.Any) -> None:
btn.config(bg="#007bff")

btn.bind("<Enter>", on_enter)
Expand Down Expand Up @@ -272,7 +273,7 @@ def _initial_connect_wrapper(self) -> None:
"""Wrapper to run _initial_connect as an asyncio task."""
asyncio.create_task(self._initial_connect())

def _schedule_dobot_task(self, task_coro: Awaitable[Any], description: str) -> None:
def _schedule_dobot_task(self, task_coro: typing.Awaitable[typing.Any], description: str) -> None:
"""
Helper to schedule an asynchronous Dobot task and update the GUI status.
This method is called from the Tkinter thread, so it uses call_soon_threadsafe
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/dobotSupliment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import math
from typing import Tuple
from enum import Enum
import enum


class Direction(Enum):
class Direction(enum.Enum):
POSITIVE = 1
NEGATIVE = -1

Expand Down
9 changes: 4 additions & 5 deletions dobotWrapperPy/dobotapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
self.verbose = verbose
self.lock = threading.Lock()
self.conn = dobot_connection
is_open = self.conn.serial_conn.isOpen()
is_open = self.conn.serial_conn.is_open
if self.verbose:
print(
"dobot: %s open" % self.conn.serial_conn.name
Expand All @@ -106,9 +106,8 @@ def close(self) -> None:
hasattr(self, "conn")
and self.conn is not None
and hasattr(self.conn, "serial_conn")
and self.conn.serial_conn
is not None # Ensure serial_conn itself is not None
and hasattr(self.conn.serial_conn, "name")
and self.conn.serial_conn is not None
and self.conn.serial_conn.name is not None
):
port_name = self.conn.serial_conn.name
print(f"dobot: {port_name} closed")
Expand Down Expand Up @@ -261,7 +260,7 @@ def _read_message(self) -> Optional[Message]:
"""
time.sleep(0.05) # Allow data to arrive
byte_buffer = self.conn.serial_conn.read_all()
if len(byte_buffer) > 0:
if byte_buffer is not None and len(byte_buffer) > 0:
msg = Message(byte_buffer)
if self.verbose:
print("dobot: <<", msg)
Expand Down
11 changes: 6 additions & 5 deletions dobotWrapperPy/dobotasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
tagARCCmd,
)
import asyncio
from typing import Tuple, Optional, Set, Any, Callable, Awaitable, TypeVar
from enum import Enum
from typing import Tuple, Optional, Set, Callable, TypeVar
import typing
import enum
import signal
import sys


class EndEffectorType(Enum):
class EndEffectorType(enum.Enum):
CUP = 0
GRIPPER = 1
LASER = 2
Expand All @@ -64,7 +65,7 @@ async def connect(self) -> None:
self._loop = asyncio.get_running_loop()
self.dobotApiInterface.initialize_robot()

def _on_sigint(self, signum: int, frame: Optional[Any]) -> None:
def _on_sigint(self, signum: int, frame: Optional[typing.Any]) -> None:
print("SIGINT received. Force Stopping robot...")
self.force_stop()
match self._endEffectorType:
Expand All @@ -84,7 +85,7 @@ def __del__(self) -> None:
if hasattr(self, "dobotApiInterface") and self.dobotApiInterface is not None:
del self.dobotApiInterface

def _run_in_loop(self, func: Callable[..., _T], *args: Any) -> Awaitable[_T]:
def _run_in_loop(self, func: Callable[..., _T], *args: typing.Any) -> typing.Awaitable[_T]:
if self._loop is None:
raise Exception("Dobot not connected")
return self._loop.run_in_executor(None, func, *args)
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/CPMode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class CPMode(Enum):
class CPMode(enum.Enum):
RELATIVE = 0
ABSOLUTE = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/CommunicationProtocolIDs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import enum


class CommunicationProtocolIDs(Enum):
class CommunicationProtocolIDs(enum.Enum):
# INFO
DEVICE_INFO_BASE = 0
DEVICE_SN = DEVICE_INFO_BASE + 0
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/EMotorIndex.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class EMotorIndex(Enum):
class EMotorIndex(enum.Enum):
STEPPER1 = 0
STEPPER2 = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/HHTTrigMode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class HHTTrigMode(Enum):
class HHTTrigMode(enum.Enum):
TriggeredOnKeyRelease = 0x0
TriggeredOnPeriodicInterval = 0x1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/IOFunction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import enum


class IOFunction(Enum):
class IOFunction(enum.Enum):
DUMMY = 0 # Do not config
DO = 1 # IO output
PWM = 2 # PWM Output
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/alarm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from enum import Enum
import struct
import enum


class Alarm(Enum):
class Alarm(enum.Enum):
COMMON_RESETTING = 0x00
COMMON_UNDEFINED_INSTRUCTION = 0x01
COMMON_FILE_SYSTEM = 0x02
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/jogCmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import enum


class JogCmd(Enum):
class JogCmd(enum.Enum):
IDEL = 0 # Void
AP_DOWN = 1 # X+/Joint1+
AN_DOWN = 2 # X-/Joint1-
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/jogMode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class JogMode(Enum):
class JogMode(enum.Enum):
COORDINATE = 0
JOINT = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/level.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class Level(Enum):
class Level(enum.Enum):
LOW = 0
HIGH = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/ptpMode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import enum


class PTPMode(Enum):
class PTPMode(enum.Enum):
"""
1. JUMP_XYZ,
Jump mode,
Expand Down
Empty file removed dobotWrapperPy/enums/py.typed
Empty file.
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/realTimeTrack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class RealTimeTrack(Enum):
class RealTimeTrack(enum.Enum):
NONREALTIME = 0
REALTIME = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/tagVersionColorSensorAndIR.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class TagVersionColorSensorAndIR(Enum):
class TagVersionColorSensorAndIR(enum.Enum):
VERSION1 = 0
VERSION2 = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/tagVersionRail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class tagVersionRail(Enum):
class tagVersionRail(enum.Enum):
VER_V1 = 0
VER_V2 = 1
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/triggerCondition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import enum


class TriggerCondition(Enum):
class TriggerCondition(enum.Enum):
LEVEL_EQUAL = 0
AD_LESS = 0
LEVEL_UNEQUAL = 1
Expand Down
4 changes: 2 additions & 2 deletions dobotWrapperPy/enums/triggerMode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import enum


class TriggerMode(Enum):
class TriggerMode(enum.Enum):
LEVEL = 0
AD = 1
9 changes: 9 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
[mypy]
strict = True
python_version = 3.13
ignore_errors = True

[mypy-dobotWrapperPy]
namespace_packages = True
ignore_missing_imports = True

[stubtest]
custom_typeshed_dir = stubs/
Loading