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

Iterables #7

Merged
merged 50 commits into from
Apr 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
78e9ab3
Removed unecessary platform specific decorations
luis-camero Mar 28, 2023
f4e0dee
Added base decorations config
luis-camero Mar 28, 2023
c0d1346
Removed PACS specific configs
luis-camero Mar 28, 2023
d9d1fad
Added get and set functions to ListConfig
luis-camero Mar 28, 2023
99698ec
Fixed assertion indenting
luis-camero Mar 28, 2023
e530093
Removed unused imports
luis-camero Mar 28, 2023
5d5b36c
Fixed assertion indenting
luis-camero Mar 28, 2023
5902e23
Updated A200 to iterable decorations
luis-camero Mar 28, 2023
e54062c
Updated J100 to iterable decorations
luis-camero Mar 28, 2023
9e1f353
Updated path to config in Platform
luis-camero Mar 28, 2023
240487b
Updated path to base decorations config
luis-camero Mar 28, 2023
f2b5984
Switched parser to new decorations config
luis-camero Mar 28, 2023
6ccddb5
Removed PACS Config testers
luis-camero Mar 29, 2023
3f88d69
Fixed lint errors in clearpath_config
luis-camero Mar 16, 2023
3012a17
Fixed lint errors in mounts
luis-camero Mar 16, 2023
5c6aaa3
Moved ListConfig
luis-camero Mar 30, 2023
5422062
Updated remove function
luis-camero Mar 30, 2023
05ad4ec
Removed mount pseudo namespace
luis-camero Mar 30, 2023
75772fa
Small lint fixes in common
luis-camero Mar 30, 2023
1dda483
Added get and set methods for individual mounts
luis-camero Mar 30, 2023
fdd47da
Split up mounts
luis-camero Mar 30, 2023
21b9305
Added uid checks to ListConfig
luis-camero Apr 3, 2023
feb651e
Removed mounting link and model
luis-camero Apr 3, 2023
d04cab7
Removed mounting link from fath and flir moutns
luis-camero Apr 3, 2023
d6d69ef
Added OrderedListConfig
luis-camero Apr 3, 2023
830b7e9
Added name from id to BaseMount
luis-camero Apr 3, 2023
fd346fe
Removed name as a default parameter
luis-camero Apr 3, 2023
9098936
Removed PACS from platform
luis-camero Apr 3, 2023
7e07db6
Moved ListConfig and all PACS from the Platform base
luis-camero Apr 3, 2023
580e2f1
Added mounts as individual ordered lists
luis-camero Apr 3, 2023
d965a62
Updated sample to new mount iterables
luis-camero Apr 4, 2023
6c0428b
Clear OrderedConfigList if empty list is set
luis-camero Apr 4, 2023
e8224e8
BaseMount no longer requires a name, default to index
luis-camero Apr 4, 2023
d11336d
Removed 'pacs_' prefix from brackets and risers
luis-camero Apr 4, 2023
dd1141a
Completely disabled all PACS testing
luis-camero Apr 4, 2023
bd9f6ef
Removed name as required argument
luis-camero Apr 4, 2023
016d294
Upgraded parser to match new mounts
luis-camero Apr 4, 2023
03594b9
Fixed key error print statement
luis-camero Apr 4, 2023
1f3f85f
Removed and
luis-camero Apr 4, 2023
729ea1f
Updated Husky sampl
luis-camero Apr 4, 2023
a2e128f
Added __init__ to mounts
luis-camero Apr 4, 2023
7f8cf03
Added BaseDecoration; by default disabled
luis-camero Apr 4, 2023
b3c07c4
Fixed top plate in parser
luis-camero Apr 4, 2023
ec952d2
Set decorations to enabled if not specified but exist
luis-camero Apr 4, 2023
a42ed01
Added method to retrieve all mounts
luis-camero Apr 4, 2023
d3bb6bc
Added Decoration.NEW class
luis-camero Apr 4, 2023
31a75d7
Added method to retrieve all decorations
luis-camero Apr 4, 2023
de1600e
Added get_enabled
luis-camero Apr 4, 2023
f297ffc
Updated A200 sample
luis-camero Apr 4, 2023
2fdc66b
Removed height from Husky sample
luis-camero Apr 5, 2023
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
Prev Previous commit
Next Next commit
Updated remove function
luis-camero committed Mar 30, 2023

Unverified

No user is associated with the committer email.
commit 5422062f402749574a567d241bc7a73f0045f108
165 changes: 12 additions & 153 deletions clearpath_config/platform/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from clearpath_config.common import Platform
from clearpath_config.common import ListConfig, Platform
from clearpath_config.platform.decorations import Decorations
from clearpath_config.platform.pacs import PACS
from copy import deepcopy
from typing import Callable, Generic, List, TypeVar

# Generic Type
T = TypeVar("T")
U = TypeVar("U")
from typing import List


