-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Pydantic for configuration management
- Loading branch information
Showing
10 changed files
with
453 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import sys | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
from colorama import Fore, Style | ||
from pydantic import BaseModel, ValidationError | ||
from pydantic_yaml import parse_yaml_file_as | ||
|
||
|
||
class Configuration(BaseModel): | ||
document_id: str | ||
version_id: str = "" | ||
workspace_id: str = "" | ||
draw_frames: bool = False | ||
draw_collisions: bool = False | ||
assembly_name: str = False | ||
use_fixed_links: bool = False | ||
configuration: str = "default" | ||
ignore_limits: bool = False | ||
|
||
# Dynamics | ||
joint_max_effort: float = 1.0 | ||
joint_max_velocity: float = 20.0 | ||
no_dynamics: bool = False | ||
|
||
# Ignore list | ||
ignore: list[str] = [] | ||
whitelist: list[str] | None = None | ||
|
||
# Color override | ||
color: list[float] | None = None | ||
|
||
# STL configuration | ||
simplify_stls: bool = False | ||
|
||
# Post-import commands to execute | ||
post_import_commands: list[str] = [] | ||
|
||
dynamics_override: dict[str, Any] = {} | ||
|
||
# Add collisions=true configuration on parts | ||
use_collisions_configurations: bool = True | ||
|
||
# ROS support | ||
package_name: str = "" | ||
add_dummy_base_link: bool = False | ||
robot_name: str = "onshape" | ||
|
||
additional_urdf_file: str = "" | ||
additional_xml: str = "" | ||
|
||
dynamics: dict[str, Any] = {} | ||
|
||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
singleton: "Configuration" = None | ||
|
||
@classmethod | ||
def from_file(cls, robot_directory: Path) -> "Configuration": | ||
try: | ||
cls.singleton = parse_yaml_file_as( | ||
Configuration, robot_directory / "config.yaml" | ||
) | ||
except ValidationError as ex: | ||
print(f"{Fore.RED}{ex}{Style.RESET_ALL}") | ||
sys.exit(1) | ||
return cls.singleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.