From a424d1cf86c01ca0a70a18d99a32728c40e9a369 Mon Sep 17 00:00:00 2001 From: aidnem <99768676+aidnem@users.noreply.github.com> Date: Fri, 16 May 2025 17:30:27 -0400 Subject: [PATCH 1/2] (#36) Remove TypeError on python 3.11 --- config.json | 13 +++++++++++++ pyproject.toml | 3 +++ src/robotvibecoder/config.py | 17 +++++++++++++++++ src/robotvibecoder/subcommands/new.py | 9 ++++++--- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..a6da380 --- /dev/null +++ b/config.json @@ -0,0 +1,13 @@ +{ + "package": "subsystems.test", + "name": "Test", + "kind": "Elevator", + "canbus": "canivore", + "motors": [ + "Beans", + "Beans", + "Beans" + ], + "lead_motor": "Beans", + "encoder": "Beans" +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index e81eba1..c2ba8c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,9 @@ robotvibecoder = "robotvibecoder.main:main" [tool.hatch.version] source = "versioningit" +[tool.hatch.metadata] +allow-direct-references = true + [tool.hatch.envs.types] extra-dependencies = ["mypy>=1.0.0"] [tool.hatch.envs.types.scripts] diff --git a/src/robotvibecoder/config.py b/src/robotvibecoder/config.py index 13e1f06..61bf555 100644 --- a/src/robotvibecoder/config.py +++ b/src/robotvibecoder/config.py @@ -9,6 +9,7 @@ from enum import Enum import json import sys +from typing import Union from robotvibecoder.cli import print_err @@ -24,6 +25,22 @@ class MechanismKind(str, Enum): ELEVATOR = "Elevator" FLYWHEEL = "Flywheel" + @staticmethod + def try_into(value: str) -> Union["MechanismKind", None]: + """Try to parse a string into a MechanismKind. + Returns none if the string isn't a valid MechanismKind. + + :param value: The string to convert + :type value: str + :return: A MechanismKind if value is a valid Mechanism Kind, otherwise none + :rtype: MechanismKind | None + """ + for kind in MechanismKind: + if value == kind: + return kind + + return None + @dataclass class MechanismConfig: diff --git a/src/robotvibecoder/subcommands/new.py b/src/robotvibecoder/subcommands/new.py index d233482..f3b25d5 100644 --- a/src/robotvibecoder/subcommands/new.py +++ b/src/robotvibecoder/subcommands/new.py @@ -29,11 +29,14 @@ def new_config_interactive() -> MechanismConfig: print("Kind: Should be either 'Elevator', 'Arm', or 'Flywheel'") kind: str = "" - while kind not in MechanismKind: + while MechanismKind.try_into(kind) is None: kind = input("> ") - if kind not in MechanismKind: + if MechanismKind.try_into(kind) is None: print("Please input either Elevator, Arm, or Flywheel.") - kind_enum: MechanismKind = MechanismKind[kind] + kind_try = MechanismKind.try_into(kind) + kind_enum: MechanismKind = ( + kind_try if kind_try is not None else MechanismKind.ELEVATOR + ) print("CAN Bus: whatever the name of the mechanism's bus is (e.g. `canivore`)") canbus: str = input("> ") From 537a433c47dbd9ca262593d8206810a839ac652f Mon Sep 17 00:00:00 2001 From: aidnem <99768676+aidnem@users.noreply.github.com> Date: Fri, 16 May 2025 17:30:52 -0400 Subject: [PATCH 2/2] (#36) Remove accidental testing config.json --- config.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 config.json diff --git a/config.json b/config.json deleted file mode 100644 index a6da380..0000000 --- a/config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "package": "subsystems.test", - "name": "Test", - "kind": "Elevator", - "canbus": "canivore", - "motors": [ - "Beans", - "Beans", - "Beans" - ], - "lead_motor": "Beans", - "encoder": "Beans" -} \ No newline at end of file