Skip to content

chore: update ruff target-version to py312#5681

Draft
pv-nvidia wants to merge 1 commit into
isaac-sim:developfrom
pv-nvidia:pv/ruff-target-py312
Draft

chore: update ruff target-version to py312#5681
pv-nvidia wants to merge 1 commit into
isaac-sim:developfrom
pv-nvidia:pv/ruff-target-py312

Conversation

@pv-nvidia
Copy link
Copy Markdown

The project requires python >= 3.12 but ruff was configured with target-version = "py310". This causes false positives (e.g. ExceptionGroup flagged as undefined) and prevents correct stdlib import sorting for modules like tomllib.

This PR updates target-version to "py312" and applies the resulting auto-fixes.

@github-actions github-actions Bot added isaac-mimic Related to Isaac Mimic team isaac-lab Related to Isaac Lab team infrastructure labels May 18, 2026
@pv-nvidia pv-nvidia marked this pull request as ready for review May 18, 2026 17:56
@pv-nvidia pv-nvidia marked this pull request as draft May 18, 2026 17:57
Copy link
Copy Markdown

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: ✅ Approve

This PR correctly aligns the ruff linter target-version with the project's requires-python = ">=3.12,<3.13" constraint. The change is well-motivated and the auto-fixes are appropriate.


Analysis

✅ Core Change - Correct

The target-version = "py312" update in pyproject.toml is the right fix. The previous py310 setting caused:

  • False positives for Python 3.11+ builtins (ExceptionGroup, tomllib)
  • Incorrect stdlib import ordering

✅ Import Reorderings - Valid

All import changes follow PEP 8/isort conventions with py312 stdlib awareness:

  • tomllib is now recognized as stdlib (moved before third-party imports)
  • distutils.util.strtobool reordering is valid (third-party via setuptools shim)

✅ Exception Change - Safe

# se3_haply.py line 347
-except asyncio.TimeoutError:
+except TimeoutError:

Since Python 3.11, asyncio.TimeoutError is an alias to the built-in TimeoutError. This change is correct and idiomatic for Python 3.12+.

✅ Pre-commit Fix (new in 8a9e499)

Added UP040 and UP047 to the ignore list:

"UP040",  # TypeAlias annotation → `type` keyword (PEP 695, migrate later)
"UP047",  # Generic function → type parameters (PEP 695, migrate later)

This properly defers the PEP 695 migration while unblocking the CI. The ignore comments indicate these are intentional deferrals, not permanent suppressions.

📝 Minor Note - Scope

The .gitignore addition (*.swp for vim swap files) is unrelated to the ruff configuration but is a reasonable quality-of-life improvement. Consider splitting this into a separate commit for cleaner git history.


LGTM - Ready to merge.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR corrects ruff's target-version from py310 to py312 to match the project's actual Python requirement, then applies the resulting auto-fixes (import reordering, asyncio.TimeoutErrorTimeoutError, blank-line cleanup, and .gitignore addition).

  • pyproject.toml: target-version = "py312" — the core fix; eliminates false positives like ExceptionGroup and correctly classifies stdlib modules such as tomllib.
  • se3_haply.py: asyncio.TimeoutError replaced with the builtin TimeoutError, which is correct for Python 3.12 where the asyncio alias is deprecated.
  • train.py / train_rl_games.py: ruff correctly reclassified from distutils.util import strtobool as a third-party import (since distutils was removed from stdlib in Python 3.12), but the import itself was not replaced — it will raise ModuleNotFoundError at runtime on a clean Python 3.12 environment without setuptools.

Confidence Score: 4/5

Safe to merge with a follow-up to replace the distutils.util.strtobool import in the two rl_games training scripts.

The core change — updating target-version — is correct and necessary. Most auto-fixes (import reordering, TimeoutError alias, blank-line cleanup) are clean. The only concern is that ruff's isort correctly moved from distutils.util import strtobool to the third-party section (because distutils is gone from Python 3.12 stdlib), but neither script replaced the import with a working alternative. On a plain Python 3.12 install without setuptools, both train.py and train_rl_games.py will crash immediately at import time.

scripts/reinforcement_learning/rl_games/train.py and scripts/reinforcement_learning/rl_games/train_rl_games.py — both still import distutils.util.strtobool which was removed from Python 3.12.

Important Files Changed

