-
Notifications
You must be signed in to change notification settings - Fork 2
Stricter pyright Setup
#24
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,27 +6,33 @@ | |
| import numpy as np | ||
| import trimesh | ||
| from dm_control import mjcf | ||
| from dm_control.mjcf.element import _ElementImpl | ||
| from dm_control.mjcf.parser import from_file | ||
| from dm_control.mjcf.physics import Physics | ||
| from mujoco import mjx | ||
| from mujoco.mjx._src.device import device_put | ||
| from mujoco.mjx._src.io import make_data | ||
|
|
||
| from ambersim import ROOT | ||
| from ambersim.utils._internal_utils import _check_filepath | ||
| from ambersim.utils._internal_utils import check_filepath | ||
| from ambersim.utils.conversion_utils import save_model_xml | ||
|
|
||
|
|
||
| def _modify_robot_float_base(filepath: Union[str, Path]) -> mj.MjModel: | ||
| def _modify_robot_float_base(filepath: str) -> mj.MjModel: | ||
| """Modifies a robot to have a floating base if it doesn't already.""" | ||
| # loading current robot | ||
| assert str(filepath).split(".")[-1] == "xml" | ||
| robot = mjcf.from_file(filepath, model_dir="/".join(filepath.split("/")[:-1])) | ||
| robot = from_file(filepath, model_dir="/".join(filepath.split("/")[:-1])) | ||
|
Comment on lines
+21
to
+25
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example: I just copy/pasted this type hint from other function signatures, but |
||
|
|
||
| # only add free joint if the first body after worldbody has no freejoints | ||
| assert robot.worldbody is not None | ||
| assert robot.worldbody is not None # pyright typechecking | ||
| assert isinstance(robot.worldbody, _ElementImpl) # pyright typechecking | ||
| if len(robot.worldbody.body[0].joint) == 0: | ||
| robot.worldbody.body[0].add("freejoint", name="freejoint") | ||
| assert robot.worldbody.body[0].inertial is not None # checking for non-physical parsing errors | ||
|
|
||
| # extracts the mujoco model from the dm_mujoco Physics object | ||
| physics = mjcf.Physics.from_mjcf_model(robot) | ||
| physics = Physics.from_mjcf_model(robot) | ||
| assert physics is not None # pyright typechecking | ||
| model = physics.model.ptr | ||
| return model | ||
|
|
@@ -60,7 +66,7 @@ def load_mj_model_from_file( | |
| elif isinstance(solver, mj.mjtSolver): | ||
| assert solver in [mj.mjtSolver.mjSOL_CG] | ||
|
|
||
| filepath = _check_filepath(filepath) | ||
| filepath = check_filepath(filepath) | ||
|
|
||
| # loading the model and data. check whether freejoint is added forcibly | ||
| if force_float: | ||
|
|
@@ -69,7 +75,7 @@ def load_mj_model_from_file( | |
| output_name = "/".join(str(filepath).split("/")[:-1]) + "/_temp_xml_model.xml" | ||
| save_model_xml(filepath, output_name=output_name) | ||
| mj_model = _modify_robot_float_base(output_name) | ||
| Path.unlink(output_name) | ||
| Path(output_name).unlink() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example: this is actually just a straight up error that I resolve in a sibling branch, but I have no idea how it passed CI for so long. It actually occurs in a few other places, too. |
||
| else: | ||
| mj_model = _modify_robot_float_base(filepath) | ||
| else: | ||
|
|
@@ -88,8 +94,8 @@ def load_mj_model_from_file( | |
| def mj_to_mjx_model_and_data(mj_model: mj.MjModel) -> Tuple[mjx.Model, mjx.Data]: | ||
| """Converts a mujoco model to an mjx (model, data) pair.""" | ||
| try: | ||
| mjx_model = mjx.device_put(mj_model) | ||
| mjx_data = mjx.make_data(mjx_model) | ||
| mjx_model = device_put(mj_model) | ||
| mjx_data = make_data(mjx_model) | ||
| return mjx_model, mjx_data | ||
| except NotImplementedError as e: | ||
| extended_msg = """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "include": [ | ||
| "ambersim" | ||
| "ambersim", | ||
| ], | ||
| "reportMissingImports": false, | ||
| "reportMissingImports": true, | ||
| "reportMissingTypeStubs": false, | ||
| "reportGeneralTypeIssues": false, | ||
| "reportGeneralTypeIssues": true, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ | ||
|
|
||
| import ctypes | ||
| import os | ||
| from ctypes import POINTER, Structure, c_bool, c_char_p, c_double, c_int, c_uint, c_uint64, c_void_p | ||
|
|
||
| import numpy as np | ||
| import trimesh | ||
|
|
||
| _lib_files = ... | ||
|
|
||
| class CoACD_Mesh(ctypes.Structure): | ||
| _fields_ = ... | ||
|
|
||
| class CoACD_MeshArray(ctypes.Structure): | ||
| _fields_ = ... | ||
|
|
||
| class Mesh: | ||
| def __init__(self, vertices=..., indices=...) -> None: ... | ||
|
|
||
| def run_coacd( | ||
| mesh: Mesh, | ||
| threshold: float = ..., | ||
| max_convex_hull: int = ..., | ||
| preprocess_mode: str = ..., | ||
| preprocess_resolution: int = ..., | ||
| resolution: int = ..., | ||
| mcts_nodes: int = ..., | ||
| mcts_iterations: int = ..., | ||
| mcts_max_depth: int = ..., | ||
| pca: int = ..., | ||
| merge: bool = ..., | ||
| seed: int = ..., | ||
| ): # -> list[Unknown]: | ||
| ... | ||
|
|
||
| def set_log_level(level: str): # -> None: | ||
| ... | ||
|
|
||
| if __name__ == "__main__": | ||
| mesh = ... | ||
| mesh = ... | ||
| result = ... | ||
| mesh_parts = ... | ||
| scene = ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ | ||
|
|
||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ | ||
|
|
||
| import collections | ||
| import os | ||
|
|
||
| from absl import logging | ||
| from dm_control._render import constants | ||
|
|
||
| """OpenGL context management for rendering MuJoCo scenes. | ||
|
|
||
| By default, the `Renderer` class will try to load one of the following rendering | ||
| APIs, in descending order of priority: GLFW > EGL > OSMesa. | ||
|
|
||
| It is also possible to select a specific backend by setting the `MUJOCO_GL=` | ||
| environment variable to 'glfw', 'egl', or 'osmesa'. | ||
| """ | ||
| BACKEND = ... | ||
| _ALL_RENDERERS = ... | ||
| _NO_RENDERER = ... | ||
| if BACKEND is not None: | ||
| import_func = ... | ||
| Renderer = ... | ||
| else: ... | ||
| USING_GPU = ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ | ||
|
|
||
| import abc | ||
| import contextlib | ||
|
|
||
| """Base class for OpenGL context handlers. | ||
|
|
||
| `ContextBase` defines a common API that OpenGL rendering contexts should conform | ||
| to. In addition, it provides a `make_current` context manager that: | ||
|
|
||
| 1. Makes this OpenGL context current within the appropriate rendering thread. | ||
| 2. Yields an object exposing a `call` method that can be used to execute OpenGL | ||
| calls within the rendering thread. | ||
|
|
||
| See the docstring for `dm_control.utils.render_executor` for further details | ||
| regarding rendering threads. | ||
| """ | ||
| _CURRENT_CONTEXT_FOR_THREAD = ... | ||
| _CURRENT_THREAD_FOR_CONTEXT = ... | ||
|
|
||
| class ContextBase(metaclass=abc.ABCMeta): | ||
| """Base class for managing OpenGL contexts.""" | ||
|
|
||
| def __init__(self, max_width, max_height, render_executor_class=...) -> None: | ||
| """Initializes this context.""" | ||
| ... | ||
| def keep_alive(self, obj): # -> None: | ||
| ... | ||
| def dont_keep_alive(self, obj): # -> None: | ||
| ... | ||
| def increment_refcount(self): # -> None: | ||
| ... | ||
| def decrement_refcount(self): # -> None: | ||
| ... | ||
| @property | ||
| def terminated(self): # -> bool: | ||
| ... | ||
| @property | ||
| def thread(self): # -> Thread | None: | ||
| ... | ||
| def free(self): # -> None: | ||
| """Frees resources associated with this context if its refcount is zero.""" | ||
| ... | ||
| def __del__(self): # -> None: | ||
| ... | ||
| @contextlib.contextmanager | ||
| def make_current(self): # -> Generator[PassthroughRenderExecutor, Any, None]: | ||
| """Context manager that makes this Renderer's OpenGL context current. | ||
|
|
||
| Yields: | ||
| An object that exposes a `call` method that can be used to call a | ||
| function on the dedicated rendering thread. | ||
|
|
||
| Raises: | ||
| RuntimeError: If this context is already current on another thread. | ||
| """ | ||
| ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ | ||
|
|
||
| """String constants for the rendering module.""" | ||
| MUJOCO_GL = ... | ||
| PYOPENGL_PLATFORM = ... | ||
| OSMESA = ... | ||
| GLFW = ... | ||
| EGL = ... | ||
| NO_RENDERER = ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """ | ||
| This type stub file was generated by pyright. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from dm_control._render.executor.native_mutex.render_executor import NativeMutexOffloadingRenderExecutor | ||
| from dm_control._render.executor.render_executor import ( | ||
| BaseRenderExecutor, | ||
| OffloadingRenderExecutor, | ||
| PassthroughRenderExecutor, | ||
| ) | ||
|
|
||
| """RenderExecutor executes OpenGL rendering calls on an appropriate thread. | ||
|
|
||
| OpenGL calls must be made on the same thread as where an OpenGL context is | ||
| made current on. With GPU rendering, migrating OpenGL contexts between threads | ||
| can become expensive. We provide a thread-safe executor that maintains a | ||
| thread on which an OpenGL context can be kept permanently current, and any other | ||
| threads that wish to render with that context will have their rendering calls | ||
| offloaded to the dedicated thread. | ||
|
|
||
| For single-threaded applications, set the `DISABLE_RENDER_THREAD_OFFLOADING` | ||
| environment variable before launching the Python interpreter. This will | ||
| eliminate the overhead of unnecessary thread-switching. | ||
| """ | ||
| _OFFLOAD = ... | ||
| _EXECUTORS = ... | ||
| if _OFFLOAD: | ||
| RenderExecutor = ... | ||
| else: | ||
| RenderExecutor = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example:
pyrightcomplains about_check_filepathbecause the leading underscore implies it's a private function of the current file, but it's unused within the file. Further, I import this elsewhere, so it's clearly not private.