# Unique Identifier: Name
@@ -24,110 +19,6 @@ def uid_level_row(T) -> tuple:
return (T.get_level(), T.get_row())


# ListConfigs
# - holds a list of an object type
# - generic class
class ListConfig(Generic[T, U]):

def __init__(self, uid: Callable) -> None:
self.__list: List[T] = []
self.__uid: Callable = uid

def find(
self,
_obj: T | U,
) -> int:
# Object: T: Template
if isinstance(_obj, self.__orig_class__.__args__[0]):
uid = self.__uid(_obj)
# Object: U: Unique ID
elif isinstance(_obj, self.__orig_class__.__args__[1]):
uid = _obj
# Error
else:
raise AssertionError(
"Object must be of type %s or %s" % (
self.__orig_class__.__args__[0].__name__,
self.__orig_class__.__args__[1].__name__
)
)
for idx, obj in enumerate(self.__list):
if self.__uid(obj) == uid:
return idx
return None

def add(
self,
obj: T,
) -> None:
assert isinstance(obj, self.__orig_class__.__args__[0]), (
"Object must be of type %s" % T
)
assert self.find(obj) is None, (
"Object with uid %s is not unique." % (
self.__uid(obj)
)
)
self.__list.append(obj)

def replace(
self,
obj: T,
) -> None:
assert isinstance(obj, self.__orig_class__.__args__[0]), (
"Object must be of type %s" % T
)
assert self.find(obj) is not None, (
"Object with uid %s cannot be replaced. Does not exist." % (
self.__uid(obj)
)
)
self.__list[self.find(obj)] = obj

def remove(
self,
_obj: T,
) -> None:
for obj in self.__list:
if self.__uid(obj) == self.__uid(_obj):
self.__list.remove(obj)
return

def get(
self,
_obj: T | U,
) -> T:
idx = self.find(_obj)
return None if idx is None else self.__list[idx]

def get_all(self) -> List[T]:
return self.__list

def set(
self,
obj: T
) -> None:
if self.find(obj) is None:
self.add(obj)
else:
self.replace(obj)

def set_all(
self,
_list: List[T],
) -> None:
# Copy and Clear
tmp_list = deepcopy(self.__list)
self.__list.clear()
# Add One-by-One
try:
for obj in _list:
self.add(obj)
# Restore Save if Failure
except AssertionError:
self.__list = tmp_list


# Base Decorations Config
# - holds the model name for that config
# - to be used by all other configurations.
@@ -179,15 +70,9 @@ def add_bumper(
# Bumper: Remove
def remove_bumper(
self,
# By Object
bumper: Decorations.Bumper = None,
# By Name
name: str = None,
# By Object or Name
bumper: Decorations.Bumper | str,
) -> None:
assert bumper or name, "Bumper object or name must be passed"
# Create Object
if name and not bumper:
bumper = Decorations.Bumper(name)
self.__bumpers.remove(bumper)

# Bumper: Get
@@ -239,14 +124,9 @@ def add_top_plate(
# Top Plate: Remove
def remove_top_plate(
self,
# By Object
top_plate: Decorations.TopPlate = None,
# By Name
name: str = None
# By Object or Name
top_plate: Decorations.TopPlate | str,
) -> None:
assert top_plate or name, "Top plate object or name must be passed."
if name and not top_plate:
top_plate = Decorations.TopPlate(name=name)
self.__top_plates.remove(top_plate)

# Top Plate: Get
@@ -296,14 +176,9 @@ def add_full_riser(
# Full Risers: Remove
def remove_full_riser(
self,
# By Object
full_riser: PACS.FullRiser = None,
# By Level
level: int = None
# By Object or Level
full_riser: PACS.FullRiser | int,
) -> None:
assert full_riser or level, "Full riser object or level must be passed"
if level and not full_riser:
full_riser = PACS.FullRiser(level=level)
self.__full_risers.remove(full_riser)

# Full Riser: Get
@@ -357,20 +232,9 @@ def add_row_riser(
# Row Risers: Remove
def remove_row_riser(
self,
# By Object
row_riser: PACS.RowRiser = None,
# By Level and Row
level: int = None,
row: int = None,
# By Object or (Level, Row)
row_riser: PACS.RowRiser | tuple[int],
) -> None:
assert row_riser or (level and row), (
"Row riser object or level and row must be passed."
)
if (level and row) and not row_riser:
row_riser = PACS.RowRiser(
level=level,
row=row,
)
self.__row_risers.remove(row_riser)

# Row Riser: Get
@@ -429,14 +293,9 @@ def add_bracket(
# Brackets: Remove
def remove_bracket(
self,
# By Object
bracket: PACS.Bracket = None,
# By Parameters
name: str = None
# By Object or Name
bracket: PACS.Bracket | str,
) -> None:
assert bracket or name, "Bracket object or name must be passed"
if name and not bracket:
bracket = PACS.Bracket(name=name)
self.__brackets.remove(bracket)

# Bracket: Get