Filename Overview
pyproject.toml Updates ruff target-version from py310 to py312 to match the project's actual Python requirement; straightforward and correct.
scripts/reinforcement_learning/rl_games/train.py Ruff isort moved from distutils.util import strtobool to the third-party section, correctly reflecting that distutils is gone from Python 3.12 stdlib — but the import itself was not replaced and will fail at runtime on Python 3.12 without setuptools.
scripts/reinforcement_learning/rl_games/train_rl_games.py Same distutils import issue as train.py — ruff re-sorted it as third-party but the removed-in-3.12 import was not replaced.
source/isaaclab/isaaclab/devices/haply/se3_haply.py Changed asyncio.TimeoutErrorTimeoutError; correct for Python 3.12 where the asyncio alias is deprecated in favour of the builtin.
source/isaaclab/isaaclab/cli/commands/install.py Import order adjustment — tomllib now sorts before pathlib as both are stdlib; cosmetic isort fix only.
tools/wheel_builder/gen_pyproject.py Removed a spurious blank line between stdlib imports (sys and tomllib); cosmetic isort fix only.
.gitignore Adds *.swp (Vim swap files) to .gitignore; safe housekeeping change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ruff target-version py310 → py312] --> B{Import classification changes}
    B --> C[tomllib: third-party → stdlib\nCorrect: added in Python 3.11]
    B --> D[distutils: stdlib → third-party\nWarning: removed in Python 3.12]
    B --> E[asyncio.TimeoutError → TimeoutError\nCorrect: UP041 fix for Python 3.12]
    D --> F{setuptools installed?}
    F -->|Yes| G[Import succeeds at runtime\nbut fragile / not guaranteed]
    F -->|No| H[ModuleNotFoundError at startup\ntrain.py & train_rl_games.py]
Loading

Reviews (1): Last reviewed commit: "chore: update ruff target-version to py3..." | Re-trigger Greptile

from distutils.util import strtobool

import gymnasium as gym
from distutils.util import strtobool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 distutils removed in Python 3.12 — import will fail at runtime

distutils was entirely removed from the Python standard library in 3.12 (PEP 632). On a clean Python 3.12 environment without setuptools, this import raises ModuleNotFoundError at startup. Ruff correctly reclassified it as a third-party import (acknowledging it is no longer stdlib), but didn't remove the broken call. The same issue exists in train_rl_games.py line 31. The recommended fix is to inline a small replacement — e.g. bool(val.lower() in {"y", "yes", "t", "true", "on", "1"}) — or depend on a maintained PyPI alternative such as str2bool.

@pv-nvidia pv-nvidia force-pushed the pv/ruff-target-py312 branch 4 times, most recently from ba0c920 to 8a8ef77 Compare May 19, 2026 15:20
Copy link
Copy Markdown

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: ✅ Approve

This PR correctly aligns the ruff linter target-version with the project's requires-python = ">=3.12,<3.13" constraint.


Analysis

✅ Core Configuration Change

The target-version = "py312" update in pyproject.toml addresses:

  • False positives for Python 3.11+ builtins (ExceptionGroup, tomllib)
  • Incorrect stdlib import ordering for tomllib (now correctly treated as stdlib)

✅ PEP 695 Rules Suppressed

"UP040",  # TypeAlias annotation → `type` keyword (PEP 695, migrate later)
"UP047",  # Generic function → type parameters (PEP 695, migrate later)

Good decision to defer PEP 695 type syntax migration — this prevents a large refactor while enabling the py312 target.

✅ Auto-fix Changes

All changes are correct ruff auto-fixes:

  • Import reordering: tomllib moved before pathlib in several files (now recognized as stdlib)
  • distutils.util.strtobool replacement: Migrated to isaaclab.utils.string.strtobool utility function
  • Exception modernization: asyncio.TimeoutErrorTimeoutError in se3_haply.py (correct since Python 3.11)

✅ Changelog Skip File

Empty .skip file added to changelog.d/ — appropriate for internal tooling changes.


LGTM — Clean fix with proper PEP 695 deferrals. CI pre-commit check passes.


Update (1eb9cfd): Reviewed incremental changes. The strtobool function was properly added to isaaclab.utils.string module instead of using local helpers — this is a better approach as it centralizes the deprecated distutils.util.strtobool replacement in a reusable utility. Implementation is correct and follows the same semantics. No issues found.

@isaaclab-review-bot
Copy link
Copy Markdown

🔄 Incremental Review Update

New commit: 8a8ef778 (was ba0c920f)

Changes Since Last Review

The _strtobool() helper function was improved in both RL training scripts:

Before:

def _strtobool(val: str) -> bool:
    return val.lower() in ("y", "yes", "t", "true", "on", "1")

After:

def _strtobool(val: str) -> bool:
    """Convert a string representation of truth to True/False.

    Raises ValueError for unrecognised values.
    """
    v = val.lower()
    if v in ("y", "yes", "t", "true", "on", "1"):
        return True
    elif v in ("n", "no", "f", "false", "off", "0"):
        return False
    else:
        raise ValueError(f"invalid truth value {val!r}")

Assessment ✅

This is a good improvement — the new implementation:

  • Adds a proper docstring
  • Explicitly returns True/False instead of implicit bool conversion
  • Raises ValueError for invalid inputs (matching original distutils.util.strtobool behavior)
  • Prevents silent acceptance of typos like "tru" or "yse"

Verdict remains: ✅ Approve

The project requires Python >=3.12 but ruff was configured with
target-version = py310. This caused false positives for 3.11+ builtins
and prevented correct stdlib import sorting for tomllib.

PEP 695 rules (UP040, UP047) are suppressed for now to avoid a large
migration; tracked separately for incremental adoption.
@pv-nvidia pv-nvidia force-pushed the pv/ruff-target-py312 branch from 8a8ef77 to 1eb9cfd Compare May 19, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infrastructure isaac-lab Related to Isaac Lab team isaac-mimic Related to Isaac Mimic team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants