mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 09:05:07 +00:00
all: More ruff fixes.
This commit is contained in:
@@ -26,7 +26,7 @@ def _is_async(self: _FunctionDefProperties) -> bool:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
return_type = self._obj.__annotations__["return"]
|
return_type = self._obj.__annotations__["return"]
|
||||||
except Exception:
|
except (AttributeError, KeyError):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return "MaybeAwaitable" in str(return_type)
|
return "MaybeAwaitable" in str(return_type)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.parsers.rst import Directive, directives
|
from docutils.parsers.rst import Directive, directives
|
||||||
@@ -35,7 +36,7 @@ JS_FILE = "requirements.js"
|
|||||||
|
|
||||||
class PybricksRequirementsDirective(Directive):
|
class PybricksRequirementsDirective(Directive):
|
||||||
has_content = True
|
has_content = True
|
||||||
option_spec = {"header": directives.unchanged}
|
option_spec: ClassVar = {"header": directives.unchanged}
|
||||||
|
|
||||||
required_arguments = 0
|
required_arguments = 0
|
||||||
optional_arguments = 10
|
optional_arguments = 10
|
||||||
|
|||||||
+3
-2
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
#
|
||||||
# Pybricks documentation build configuration file
|
# Pybricks documentation build configuration file
|
||||||
#
|
#
|
||||||
@@ -36,7 +35,9 @@ if tags.has("ide"): # noqa F821
|
|||||||
html_css_files.append("css/ide.css")
|
html_css_files.append("css/ide.css")
|
||||||
html_js_files = ["js/ide.js"]
|
html_js_files = ["js/ide.js"]
|
||||||
|
|
||||||
exec(open(os.path.abspath("../common/conf.py")).read())
|
# Shared config must run in this namespace so it sees the globals above.
|
||||||
|
with open(os.path.abspath("../common/conf.py")) as _f:
|
||||||
|
exec(_f.read()) # noqa: S102
|
||||||
|
|
||||||
# Build hub specific example scripts.
|
# Build hub specific example scripts.
|
||||||
sys.path.append(os.path.abspath("../../examples/pup/hub_common"))
|
sys.path.append(os.path.abspath("../../examples/pup/hub_common"))
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
from pybricks.messaging import BluetoothMailboxClient, TextMailbox
|
from pybricks.messaging import BluetoothMailboxClient, TextMailbox
|
||||||
|
|
||||||
# This demo makes your PC talk to an EV3 over Bluetooth.
|
# This demo makes your PC talk to an EV3 over Bluetooth.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
from pybricks.messaging import BluetoothMailboxServer, TextMailbox
|
from pybricks.messaging import BluetoothMailboxServer, TextMailbox
|
||||||
|
|
||||||
# This demo makes your PC talk to an EV3 over Bluetooth.
|
# This demo makes your PC talk to an EV3 over Bluetooth.
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
__pycache__/
|
|
||||||
*.pyc
|
|
||||||
.venv/
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
|
||||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
|
||||||
|
|
||||||
// List of extensions which should be recommended for users of this workspace.
|
|
||||||
"recommendations": [
|
|
||||||
"lego-education.ev3-micropython"
|
|
||||||
],
|
|
||||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-python.python"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Vendored
-15
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Download and Run",
|
|
||||||
"type": "ev3devBrowser",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "/home/robot/${workspaceRootFolderName}/main.py",
|
|
||||||
"interactiveTerminal": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
// Place your settings in this file to overwrite default and user settings.
|
|
||||||
{
|
|
||||||
"files.eol": "\n",
|
|
||||||
"debug.openDebug": "neverOpen",
|
|
||||||
"python.linting.enabled": false,
|
|
||||||
"python.languageServer": "None"
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
import struct
|
|
||||||
|
|
||||||
from pybricks.ev3devices import Motor
|
|
||||||
from pybricks.parameters import Port
|
|
||||||
|
|
||||||
# This program uses the two PS4 sticks to control two EV3 Large Servo Motors
|
|
||||||
# using tank like controls. For a full map of all PS4 buttons, trackpad, and
|
|
||||||
# motion checkout: https://github.com/codeadamca/python-connect-ps4
|
|
||||||
|
|
||||||
# Initialize EV3 motors
|
|
||||||
left_motor = Motor(Port.B)
|
|
||||||
right_motor = Motor(Port.C)
|
|
||||||
left_speed = 0
|
|
||||||
right_speed = 0
|
|
||||||
|
|
||||||
# Locate the event file you want to react to, on my setup the PS4 controller
|
|
||||||
# button events are located in /dev/input/event4
|
|
||||||
infile_path = "/dev/input/event4"
|
|
||||||
in_file = open(infile_path, "rb")
|
|
||||||
|
|
||||||
# Define the format the event data will be read.
|
|
||||||
# https://docs.python.org/3/library/struct.html#format-characters
|
|
||||||
FORMAT = "llHHi"
|
|
||||||
EVENT_SIZE = struct.calcsize(FORMAT)
|
|
||||||
event = in_file.read(EVENT_SIZE)
|
|
||||||
|
|
||||||
|
|
||||||
# A helper function for converting stick values (0 to 255) to more usable
|
|
||||||
# numbers (-100 to 100)
|
|
||||||
def scale(val, src, dst):
|
|
||||||
|
|
||||||
result = float(val - src[0]) / (src[1] - src[0])
|
|
||||||
result = result * (dst[1] - dst[0]) + dst[0]
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
# Create a loop to react to events
|
|
||||||
# This loop reacts to all main PS4 button and stick events. I have left out
|
|
||||||
# buttons like share and options, but can easily be added in by referring
|
|
||||||
# to the table at: https://github.com/codeadamca/python-connect-ps4
|
|
||||||
|
|
||||||
|
|
||||||
while event:
|
|
||||||
# Place event data into variables
|
|
||||||
(tv_sec, tv_usec, ev_type, code, value) = struct.unpack(FORMAT, event)
|
|
||||||
|
|
||||||
# If a button was pressed or released
|
|
||||||
if ev_type == 1:
|
|
||||||
# React to the X button
|
|
||||||
if code == 304 and value == 0:
|
|
||||||
print("The X button was released")
|
|
||||||
elif code == 304 and value == 1:
|
|
||||||
print("The X button was pressed")
|
|
||||||
|
|
||||||
# React to the Circle button
|
|
||||||
elif code == 305 and value == 0:
|
|
||||||
print("The Circle button was released")
|
|
||||||
elif code == 305 and value == 1:
|
|
||||||
print("The Circle button was pressed")
|
|
||||||
|
|
||||||
# React to the Triangle button
|
|
||||||
elif code == 307 and value == 0:
|
|
||||||
print("The Triangle button was released")
|
|
||||||
elif code == 307 and value == 1:
|
|
||||||
print("The Triangle button was pressed")
|
|
||||||
|
|
||||||
# React to the Square button
|
|
||||||
elif code == 308 and value == 0:
|
|
||||||
print("The Square button was released")
|
|
||||||
elif code == 308 and value == 1:
|
|
||||||
print("The Square button was pressed")
|
|
||||||
|
|
||||||
# React to the L1 button
|
|
||||||
elif code == 310 and value == 0:
|
|
||||||
print("The L1 button was released")
|
|
||||||
elif code == 310 and value == 1:
|
|
||||||
print("The L1 button was pressed")
|
|
||||||
|
|
||||||
# React to the R1 button
|
|
||||||
elif code == 311 and value == 0:
|
|
||||||
print("The R1 button was released")
|
|
||||||
elif code == 311 and value == 1:
|
|
||||||
print("The R1 button was pressed")
|
|
||||||
|
|
||||||
# React to the L2 button
|
|
||||||
elif code == 312 and value == 0:
|
|
||||||
print("The L2 button was released")
|
|
||||||
elif code == 312 and value == 1:
|
|
||||||
print("The L2 button was pressed")
|
|
||||||
|
|
||||||
# React to the R2 button
|
|
||||||
elif code == 313 and value == 0:
|
|
||||||
print("The R2 button was released")
|
|
||||||
elif code == 313 and value == 1:
|
|
||||||
print("The R2 button was pressed")
|
|
||||||
|
|
||||||
elif ev_type == 3:
|
|
||||||
# The sticks often trigger non-stop events, comment this out if you are
|
|
||||||
# not using the sticks as part of your project, or it becomes hard to
|
|
||||||
# read other data
|
|
||||||
|
|
||||||
# React to the left stick vertical
|
|
||||||
if code == 1:
|
|
||||||
print("The left stick vertical is at ", value)
|
|
||||||
left_speed = scale(value, (0, 255), (100, -100))
|
|
||||||
|
|
||||||
# React to the left stick horizontal
|
|
||||||
elif code == 0:
|
|
||||||
print("The left stick horizontal is at ", value)
|
|
||||||
|
|
||||||
# React to the right stick vertical
|
|
||||||
elif code == 4:
|
|
||||||
print("The right stick vertical is at ", value)
|
|
||||||
right_speed = scale(value, (0, 255), (100, -100))
|
|
||||||
|
|
||||||
# React to the right stick horizontal
|
|
||||||
elif code == 3:
|
|
||||||
print("The right stick horizontal is at ", value)
|
|
||||||
|
|
||||||
# React to the Directional pad
|
|
||||||
if code == 16 and value == -1:
|
|
||||||
print("The horizontal directional pad is left")
|
|
||||||
elif code == 16 and value == 1:
|
|
||||||
print("The horizontal directional pad is right")
|
|
||||||
elif code == 16 and value == 0:
|
|
||||||
print("The horizontal directional pad is released")
|
|
||||||
|
|
||||||
elif code == 17 and value == -1:
|
|
||||||
print("The vertical directional pad is up")
|
|
||||||
elif code == 17 and value == 1:
|
|
||||||
print("The horizontal directional pad is down")
|
|
||||||
elif code == 17 and value == 0:
|
|
||||||
print("The horizontal directional pad is released")
|
|
||||||
|
|
||||||
# Set motor speed
|
|
||||||
left_motor.dc(left_speed)
|
|
||||||
right_motor.dc(right_speed)
|
|
||||||
|
|
||||||
# Read the next event
|
|
||||||
event = in_file.read(EVENT_SIZE)
|
|
||||||
|
|
||||||
in_file.close()
|
|
||||||
+15
-17
@@ -23,14 +23,10 @@ import builtins
|
|||||||
from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, Sequence
|
from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, Sequence
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Dict,
|
|
||||||
List,
|
|
||||||
Literal,
|
Literal,
|
||||||
SupportsComplex,
|
SupportsComplex,
|
||||||
SupportsFloat,
|
SupportsFloat,
|
||||||
SupportsInt,
|
SupportsInt,
|
||||||
TypeVar,
|
|
||||||
Union,
|
|
||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,7 +46,9 @@ _complex = complex
|
|||||||
_dict = dict
|
_dict = dict
|
||||||
_float = float
|
_float = float
|
||||||
_int = int
|
_int = int
|
||||||
|
_list = list
|
||||||
_str = str
|
_str = str
|
||||||
|
_tuple = tuple
|
||||||
_type = type
|
_type = type
|
||||||
|
|
||||||
|
|
||||||
@@ -171,8 +169,8 @@ class bytes:
|
|||||||
def __init__(self, source: _str, encoding: _str) -> None: ...
|
def __init__(self, source: _str, encoding: _str) -> None: ...
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
r"""
|
"""
|
||||||
bytes()
|
bytes(\u200b)
|
||||||
bytes(integer)
|
bytes(integer)
|
||||||
bytes(iterable)
|
bytes(iterable)
|
||||||
bytes(string, encoding)
|
bytes(string, encoding)
|
||||||
@@ -207,8 +205,8 @@ class bytearray:
|
|||||||
def __init__(self, source: _bytes | _bytearray | _str | Iterable[_int]) -> None: ...
|
def __init__(self, source: _bytes | _bytearray | _str | Iterable[_int]) -> None: ...
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
r"""
|
"""
|
||||||
bytearray()
|
bytearray(\u200b)
|
||||||
bytearray(integer)
|
bytearray(integer)
|
||||||
bytearray(iterable)
|
bytearray(iterable)
|
||||||
bytearray(string)
|
bytearray(string)
|
||||||
@@ -328,17 +326,17 @@ class dict:
|
|||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def dir() -> list[_str]: ...
|
def dir() -> _list[_str]: ...
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def dir(object: Any) -> list[_str]: ...
|
def dir(object: Any) -> _list[_str]: ...
|
||||||
|
|
||||||
|
|
||||||
def dir(*args) -> list[_str]:
|
def dir(*args) -> _list[_str]:
|
||||||
"""
|
"""
|
||||||
dir() -> List[str]
|
dir() -> list[str]
|
||||||
dir(object) -> List[str]
|
dir(object) -> list[str]
|
||||||
|
|
||||||
Gets a list of attributes of an object.
|
Gets a list of attributes of an object.
|
||||||
|
|
||||||
@@ -354,11 +352,11 @@ def dir(*args) -> list[_str]:
|
|||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def divmod(a: _int, b: _int) -> tuple[_int, _int]: ...
|
def divmod(a: _int, b: _int) -> _tuple[_int, _int]: ...
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def divmod(a: _float, b: _float) -> tuple[_float, _float]: ...
|
def divmod(a: _float, b: _float) -> _tuple[_float, _float]: ...
|
||||||
|
|
||||||
|
|
||||||
def divmod(a, b):
|
def divmod(a, b):
|
||||||
@@ -689,7 +687,7 @@ class int:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def isinstance(object: Any, classinfo: _type | tuple[_type]) -> _bool:
|
def isinstance(object: Any, classinfo: _type | _tuple[_type]) -> _bool:
|
||||||
"""
|
"""
|
||||||
isinstance(object, classinfo) -> bool
|
isinstance(object, classinfo) -> bool
|
||||||
|
|
||||||
@@ -705,7 +703,7 @@ def isinstance(object: Any, classinfo: _type | tuple[_type]) -> _bool:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def issubclass(cls: _type, classinfo: _type | tuple[_type]) -> _bool:
|
def issubclass(cls: _type, classinfo: _type | _tuple[_type]) -> _bool:
|
||||||
"""
|
"""
|
||||||
issubclass(cls, classinfo) -> bool
|
issubclass(cls, classinfo) -> bool
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
This module provides access to symbolic error codes for `OSError` exception.
|
This module provides access to symbolic error codes for `OSError` exception.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
EAGAIN: int
|
EAGAIN: int
|
||||||
"""
|
"""
|
||||||
The operation is not complete and should be tried again soon.
|
The operation is not complete and should be tried again soon.
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ This module contains ``stream`` objects that behave like files.
|
|||||||
|
|
||||||
# TODO: open() is not implemented on Powered Up hubs
|
# TODO: open() is not implemented on Powered Up hubs
|
||||||
|
|
||||||
from typing import Union, overload
|
from typing import overload
|
||||||
|
|
||||||
# TODO: MicroPython streams implement '__enter__', '__exit__', 'close', 'read',
|
# TODO: MicroPython streams implement '__enter__', '__exit__', 'close', 'read',
|
||||||
# 'readinto', 'readline', 'write', 'flush', 'seek', 'tell'
|
# 'readinto', 'readline', 'write', 'flush', 'seek', 'tell'
|
||||||
|
|||||||
Reference in New Issue
Block a user