Skip to content

Commit

Permalink
pre-commit hooks and formatting codebase (ARISE-Initiative#273)
Browse files Browse the repository at this point in the history
* Add black and isort as pre-commit hooks

* Update contributing guidelines

* Remove pre-commit from deps and make it optional
  • Loading branch information
yukezhu authored Dec 27, 2021
1 parent bcee6ed commit 874ce96
Show file tree
Hide file tree
Showing 140 changed files with 3,293 additions and 2,971 deletions.
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 21.12b0 # Replace by any tag/version: https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ $ python -m pytest

Submission
----------
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)
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.

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)
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.
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.

Coding Conventions
------------------
We value readability and adhere to the following coding conventions:
In addition to the pre-commit hooks, we value readability and adhere to the following coding conventions:
- Indent using four spaces (soft tabs)
- 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`)
- Use the [Google Python Style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for the docstrings
Expand Down
66 changes: 30 additions & 36 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import os
import sys
sys.path.insert(0, os.path.abspath('.'))

sys.path.insert(0, os.path.abspath("."))

import sphinx_rtd_theme

import robosuite

# -- General configuration ------------------------------------------------
Expand All @@ -33,14 +35,14 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon',
'sphinx_rtd_theme',
'sphinx_markdown_tables',
'sphinx.ext.mathjax',
'sphinx.ext.githubpages',
'sphinx.ext.autodoc',
'recommonmark', # use Sphinx-1.4 or newer
'nbsphinx',
"sphinx.ext.napoleon",
"sphinx_rtd_theme",
"sphinx_markdown_tables",
"sphinx.ext.mathjax",
"sphinx.ext.githubpages",
"sphinx.ext.autodoc",
"recommonmark", # use Sphinx-1.4 or newer
"nbsphinx",
]


Expand All @@ -50,23 +52,23 @@


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# source_parsers = {
# '.md': CommonMarkParser,
# }

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

# The master toctree document.
master_doc = 'index'
master_doc = "index"

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

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

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

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

html_context = {
'css_files': [
'_static/css/theme.css',
'_static/pygments.css',
'_static/theme_overrides.css', # override wide tables in RTD theme
"css_files": [
"_static/css/theme.css",
"_static/pygments.css",
"_static/theme_overrides.css", # override wide tables in RTD theme
],
}

# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'robosuitedoc'
htmlhelp_basename = "robosuitedoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -134,15 +136,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -152,18 +151,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'robosuite.tex', u'robosuite Documentation', author, 'manual'),
(master_doc, "robosuite.tex", "robosuite Documentation", author, "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'robosuite', u'robosuite Documentation',
[author], 1)
]
man_pages = [(master_doc, "robosuite", "robosuite Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -172,7 +168,5 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'robosuite', u'robosuite Documentation',
author, 'robosuite', 'ARISE',
'Miscellaneous'),
]
(master_doc, "robosuite", "robosuite Documentation", author, "robosuite", "ARISE", "Miscellaneous"),
]
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.black]
line-length = 120
target-version = ["py36", "py37", "py38"]
extend-exclude = "robosuite/((models/assets)|(controllers/config))"

[tool.isort]
profile = "black"
line_length = 120
skip = ["__init__.py"]
filter_files = true
py_version = "all"
extend_skip = [
"robosuite/models/assets",
"robosuite/controllers/config",
]
10 changes: 5 additions & 5 deletions robosuite/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@


CONTROLLER_INFO = {
"JOINT_VELOCITY": "Joint Velocity",
"JOINT_TORQUE": "Joint Torque",
"JOINT_POSITION": "Joint Position",
"JOINT_VELOCITY": "Joint Velocity",
"JOINT_TORQUE": "Joint Torque",
"JOINT_POSITION": "Joint Position",
"OSC_POSITION": "Operational Space Control (Position Only)",
"OSC_POSE": "Operational Space Control (Position + Orientation)",
"IK_POSE": "Inverse Kinematics Control (Position + Orientation) (Note: must have PyBullet installed)",
"OSC_POSE": "Operational Space Control (Position + Orientation)",
"IK_POSE": "Inverse Kinematics Control (Position + Orientation) (Note: must have PyBullet installed)",
}

ALL_CONTROLLERS = CONTROLLER_INFO.keys()
24 changes: 14 additions & 10 deletions robosuite/controllers/base_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import abc
from collections.abc import Iterable
import numpy as np

import mujoco_py
import numpy as np

import robosuite.utils.macros as macros


Expand All @@ -25,11 +27,13 @@ class Controller(object, metaclass=abc.ABCMeta):
actuator_range (2-tuple of array of float): 2-Tuple (low, high) representing the robot joint actuator range
"""
def __init__(self,
sim,
eef_name,
joint_indexes,
actuator_range,

def __init__(
self,
sim,
eef_name,
joint_indexes,
actuator_range,
):

# Actuator range
Expand Down Expand Up @@ -135,7 +139,9 @@ def update(self, force=False):
self.sim.forward()

self.ee_pos = np.array(self.sim.data.site_xpos[self.sim.model.site_name2id(self.eef_name)])
self.ee_ori_mat = np.array(self.sim.data.site_xmat[self.sim.model.site_name2id(self.eef_name)].reshape([3, 3]))
self.ee_ori_mat = np.array(
self.sim.data.site_xmat[self.sim.model.site_name2id(self.eef_name)].reshape([3, 3])
)
self.ee_pos_vel = np.array(self.sim.data.site_xvelp[self.sim.model.site_name2id(self.eef_name)])
self.ee_ori_vel = np.array(self.sim.data.site_xvelr[self.sim.model.site_name2id(self.eef_name)])

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

mass_matrix = np.ndarray(shape=(len(self.sim.data.qvel) ** 2,), dtype=np.float64, order='C')
mass_matrix = np.ndarray(shape=(len(self.sim.data.qvel) ** 2,), dtype=np.float64, order="C")
mujoco_py.cymj._mj_fullM(self.sim.model, mass_matrix, self.sim.data.qM)
mass_matrix = np.reshape(mass_matrix, (len(self.sim.data.qvel), len(self.sim.data.qvel)))
self.mass_matrix = mass_matrix[self.qvel_index, :][:, self.qvel_index]
Expand Down Expand Up @@ -265,5 +271,3 @@ def name(self):
str: controller name
"""
raise NotImplementedError


Loading

0 comments on commit 874ce96

Please sign in to comment.