Skip to content

Commit

Permalink
Merge pull request #102 from VEX-Robotics-AI/lint
Browse files Browse the repository at this point in the history
enable PyLint
  • Loading branch information
TheVinhLuong102 authored Nov 9, 2023
2 parents 900ca4e + dc3610a commit e00cf43
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 49 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run tests
name: Install, Lint & Test

on:
push:
Expand All @@ -20,20 +20,20 @@ jobs:
# github.com/actions/python-versions/blob/main/versions-manifest.json

steps:
- name: Checkout repo
- name: Checkout Repo
uses: actions/checkout@v2

- name: Set Up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
- name: Install Python Module(s)/Package(s) & Dependencies
run: make install-editable

- name: Lint Python Code
run: make lint-all

- name: Install pytest
run: |
python -m pip install --upgrade pip
Expand Down
5 changes: 4 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[MESSAGES CONTROL]

disable=
isinstance-second-argument-not-valid-type,
duplicate-code,
invalid-name,
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
install-editable:
@ install/install-editable

lint-all:
@ lint/all
4 changes: 4 additions & 0 deletions lint/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash


lint/pylint
1 change: 1 addition & 0 deletions lint/all.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint/pylint.bat
4 changes: 4 additions & 0 deletions lint/pylint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash


pylint src/
1 change: 1 addition & 0 deletions lint/pylint.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pylint src/
16 changes: 8 additions & 8 deletions src/drivetrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class Drivetrain: # pylint: disable=too-many-instance-attributes
a DistanceUnits enum value
- gear_ratio: external gear ratio, usually 1.0
""")
def __init__(
self,
def __init__( # pylint: disable=too-many-arguments
self: Self,
left_motor: DrivetrainMotorType, right_motor: DrivetrainMotorType,
wheel_travel: Num = 200, track_width: Num = 176,
distanceUnits: DistanceUnits = DistanceUnits.MM,
Expand Down Expand Up @@ -128,8 +128,8 @@ def drive(self: Self, directionType: DirectionType,
True if the drivetrain has reached the target distance, False otherwise
""")
@act
def drive_for(
self, directionType: DirectionType,
def drive_for( # pylint: disable=too-many-arguments
self: Self, directionType: DirectionType,
distance: Num, distanceUnits: DistanceUnits = DistanceUnits.MM,
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT,
Expand All @@ -150,8 +150,8 @@ def drive_for(
a VelocityUnits enum value
""")
@act
def start_drive_for(
self, directionType: DirectionType,
def start_drive_for( # pylint: disable=too-many-arguments
self: Self, directionType: DirectionType,
distance: Num, distanceUnits: DistanceUnits = DistanceUnits.MM,
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT, /):
Expand Down Expand Up @@ -193,7 +193,7 @@ def turn(self: Self, turnType: TurnType,
Reimplemented from drivetrain.Drivetrain.
""")
@act
def turn_for(self: Self, turnType: TurnType,
def turn_for(self: Self, turnType: TurnType, # pylint: disable=too-many-arguments
angle: Num, rotationUnits: RotationUnits = RotationUnits.DEG, # noqa: E501
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT,
Expand All @@ -216,7 +216,7 @@ def turn_for(self: Self, turnType: TurnType,
Reimplemented in smartdrive.Smartdrive.
""")
@act
def start_turn_for(self: Self, turnType: TurnType,
def start_turn_for(self: Self, turnType: TurnType, # pylint: disable=too-many-arguments
angle: Num, angleUnits: RotationUnits = RotationUnits.DEG, # noqa: E501
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT, /):
Expand Down
11 changes: 6 additions & 5 deletions src/motor_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from vex.motor.torque import TorqueUnits
from vex.time.units import TimeUnits
from vex._common_enums.rotation import RotationUnits
from vex._common_enums.percent import PERCENT
from vex._common_enums.velocity import VelocityUnits

from vex._util.doc import robotmesh_doc
Expand Down Expand Up @@ -197,7 +198,7 @@ def spin(self: Self,
By default, this parameter is true.
""")
@act
def spin_to(self: Self,
def spin_to(self: Self, # pylint: disable=too-many-arguments
rotation: Num, rotationUnits: RotationUnits = RotationUnits.DEG, # noqa: E501
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT,
Expand Down Expand Up @@ -226,7 +227,7 @@ def spin_to(self: Self,
By default, this parameter is true.
""")
@act
def spin_for(self: Self,
def spin_for(self: Self, # pylint: disable=too-many-arguments
dir: DirectionType, # pylint: disable=redefined-builtin
rotation: Num, rotationUnits: RotationUnits = RotationUnits.DEG, # noqa: E501
velocity: Optional[Num] = None,
Expand All @@ -247,7 +248,7 @@ def spin_for(self: Self,
a VelocityUnits enum value.
""")
@act
def spin_for_time(self: Self,
def spin_for_time(self: Self, # pylint: disable=too-many-arguments
dir: DirectionType, # pylint: disable=redefined-builtin
time: Num, timeUnits: TimeUnits = TimeUnits.SEC,
velocity: Optional[Num] = None,
Expand Down Expand Up @@ -286,7 +287,7 @@ def start_spin_to(self: Self,
- velocityUnits: The measurement unit for the velocity value.
""")
@act
def start_spin_for(self: Self,
def start_spin_for(self: Self, # pylint: disable=too-many-arguments
dir: DirectionType, # pylint: disable=redefined-builtin
rotation: Num,
rotationUnits: RotationUnits = RotationUnits.DEG, # noqa: E501
Expand Down Expand Up @@ -335,7 +336,7 @@ def stop(self: Self, brakeType: Optional[BrakeType] = None, /):
@act
def set_max_torque_percent(self: Self, value: int, /):
"""Set max torque percentage level."""
self.max_torque[TorqueUnits.PCT] = value
self.max_torque[PERCENT] = value

@robotmesh_doc("""
Set the max torque of all motors.
Expand Down
12 changes: 6 additions & 6 deletions src/smartdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Smartdrive(Drivetrain):
a DistanceUnits enum value
- gear_ratio: external gear ratio, usually 1.0
""")
def __init__(
self,
def __init__( # pylint: disable=too-many-arguments
self: Self,
left_motor: DrivetrainMotorType, right_motor: DrivetrainMotorType,
gyro: Gyro,
wheel_travel: Num = 200, track_width: Num = 176,
Expand Down Expand Up @@ -100,8 +100,8 @@ def __hash__(self: Self) -> int:
By default, this parameter is true.
""")
@act
def turn_to_heading(
self,
def turn_to_heading( # pylint: disable=too-many-arguments
self: Self,
angle: Num, angleUnits: RotationUnits = RotationUnits.DEG,
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT,
Expand All @@ -112,8 +112,8 @@ def turn_to_heading(
Turn to rotation.
""")
@act
def turn_to_rotation(
self,
def turn_to_rotation( # pylint: disable=too-many-arguments
self: Self,
angle: Num, angleUnits: RotationUnits = RotationUnits.DEG,
velocity: Optional[Num] = None,
velocityUnits: VelocityUnits = VelocityUnits.PCT,
Expand Down
2 changes: 1 addition & 1 deletion src/vex/_common_enums/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ class DistanceUnits(IntEnum):
INCHES: DistanceUnits = DistanceUnits.IN


class _Distance(_MeasurementWithUnitABC):
class _Distance(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: DistanceUnits = MM
2 changes: 1 addition & 1 deletion src/vex/_common_enums/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class PowerUnits(IntEnum):
WATT: int = 0 # unit representing values of power in watts


class _Power(_MeasurementWithUnitABC):
class _Power(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: PowerUnits = PowerUnits.WATT
2 changes: 1 addition & 1 deletion src/vex/_common_enums/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ class RotationUnits(IntEnum):
TURNS: RotationUnits = RotationUnits.REV


class _Rotation(_MeasurementWithUnitABC):
class _Rotation(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: RotationUnits = DEGREES
2 changes: 1 addition & 1 deletion src/vex/_common_enums/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class TemperatureUnits(IntEnum):
PCT: int = 0xFF


class _Temperature(_MeasurementWithUnitABC):
class _Temperature(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
measurement: float
unit: TemperatureUnits = TemperatureUnits.CELSIUS
2 changes: 1 addition & 1 deletion src/vex/_common_enums/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ class VelocityUnits(IntEnum):
DPS: VelocityUnits = VelocityUnits.DPS


class _Velocity(_MeasurementWithUnitABC):
class _Velocity(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: VelocityUnits = RPM
3 changes: 3 additions & 0 deletions src/vex/_util/io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""IO Utilities."""


from contextlib import contextmanager
from io import StringIO
import sys
Expand Down
2 changes: 1 addition & 1 deletion src/vex/controller/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections.abc import Callable, Sequence
from threading import Thread
from typing import LiteralString, Self, TypeVar # noqa: F401
from typing import LiteralString, Self

from abm.decor import sense

Expand Down
29 changes: 17 additions & 12 deletions src/vex/motor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Motor."""


# pylint: disable=too-many-lines


from collections.abc import Sequence
from typing import Literal, LiteralString, Optional, Self, overload

Expand Down Expand Up @@ -90,7 +93,8 @@ def __init__(self: Self, index: Ports, /, *args: GearSetting | bool) -> None: #
self.gear_setting, self.reverse = args

assert isinstance(self.gear_setting, GearSetting), \
TypeError(f'*** 2ND ARG gearSetting={self.gear_setting} NOT GearSetting ***') # noqa: E501
TypeError(f'*** 2ND ARG gearSetting={self.gear_setting} '
'NOT GearSetting ***')

assert isinstance(self.reverse, bool), \
TypeError(f'*** 3ND ARG reverse={self.reverse} NOT BOOL ***')
Expand Down Expand Up @@ -493,8 +497,8 @@ def spin_for(self: Self, direction: DirectionType,
...

@overload
def spin_for(
self,
def spin_for( # pylint: disable=too-many-arguments
self: Self,
dir: Optional[DirectionType], # pylint: disable=redefined-builtin
rotation: Num,
rotationUnits: RotationUnits = RotationUnits.DEG,
Expand Down Expand Up @@ -641,7 +645,7 @@ def spin_to_position(self: Self,
By default, this parameter is true.
""")
@act
def spin_to(self: Self,
def spin_to(self: Self, # pylint: disable=too-many-arguments
rotation: Num,
rotationUnits: RotationUnits = RotationUnits.DEG,
velocity: Optional[Num] = None,
Expand Down Expand Up @@ -677,8 +681,8 @@ def spin_to(self: Self,
- velocityUnits: measurement unit for velocity
""")
@act
def spin_for_time(
self,
def spin_for_time( # pylint: disable=too-many-arguments
self: Self,
dir: Optional[DirectionType], # pylint: disable=redefined-builtin
time: Num,
timeUnits: TimeUnits = TimeUnits.SEC,
Expand Down Expand Up @@ -713,8 +717,8 @@ def spin_for_time(
- velocityUnits: measurement unit for velocity
""")
@act
def start_spin_for(
self,
def start_spin_for( # pylint: disable=too-many-arguments
self: Self,
dir: Optional[DirectionType], # pylint: disable=redefined-builtin
rotation: Num,
rotationUnits: RotationUnits = RotationUnits.DEG,
Expand Down Expand Up @@ -988,12 +992,13 @@ def efficiency(
Returns: temperature of motor in unit defined
""")
@sense
def temperature(
self: Self,
temperatureUnits: TemperatureUnits = TemperatureUnits.CELSIUS, /) -> float: # noqa: E501
def temperature(self: Self,
temperatureUnits: TemperatureUnits = TemperatureUnits.CELSIUS, # noqa: E501
/) -> float:
"""Return temperature."""
assert isinstance(temperatureUnits, TemperatureUnits), \
TypeError(f'*** temperatureUnits={temperatureUnits} NOT OF TYPE TemperatureUnits ***') # noqa: E501
TypeError(f'*** temperatureUnits={temperatureUnits} '
'NOT OF TYPE TemperatureUnits ***')

@robotmesh_doc("""
Get device type
Expand Down
2 changes: 1 addition & 1 deletion src/vex/motor/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class CurrentUnits(IntEnum):
AMP: int = auto()


class _Current(_MeasurementWithUnitABC):
class _Current(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: CurrentUnits = CurrentUnits.AMP
2 changes: 1 addition & 1 deletion src/vex/motor/efficiency.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
__all__: Sequence[LiteralString] = ('_Efficiency',)


class _Efficiency(_MeasurementWithUnitABC):
class _Efficiency(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
measurement: float
unit: PercentUnits | Literal[PERCENT] = PERCENT
2 changes: 1 addition & 1 deletion src/vex/motor/torque.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ class TorqueUnits(IntEnum):
IN_LB: int = 1 # torque unit measured in Inch Pounds


class _Torque(_MeasurementWithUnitABC):
class _Torque(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: TorqueUnits | PercentUnits | Literal[PERCENT] = PERCENT
2 changes: 1 addition & 1 deletion src/vex/motor/voltage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class VoltageUnits(IntEnum):
MV: int = 1


class _Voltage(_MeasurementWithUnitABC):
class _Voltage(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: VoltageUnits = VoltageUnits.VOLT
1 change: 1 addition & 0 deletions src/vex/multi_device_group/drive_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DriveTrain(MotorGroup): # pylint: disable=too-many-instance-attributes
def __init__(self: Self, left_motor: Motor, right_motor: Motor,
wheel_base: float = 200, track_width: float = 176,
length_unit: DistanceUnits = MM, gear_ratio: float = 1, /):
# pylint: disable=too-many-arguments
"""Initialize Drivetrain."""
super().__init__(left_motor, right_motor)

Expand Down
2 changes: 1 addition & 1 deletion src/vex/time/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ class TimeUnits(IntEnum):
MSEC: TimeUnits = TimeUnits.MSEC


class _Time(_MeasurementWithUnitABC):
class _Time(_MeasurementWithUnitABC): # pylint: disable=too-few-public-methods
unit: TimeUnits = SECONDS
1 change: 1 addition & 0 deletions src/vex/touch_led/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def blink_hue(self: Self, colorHue: Color,
@act
def blink_rgb(self: Self, red: int, green: int, blue: int,
on_time: float = 0.25, off_time: float = 0.25, /):
# pylint: disable=too-many-arguments
"""Blink RGB color."""

@robotmesh_doc("""
Expand Down

0 comments on commit e00cf43

Please sign in to comment.