Skip to content

Commit

Permalink
Adds preview features for black formatter (#192)
Browse files Browse the repository at this point in the history
# Description

Adds `--preview` feature to the black formatter which also takes care of
the string representations in the code. This feature will become the
default setting in the next release of black
(psf/black#1802).

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
  • Loading branch information
Mayankm96 authored Oct 18, 2023
1 parent 36471c3 commit aa220db
Show file tree
Hide file tree
Showing 31 changed files with 103 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: 23.3.0
hooks:
- id: black
args: ["--line-length", "120"]
args: ["--line-length", "120", "--preview"]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
Expand Down
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@
"use_edit_page_button": True,
"show_toc_level": 2,
"use_sidenotes": True,
"announcement": "⚠️This is a pre-release version of Orbit. Please report any issues on <a href='https://github.com/NVIDIA-Omniverse/orbit/issues'>GitHub</a>.",
"announcement": (
"⚠️This is a pre-release version of Orbit. Please report any issues on <a"
" href='https://github.com/NVIDIA-Omniverse/orbit/issues'>GitHub</a>."
),
}

html_show_copyright = True
Expand Down
53 changes: 26 additions & 27 deletions source/extensions/omni.isaac.orbit/omni/isaac/orbit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ def __init__(self, launcher_args: argparse.Namespace | dict = None, **kwargs):
if not set(kwargs.keys()).isdisjoint(launcher_args.keys()):
overlapping_args = set(kwargs.keys()).intersection(launcher_args.keys())
raise ValueError(
f"Input `launcher_args` and `kwargs` both provided common attributes: {overlapping_args}. "
"Please ensure that each argument is supplied to only one of them, as the AppLauncher cannot "
"discern priority between them."
f"Input `launcher_args` and `kwargs` both provided common attributes: {overlapping_args}."
" Please ensure that each argument is supplied to only one of them, as the AppLauncher cannot"
" discern priority between them."
)
launcher_args.update(kwargs)

Expand Down Expand Up @@ -300,10 +300,10 @@ def add_app_launcher_args(parser: argparse.ArgumentParser) -> None:
config = vars(known)
if len(config) == 0:
print(
"[Warn][AppLauncher]: There are no arguments attached to the ArgumentParser object. "
"If you have your own arguments, please load your own arguments before calling the "
"`AppLauncher.add_app_launcher_args` method. This allows the method to check the validity "
"of the arguments and perform checks for argument names."
"[Warn][AppLauncher]: There are no arguments attached to the ArgumentParser object."
" If you have your own arguments, please load your own arguments before calling the"
" `AppLauncher.add_app_launcher_args` method. This allows the method to check the validity"
" of the arguments and perform checks for argument names."
)
else:
AppLauncher._check_argparser_config_params(config)
Expand Down Expand Up @@ -406,9 +406,9 @@ def _check_argparser_config_params(config: dict) -> None:
for key, value in config.items():
if key in applauncher_keys:
raise ValueError(
f"The passed ArgParser object already has the field '{key}'. This field will be added by "
"AppLauncher.add_app_launcher_args(), and should not be added directly. Please remove the "
"argument or rename it to a non-conflicting name."
f"The passed ArgParser object already has the field '{key}'. This field will be added by"
" `AppLauncher.add_app_launcher_args()`, and should not be added directly. Please remove the"
" argument or rename it to a non-conflicting name."
)
# check that type of the passed keys are valid
simulationapp_keys = set(AppLauncher._SIMULATIONAPP_CONFIG_TYPES.keys())
Expand All @@ -418,9 +418,9 @@ def _check_argparser_config_params(config: dict) -> None:
expected_types = AppLauncher._SIMULATIONAPP_CONFIG_TYPES[key]
if type(value) not in set(expected_types):
raise ValueError(
f"Invalid value type for the argument '{key}': {given_type}. Expected one of {expected_types}, "
f"if intended to be ingested by the SimulationApp object. Please change the type if this "
"intended for the SimulationApp or change the name of the argument to avoid name conflicts."
f"Invalid value type for the argument '{key}': {given_type}. Expected one of {expected_types},"
" if intended to be ingested by the SimulationApp object. Please change the type if this"
" intended for the SimulationApp or change the name of the argument to avoid name conflicts."
)
# Print out values which will be used
print(f"[INFO][AppLauncher]: The argument '{key}' will be used to configure the SimulationApp.")
Expand All @@ -441,22 +441,22 @@ def _config_resolution(self, launcher_args: dict):
# Value checking on LIVESTREAM
if livestream_env not in livestream_valid_vals:
raise ValueError(
f"Invalid value for environment variable `LIVESTREAM`: {livestream_env} . "
f"Expected: {livestream_valid_vals}."
f"Invalid value for environment variable `LIVESTREAM`: {livestream_env} ."
f" Expected: {livestream_valid_vals}."
)
# We allow livestream kwarg to supersede LIVESTREAM envvar
if livestream_arg >= 0:
if livestream_arg in livestream_valid_vals:
self._livestream = livestream_arg
# print info that we overrode the env-var
print(
f"[INFO][AppLauncher]: Input keyword argument `livestream={livestream_arg}` has overridden "
f"the environment variable `LIVESTREAM={livestream_env}`."
f"[INFO][AppLauncher]: Input keyword argument `livestream={livestream_arg}` has overridden"
f" the environment variable `LIVESTREAM={livestream_env}`."
)
else:
raise ValueError(
f"Invalid value for input keyword argument `livestream`: {livestream_arg} . "
f"Expected: {livestream_valid_vals}."
f"Invalid value for input keyword argument `livestream`: {livestream_arg} ."
f" Expected: {livestream_valid_vals}."
)
else:
self._livestream = livestream_env
Expand All @@ -472,8 +472,7 @@ def _config_resolution(self, launcher_args: dict):
# Value checking on HEADLESS
if headless_env not in headless_valid_vals:
raise ValueError(
f"Invalid value for environment variable `HEADLESS`: {headless_env} . "
f"Expected: {headless_valid_vals}."
f"Invalid value for environment variable `HEADLESS`: {headless_env} . Expected: {headless_valid_vals}."
)
# We allow headless kwarg to supersede HEADLESS envvar if headless_arg does not have the default value
# Note: Headless is always true when livestreaming
Expand All @@ -485,13 +484,13 @@ def _config_resolution(self, launcher_args: dict):
# inform who has toggled the headless flag
if self._livestream == livestream_arg:
print(
f"[INFO][AppLauncher]: Input keyword argument `livestream={self._livestream}` has implicitly "
f"overridden the environment variable `HEADLESS={headless_env}` to True."
f"[INFO][AppLauncher]: Input keyword argument `livestream={self._livestream}` has implicitly"
f" overridden the environment variable `HEADLESS={headless_env}` to True."
)
elif self._livestream == livestream_env:
print(
f"[INFO][AppLauncher]: Environment variable `LIVESTREAM={self._livestream}` has implicitly "
f"overridden the environment variable `HEADLESS={headless_env}` to True."
f"[INFO][AppLauncher]: Environment variable `LIVESTREAM={self._livestream}` has implicitly"
f" overridden the environment variable `HEADLESS={headless_env}` to True."
)
else:
# Headless needs to be a bool to be ingested by SimulationApp
Expand All @@ -515,8 +514,8 @@ def _config_resolution(self, launcher_args: dict):
self._ros = ros_arg
# print info that we overrode the env-var
print(
f"[INFO][AppLauncher]: Input keyword argument `ros={ros_arg}` has overridden "
f"the environment variable `ROS_ENABLED={ros_env}`."
f"[INFO][AppLauncher]: Input keyword argument `ros={ros_arg}` has overridden"
f" the environment variable `ROS_ENABLED={ros_env}`."
)
else:
raise ValueError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ def _process_actuators_cfg(self):
# check if any joints are found
if len(joint_names) == 0:
raise ValueError(
f"No joints found for actuator group: {actuator_name} with joint name expression: "
f"{actuator_cfg.joint_names_expr}."
f"No joints found for actuator group: {actuator_name} with joint name expression:"
f" {actuator_cfg.joint_names_expr}."
)
# for efficiency avoid indexing when over all indices
if len(joint_names) == self.num_joints:
Expand All @@ -524,8 +524,8 @@ def _process_actuators_cfg(self):
)
# log information on actuator groups
carb.log_info(
f"Actuator collection: {actuator_name} with model '{actuator_cfg.class_type.__name__}' and "
f"joint names: {joint_names} [{joint_ids}]."
f"Actuator collection: {actuator_name} with model '{actuator_cfg.class_type.__name__}' and"
f" joint names: {joint_names} [{joint_ids}]."
)
# store actuator group
self.actuators[actuator_name] = actuator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ def apply_physics_material(prim_path: str, material_path: str, weaker_than_desce
has_particle_system = prim.IsA(PhysxSchema.PhysxParticleSystem)
if not (has_collider or has_deformable_body or has_particle_system):
raise ValueError(
f"Cannot apply physics material on prim '{prim_path}'. It is neither a collider, nor a deformable body, nor a particle system."
f"Cannot apply physics material on prim '{prim_path}'. It is neither a collider,"
" nor a deformable body, nor a particle system."
)
# obtain material binding API
if prim.HasAPI(UsdShade.MaterialBindingAPI):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ def _prepare_observation_terms(self):
# Think: Check for cases when kwargs are set inside the function?
if len(args) > 2:
if set(args[2:]) != set(term_params):
msg = f"Observation term '{term_name}' expects parameters: {args[2:]}, but {term_params} provided."
msg = (
f"Observation term '{term_name}' expects parameters: {args[2:]}, but"
f" {term_params} provided."
)
raise ValueError(msg)
# add function to list
self._group_obs_term_names[group_name].append(term_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def __init__(self, cfg: actions_cfg.BinaryJointActionCfg, env: BaseEnv) -> None:
self._num_joints = len(self._joint_ids)
# log the resolved joint names for debugging
carb.log_info(
f"Resolved joint names for the action term {self.__class__.__name__}: {self._joint_names} [{self._joint_ids}]"
f"Resolved joint names for the action term {self.__class__.__name__}:"
f" {self._joint_names} [{self._joint_ids}]"
)

# create tensors for raw and processed actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def __init__(self, cfg: actions_cfg.JointActionCfg, env: BaseEnv) -> None:
self._num_joints = len(self._joint_ids)
# log the resolved joint names for debugging
carb.log_info(
f"Resolved joint names for the action term {self.__class__.__name__}: {self._joint_names} [{self._joint_ids}]"
f"Resolved joint names for the action term {self.__class__.__name__}:"
f" {self._joint_names} [{self._joint_ids}]"
)

# Avoid indexing across all joints for efficiency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def __init__(self, cfg: actions_cfg.NonHolonomicActionCfg, env: BaseEnv):
self._joint_names = [x_joint_name[0], y_joint_name[0], yaw_joint_name[0]]
# log info for debugging
carb.log_info(
f"Resolved joint names for the action term {self.__class__.__name__}: {self._joint_names} [{self._joint_ids}]"
f"Resolved joint names for the action term {self.__class__.__name__}:"
f" {self._joint_names} [{self._joint_ids}]"
)
carb.log_info(
f"Resolved body name for the action term {self.__class__.__name__}: {self._body_name} [{self._body_idx}]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(self, cfg: actions_cfg.DifferentialInverseKinematicsActionCfg, env:

# log info for debugging
carb.log_info(
f"Resolved joint names for the action term {self.__class__.__name__}: {self._joint_names} [{self._joint_ids}]"
f"Resolved joint names for the action term {self.__class__.__name__}:"
f" {self._joint_names} [{self._joint_ids}]"
)
carb.log_info(
f"Resolved body name for the action term {self.__class__.__name__}: {self._body_name} [{self._body_idx}]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def _prepare_terms(self):
# check valid type
if not isinstance(term_cfg, ActionTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type ActionTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type ActionTermCfg."
f" Received: '{type(term_cfg)}'."
)
# create the action term
term = term_cfg.class_type(term_cfg, self._env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def _prepare_terms(self):
# check if the term is a valid term config
if not isinstance(term_cfg, CurriculumTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type CurriculumTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type CurriculumTermCfg."
f" Received: '{type(term_cfg)}'."
)
# resolve common parameters
self._resolve_common_term_cfg(term_name, term_cfg, min_argc=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def _resolve_common_term_cfg(self, term_name: str, term_cfg: ManagerBaseTermCfg,
# check if the term is a valid term config
if not isinstance(term_cfg, ManagerBaseTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type ManagerBaseTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type ManagerBaseTermCfg."
f" Received: '{type(term_cfg)}'."
)
# iterate over all the entities and parse the joint and body names
for key, value in term_cfg.params.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def _prepare_terms(self):
# check if the term is a curriculum term
if not isinstance(group_cfg, ObservationGroupCfg):
raise TypeError(
f"Observation group '{group_name}' is not of type 'ObservationGroupCfg'. Received '{type(group_cfg)}'."
f"Observation group '{group_name}' is not of type 'ObservationGroupCfg'."
f" Received: '{type(group_cfg)}'."
)
# initialize list for the group settings
self._group_obs_term_names[group_name] = list()
Expand All @@ -194,7 +195,8 @@ def _prepare_terms(self):
continue
if not isinstance(term_cfg, ObservationTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type ObservationTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type ObservationTermCfg."
f" Received: '{type(term_cfg)}'."
)
# resolve common terms in the config
self._resolve_common_term_cfg(f"{group_name}/{term_name}", term_cfg, min_argc=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def randomize(self, mode: str, env_ids: Sequence[int] | None = None, dt: float |
if mode == "interval":
if dt is None:
raise ValueError(
f"Randomization mode '{mode}' requires the time step of the environment to be passed to the randomization manager."
f"Randomization mode '{mode}' requires the time step of the environment"
" to be passed to the randomization manager."
)
# extract time left for this term
time_left = self._interval_mode_time_left[index]
Expand Down Expand Up @@ -167,7 +168,8 @@ def _prepare_terms(self):
# check for valid config type
if not isinstance(term_cfg, RandomizationTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type RandomizationTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type RandomizationTermCfg."
f" Received: '{type(term_cfg)}'."
)
# resolve common parameters
self._resolve_common_term_cfg(term_name, term_cfg, min_argc=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ def _prepare_terms(self):
# check for valid config type
if not isinstance(term_cfg, RewardTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type RewardTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type RewardTermCfg."
f" Received: '{type(term_cfg)}'."
)
# check for valid weight type
if not isinstance(term_cfg.weight, (float, int)):
raise TypeError(
f"Weight for the term '{term_name}' is not of type float or int. Received '{type(term_cfg.weight)}'."
f"Weight for the term '{term_name}' is not of type float or int."
f" Received: '{type(term_cfg.weight)}'."
)
# resolve common parameters
self._resolve_common_term_cfg(term_name, term_cfg, min_argc=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def _prepare_terms(self):
# check for valid config type
if not isinstance(term_cfg, TerminationTermCfg):
raise TypeError(
f"Configuration for the term '{term_name}' is not of type TerminationTermCfg. Received '{type(term_cfg)}'."
f"Configuration for the term '{term_name}' is not of type TerminationTermCfg."
f" Received: '{type(term_cfg)}'."
)
# resolve common parameters
self._resolve_common_term_cfg(term_name, term_cfg, min_argc=1)
Expand Down
Loading

0 comments on commit aa220db

Please sign in to comment.