Skip to content

Commit 874ce96

Browse files
authored
pre-commit hooks and formatting codebase (ARISE-Initiative#273)
* Add black and isort as pre-commit hooks * Update contributing guidelines * Remove pre-commit from deps and make it optional
1 parent bcee6ed commit 874ce96

File tree

140 files changed

+3293
-2971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+3293
-2971
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 21.12b0 # Replace by any tag/version: https://github.com/psf/black/tags
4+
hooks:
5+
- id: black
6+
language_version: python3 # Should be a command that runs python3.6+
7+
- repo: https://github.com/pycqa/isort
8+
rev: 5.10.1
9+
hooks:
10+
- id: isort
11+
name: isort (python)

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ $ python -m pytest
2727

2828
Submission
2929
----------
30-
Please read the coding conventions below and make sure that your code is consistent with ours. When making a contribution, make a [pull request](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests)
30+
Please read the coding conventions below and make sure that your code is consistent with ours. We use the [black](https://github.com/psf/black) and [isort](https://github.com/pycqa/isort) as the [pre-commit](https://pre-commit.com/) hooks to format the source code before code review. To install these hooks, first `pip install pre-commit; pre-commit install` to set them up. Once set up, these hooks should be automatically triggered when committing new changes. If you want to manually check the format of the codes that have already been committed, please run `pre-commit run --all-files` in the project folder.
31+
32+
When making a contribution, make a [pull request](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests)
3133
to robosuite with an itemized list of what you have done. When you submit a pull request, it is immensely helpful to include example script(s) that showcase the proposed changes and highlight any new APIs.
3234
We always love to see more test coverage. When it is appropriate, add a new test to the [tests](https://github.com/ARISE-Initiative/robosuite/tree/master/tests) folder for checking the correctness of your code.
3335

3436
Coding Conventions
3537
------------------
36-
We value readability and adhere to the following coding conventions:
38+
In addition to the pre-commit hooks, we value readability and adhere to the following coding conventions:
3739
- Indent using four spaces (soft tabs)
3840
- Always put spaces after list items and method parameters (e.g., `[1, 2, 3]` rather than `[1,2,3]`), and around operators and hash arrows (e.g., `x += 1` rather than `x+=1`)
3941
- Use the [Google Python Style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for the docstrings

docs/conf.py

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import os
2020
import sys
21-
sys.path.insert(0, os.path.abspath('.'))
21+
22+
sys.path.insert(0, os.path.abspath("."))
2223

2324
import sphinx_rtd_theme
25+
2426
import robosuite
2527

2628
# -- General configuration ------------------------------------------------
@@ -33,14 +35,14 @@
3335
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3436
# ones.
3537
extensions = [
36-
'sphinx.ext.napoleon',
37-
'sphinx_rtd_theme',
38-
'sphinx_markdown_tables',
39-
'sphinx.ext.mathjax',
40-
'sphinx.ext.githubpages',
41-
'sphinx.ext.autodoc',
42-
'recommonmark', # use Sphinx-1.4 or newer
43-
'nbsphinx',
38+
"sphinx.ext.napoleon",
39+
"sphinx_rtd_theme",
40+
"sphinx_markdown_tables",
41+
"sphinx.ext.mathjax",
42+
"sphinx.ext.githubpages",
43+
"sphinx.ext.autodoc",
44+
"recommonmark", # use Sphinx-1.4 or newer
45+
"nbsphinx",
4446
]
4547

4648

@@ -50,23 +52,23 @@
5052

5153

5254
# Add any paths that contain templates here, relative to this directory.
53-
templates_path = ['_templates']
55+
templates_path = ["_templates"]
5456

5557
# source_parsers = {
5658
# '.md': CommonMarkParser,
5759
# }
5860

5961
# The suffix(es) of source filenames.
6062
# You can specify multiple suffix as a list of string:
61-
source_suffix = ['.rst', '.md', '.ipynb']
63+
source_suffix = [".rst", ".md", ".ipynb"]
6264

6365
# The master toctree document.
64-
master_doc = 'index'
66+
master_doc = "index"
6567

6668
# General information about the project.
67-
project = u'robosuite'
68-
copyright = u'Stanford University and The University of Texas at Austin 2021'
69-
author = u'Yuke Zhu, Josiah Wong, Ajay Mandlekar, Roberto Martín-Martín'
69+
project = "robosuite"
70+
copyright = "Stanford University and The University of Texas at Austin 2021"
71+
author = "Yuke Zhu, Josiah Wong, Ajay Mandlekar, Roberto Martín-Martín"
7072

7173
# The version info for the project you're documenting, acts as replacement for
7274
# |version| and |release|, also used in various other places throughout the
@@ -87,10 +89,10 @@
8789
# List of patterns, relative to source directory, that match files and
8890
# directories to ignore when looking for source files.
8991
# This patterns also effect to html_static_path and html_extra_path
90-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
92+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
9193

9294
# The name of the Pygments (syntax highlighting) style to use.
93-
pygments_style = 'sphinx'
95+
pygments_style = "sphinx"
9496

9597
# If true, `todo` and `todoList` produce output, else they produce nothing.
9698
todo_include_todos = False
@@ -101,7 +103,7 @@
101103
# The theme to use for HTML and HTML Help pages. See the documentation for
102104
# a list of builtin themes.
103105
#
104-
html_theme = 'sphinx_rtd_theme'
106+
html_theme = "sphinx_rtd_theme"
105107

106108
# Theme options are theme-specific and customize the look and feel of a theme
107109
# further. For a list of options available for each theme, see the
@@ -112,20 +114,20 @@
112114
# Add any paths that contain custom static files (such as style sheets) here,
113115
# relative to this directory. They are copied after the builtin static files,
114116
# so a file named "default.css" will overwrite the builtin "default.css".
115-
html_static_path = ['_static']
117+
html_static_path = ["_static"]
116118

117119
html_context = {
118-
'css_files': [
119-
'_static/css/theme.css',
120-
'_static/pygments.css',
121-
'_static/theme_overrides.css', # override wide tables in RTD theme
120+
"css_files": [
121+
"_static/css/theme.css",
122+
"_static/pygments.css",
123+
"_static/theme_overrides.css", # override wide tables in RTD theme
122124
],
123125
}
124126

125127
# -- Options for HTMLHelp output ------------------------------------------
126128

127129
# Output file base name for HTML help builder.
128-
htmlhelp_basename = 'robosuitedoc'
130+
htmlhelp_basename = "robosuitedoc"
129131

130132

131133
# -- Options for LaTeX output ---------------------------------------------
@@ -134,15 +136,12 @@
134136
# The paper size ('letterpaper' or 'a4paper').
135137
#
136138
# 'papersize': 'letterpaper',
137-
138139
# The font size ('10pt', '11pt' or '12pt').
139140
#
140141
# 'pointsize': '10pt',
141-
142142
# Additional stuff for the LaTeX preamble.
143143
#
144144
# 'preamble': '',
145-
146145
# Latex figure (float) alignment
147146
#
148147
# 'figure_align': 'htbp',
@@ -152,18 +151,15 @@
152151
# (source start file, target name, title,
153152
# author, documentclass [howto, manual, or own class]).
154153
latex_documents = [
155-
(master_doc, 'robosuite.tex', u'robosuite Documentation', author, 'manual'),
154+
(master_doc, "robosuite.tex", "robosuite Documentation", author, "manual"),
156155
]
157156

158157

159158
# -- Options for manual page output ---------------------------------------
160159

161160
# One entry per manual page. List of tuples
162161
# (source start file, name, description, authors, manual section).
163-
man_pages = [
164-
(master_doc, 'robosuite', u'robosuite Documentation',
165-
[author], 1)
166-
]
162+
man_pages = [(master_doc, "robosuite", "robosuite Documentation", [author], 1)]
167163

168164

169165
# -- Options for Texinfo output -------------------------------------------
@@ -172,7 +168,5 @@
172168
# (source start file, target name, title, author,
173169
# dir menu entry, description, category)
174170
texinfo_documents = [
175-
(master_doc, 'robosuite', u'robosuite Documentation',
176-
author, 'robosuite', 'ARISE',
177-
'Miscellaneous'),
178-
]
171+
(master_doc, "robosuite", "robosuite Documentation", author, "robosuite", "ARISE", "Miscellaneous"),
172+
]

pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[tool.black]
2+
line-length = 120
3+
target-version = ["py36", "py37", "py38"]
4+
extend-exclude = "robosuite/((models/assets)|(controllers/config))"
5+
6+
[tool.isort]
7+
profile = "black"
8+
line_length = 120
9+
skip = ["__init__.py"]
10+
filter_files = true
11+
py_version = "all"
12+
extend_skip = [
13+
"robosuite/models/assets",
14+
"robosuite/controllers/config",
15+
]

robosuite/controllers/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77

88
CONTROLLER_INFO = {
9-
"JOINT_VELOCITY": "Joint Velocity",
10-
"JOINT_TORQUE": "Joint Torque",
11-
"JOINT_POSITION": "Joint Position",
9+
"JOINT_VELOCITY": "Joint Velocity",
10+
"JOINT_TORQUE": "Joint Torque",
11+
"JOINT_POSITION": "Joint Position",
1212
"OSC_POSITION": "Operational Space Control (Position Only)",
13-
"OSC_POSE": "Operational Space Control (Position + Orientation)",
14-
"IK_POSE": "Inverse Kinematics Control (Position + Orientation) (Note: must have PyBullet installed)",
13+
"OSC_POSE": "Operational Space Control (Position + Orientation)",
14+
"IK_POSE": "Inverse Kinematics Control (Position + Orientation) (Note: must have PyBullet installed)",
1515
}
1616

1717
ALL_CONTROLLERS = CONTROLLER_INFO.keys()

robosuite/controllers/base_controller.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import abc
22
from collections.abc import Iterable
3-
import numpy as np
3+
44
import mujoco_py
5+
import numpy as np
6+
57
import robosuite.utils.macros as macros
68

79

@@ -25,11 +27,13 @@ class Controller(object, metaclass=abc.ABCMeta):
2527
2628
actuator_range (2-tuple of array of float): 2-Tuple (low, high) representing the robot joint actuator range
2729
"""
28-
def __init__(self,
29-
sim,
30-
eef_name,
31-
joint_indexes,
32-
actuator_range,
30+
31+
def __init__(
32+
self,
33+
sim,
34+
eef_name,
35+
joint_indexes,
36+
actuator_range,
3337
):
3438

3539
# Actuator range
@@ -135,7 +139,9 @@ def update(self, force=False):
135139
self.sim.forward()
136140

137141
self.ee_pos = np.array(self.sim.data.site_xpos[self.sim.model.site_name2id(self.eef_name)])
138-
self.ee_ori_mat = np.array(self.sim.data.site_xmat[self.sim.model.site_name2id(self.eef_name)].reshape([3, 3]))
142+
self.ee_ori_mat = np.array(
143+
self.sim.data.site_xmat[self.sim.model.site_name2id(self.eef_name)].reshape([3, 3])
144+
)
139145
self.ee_pos_vel = np.array(self.sim.data.site_xvelp[self.sim.model.site_name2id(self.eef_name)])
140146
self.ee_ori_vel = np.array(self.sim.data.site_xvelr[self.sim.model.site_name2id(self.eef_name)])
141147

@@ -146,7 +152,7 @@ def update(self, force=False):
146152
self.J_ori = np.array(self.sim.data.get_site_jacr(self.eef_name).reshape((3, -1))[:, self.qvel_index])
147153
self.J_full = np.array(np.vstack([self.J_pos, self.J_ori]))
148154

149-
mass_matrix = np.ndarray(shape=(len(self.sim.data.qvel) ** 2,), dtype=np.float64, order='C')
155+
mass_matrix = np.ndarray(shape=(len(self.sim.data.qvel) ** 2,), dtype=np.float64, order="C")
150156
mujoco_py.cymj._mj_fullM(self.sim.model, mass_matrix, self.sim.data.qM)
151157
mass_matrix = np.reshape(mass_matrix, (len(self.sim.data.qvel), len(self.sim.data.qvel)))
152158
self.mass_matrix = mass_matrix[self.qvel_index, :][:, self.qvel_index]
@@ -265,5 +271,3 @@ def name(self):
265271
str: controller name
266272
"""
267273
raise NotImplementedError
268-
269-

0 commit comments

Comments
 (0)