Skip to content
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

Add ruffaction and configuration #114

Merged
merged 11 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
steps:

- name: "🔀 Checkout repository"
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: '🐍 Initialize Python'
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand All @@ -37,10 +37,10 @@ jobs:
steps:

- name: "🔀 Checkout repository"
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: '🐍 Initialize Python'
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand All @@ -51,3 +51,16 @@ jobs:
uses: isort/isort-action@master
with:
configuration: --check --diff --color

ruff:

name: ruff
runs-on: ubuntu-latest

steps:

- name: "🔀 Checkout repository"
uses: actions/checkout@v4

- name: "📝 Ruff"
uses: chartboost/ruff-action@v1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ dmypy.json

# setuptools_scm dynamic version
src/jaxsim/_version.py

# ruff
.ruff_cache/
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ repos:
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
- id: ruff
3 changes: 0 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Configuration file for the Sphinx documentation builder.
import os
import pathlib
import sys

from pkg_resources import get_distribution
Expand All @@ -23,8 +22,6 @@ def _recursive_add_annotations_import():
if "READTHEDOCS" in os.environ:
_recursive_add_annotations_import()

import jaxsim

# -- Version information

sys.path.insert(0, os.path.abspath("."))
Expand Down
55 changes: 49 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"wheel",
"setuptools>=64",
"setuptools_scm[toml]>=8",
"wheel",
"setuptools>=64",
"setuptools_scm[toml]>=8",
]

[tool.setuptools_scm]
Expand All @@ -14,12 +14,55 @@ version_file = "src/jaxsim/_version.py"
line-length = 88

[tool.isort]
profile = "black"
multi_line_output = 3
profile = "black"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-rsxX -v --strict-markers"
minversion = "6.0"
preview = true
testpaths = [
"tests",
"tests",
]

target-version = "py311"

[tool.ruff]
exclude = [
".git",
".pytest_cache",
".ruff_cache",
".vscode",
".devcontainer",
"__pycache__",
]
preview = true

[tool.ruff.lint]
# https://docs.astral.sh/ruff/rules/
ignore = [
"B008", # Function call in default argument
"B024", # Abstract base class without abstract methods
"B904", # Raise without from inside exception
"B905", # Zip without explicit strict
"E402", # Module level import not at top of file
"E501", # Line too long
"E731", # Do not assign a `lambda` expression, use a `def`
"E741", # Ambiguous variable name
"F841", # Local variable is assigned to but never used
"I001", # Import block is unsorted or unformatted
]
select = [
"B",
"E",
"F",
"I",
"W",
"YTT",
]

[tool.ruff.lint.per-file-ignores]
# Ignore `E402` (import violations) in all `__init__.py` files
"**/{tests,docs,tools}/*" = ["E402"]
"**/{tests}/*" = ["B007"]
"__init__.py" = ["F401"]
4 changes: 2 additions & 2 deletions src/jaxsim/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def inertial_to_other_representation(
transform: jtp.Matrix,
is_force: bool = False,
) -> jtp.Array:
"""
r"""
Convert a 6D quantity from inertial-fixed to another representation.

Args:
Expand Down Expand Up @@ -155,7 +155,7 @@ def other_representation_to_inertial(
transform: jtp.Matrix,
is_force: bool = False,
) -> jtp.Array:
"""
r"""
Convert a 6D quantity from another representation to inertial-fixed.

Args:
Expand Down
8 changes: 4 additions & 4 deletions src/jaxsim/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ def base_velocity(self) -> jtp.Vector:

@jax.jit
def generalized_position(self) -> tuple[jtp.Matrix, jtp.Vector]:
"""
r"""
Get the generalized position
:math:`\mathbf{q} = ({}^W \mathbf{H}_B, \mathbf{s}) \in \text{SO}(3) \times \mathbb{R}^n`.
:math:`\\mathbf{q} = ({}^W \\mathbf{H}_B, \\mathbf{s}) \\in \text{SO}(3) \times \\mathbb{R}^n`.

Returns:
A tuple containing the base transform and the joint positions.
Expand All @@ -427,9 +427,9 @@ def generalized_position(self) -> tuple[jtp.Matrix, jtp.Vector]:

@jax.jit
def generalized_velocity(self) -> jtp.Vector:
"""
r"""
Get the generalized velocity
:math:`\boldsymbol{\nu} = (\boldsymbol{v}_{W,B};\, \boldsymbol{\omega}_{W,B};\, \mathbf{s}) \in \mathbb{R}^{6+n}`
:math:`\boldsymbol{\nu} = (\boldsymbol{v}_{W,B};\\, \boldsymbol{\\omega}_{W,B};\\, \\mathbf{s}) \\in \\mathbb{R}^{6+n}`

Returns:
The generalized velocity in the active representation.
Expand Down
4 changes: 2 additions & 2 deletions src/jaxsim/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def to_inertial(C_v̇_WB, W_H_C, C_v_WB, W_v_WC):
def free_floating_gravity_forces(
model: JaxSimModel, data: js.data.JaxSimModelData
) -> jtp.Vector:
"""
r"""
Compute the free-floating gravity forces :math:`g(\mathbf{q})` of the model.

Args:
Expand Down Expand Up @@ -987,7 +987,7 @@ def free_floating_bias_forces(
model: JaxSimModel, data: js.data.JaxSimModelData
) -> jtp.Vector:
"""
Compute the free-floating bias forces :math:`h(\mathbf{q}, \boldsymbol{\nu})`
Compute the free-floating bias forces :math:`h(\\mathbf{q}, \boldsymbol{\nu})`
of the model.

Args:
Expand Down
1 change: 0 additions & 1 deletion src/jaxsim/api/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jaxsim.typing as jtp
from jaxsim.integrators import Time
from jaxsim.math import Quaternion
from jaxsim.utils import Mutability

from .common import VelRepr
from .ode_data import ODEState
Expand Down
4 changes: 2 additions & 2 deletions src/jaxsim/integrators/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def integrate_rk_stage(
def post_process_state(
cls, x0: State, t0: Time, xf: NextState, dt: TimeStep
) -> NextState:
"""
r"""
Post-process the integrated state at :math:`t_f = t_0 + \Delta t`.

Args:
Expand Down Expand Up @@ -529,7 +529,7 @@ def butcher_tableau_supports_fsal(
# Return the index of the row of A providing the fsal derivative (that is the
# possibly intermediate kᵢ derivative).
# Note that if multiple rows match (it should not), we return the first match.
return True, int(jnp.where(rows_of_A_with_fsal == True)[0].tolist()[0])
return True, int(jnp.where(rows_of_A_with_fsal)[0].tolist()[0])


class ExplicitRungeKuttaSO3Mixin:
Expand Down
1 change: 0 additions & 1 deletion src/jaxsim/math/transform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import jax
import jax.numpy as jnp
import jaxlie

Expand Down
2 changes: 1 addition & 1 deletion src/jaxsim/mujoco/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def add_floating_joint(

if root.find(f".//joint[@name='{floating_joint_name}']") is not None:
msg = f"The URDF already has a floating joint '{floating_joint_name}'"
warnings.warn(msg)
warnings.warn(msg, stacklevel=2)
return ET.tostring(root, pretty_print=True).decode()

# Create the "world" link if it doesn't exist.
Expand Down
2 changes: 2 additions & 0 deletions src/jaxsim/mujoco/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import numpy.typing as npt
from scipy.spatial.transform import Rotation

import jaxsim.typing as jtp

HeightmapCallable = Callable[[jtp.FloatLike, jtp.FloatLike], jtp.FloatLike]


Expand Down
2 changes: 1 addition & 1 deletion src/jaxsim/parsers/kinematic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def reduce(self, considered_joints: List[str]) -> "KinematicGraph":

# Return early if there is no action to take
if len(joint_names_to_remove) == 0:
logging.info(f"The kinematic graph doesn't need to be reduced")
logging.info("The kinematic graph doesn't need to be reduced")
return copy.deepcopy(self)

# Check if all considered joints are part of the full kinematic graph
Expand Down
1 change: 0 additions & 1 deletion src/jaxsim/utils/jaxsim_dataclass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
import contextlib
import copy
import dataclasses
import functools
from collections.abc import Iterator
Expand Down
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pathlib

import jax
import jax.numpy as jnp
import pytest
import rod

Expand Down Expand Up @@ -176,14 +175,12 @@ def jaxsim_model_ergocub() -> js.model.JaxSimModel:
The JaxSim model of the ErgoCub robot.
"""

os_environ_original = os.environ.copy()

try:
os.environ["ROBOT_DESCRIPTION_COMMIT"] = "v0.7.1"

import robot_descriptions.ergocub_description
finally:
os.environ = os_environ_original
_ = os.environ.pop("ROBOT_DESCRIPTION_COMMIT", None)

model_urdf_path = pathlib.Path(
robot_descriptions.ergocub_description.URDF_PATH.replace(
Expand Down
1 change: 0 additions & 1 deletion tests/test_pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from contextlib import redirect_stdout

import jax
import jax.numpy as jnp
import rod.builder.primitives
import rod.urdf.exporter

Expand Down
Loading