From 31eb278dd6b2db067e5305a1ccd3a768523ea791 Mon Sep 17 00:00:00 2001 From: "Jonathan B. Coe" Date: Thu, 1 Jan 2026 20:48:56 +0000 Subject: [PATCH] Use ruff rather than black and isort for linting --- .github/workflows/lint_python.yml | 1 - .pre-commit-config.yaml | 6 +----- nle/dataset/__init__.py | 4 ++-- nle/env/__init__.py | 2 +- nle/nethack/__init__.py | 14 +++++++------- nle/scripts/collect_env.py | 5 +---- nle/tests/test_dataset.py | 23 +++++++++++++---------- nle/tests/test_db.py | 3 +-- nle/tests/test_nethack.py | 3 +-- nle/tests/test_populate_db.py | 6 ++++-- pyproject.toml | 21 +-------------------- uv.lock | 12 ------------ 12 files changed, 32 insertions(+), 68 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 3d6787107..7e6eb4d8f 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -20,4 +20,3 @@ jobs: - run: uv sync - run: uv run ruff format --check --diff . - run: uv run ruff check - - run: uv run isort -c --diff nle/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b4013392..396370d0a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,7 @@ repos: - hooks: - id: ruff + args: [--fix] - id: ruff-format repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.4.3 @@ -17,8 +18,3 @@ repos: language: system name: clang-format repo: local - - hooks: - - id: isort - name: isort (python) - repo: https://github.com/pycqa/isort - rev: 5.13.2 diff --git a/nle/dataset/__init__.py b/nle/dataset/__init__.py index ab78874fe..d9968b55f 100644 --- a/nle/dataset/__init__.py +++ b/nle/dataset/__init__.py @@ -1,4 +1,4 @@ -from nle._pyconverter import Converter import nle.dataset.db -from nle.dataset.populate_db import add_altorg_directory, add_nledata_directory +from nle._pyconverter import Converter from nle.dataset.dataset import TtyrecDataset +from nle.dataset.populate_db import add_altorg_directory, add_nledata_directory diff --git a/nle/env/__init__.py b/nle/env/__init__.py index 03fa147a7..51031925b 100644 --- a/nle/env/__init__.py +++ b/nle/env/__init__.py @@ -2,7 +2,7 @@ import gymnasium as gym from gymnasium.envs import registration -from nle.env.base import NLE, DUNGEON_SHAPE +from nle.env.base import DUNGEON_SHAPE, NLE _version = "v0" diff --git a/nle/nethack/__init__.py b/nle/nethack/__init__.py index 6623e27b7..8b9afa8ae 100644 --- a/nle/nethack/__init__.py +++ b/nle/nethack/__init__.py @@ -1,16 +1,16 @@ # Copyright (c) Facebook, Inc. and its affiliates. -from nle.nethack.actions import * # noqa: F403 from nle._pynethack.nethack import * # noqa: F403 +from nle.nethack.actions import * # noqa: F403 from nle.nethack.nethack import ( - Nethack, - NETHACKOPTIONS, - DUNGEON_SHAPE, BLSTATS_SHAPE, - MESSAGE_SHAPE, - INV_SIZE, - PROGRAM_STATE_SHAPE, + DUNGEON_SHAPE, INTERNAL_SHAPE, + INV_SIZE, + MESSAGE_SHAPE, + NETHACKOPTIONS, OBSERVATION_DESC, + PROGRAM_STATE_SHAPE, TTYREC_VERSION, + Nethack, tty_render, ) diff --git a/nle/scripts/collect_env.py b/nle/scripts/collect_env.py index 4c6c3bccd..195047229 100644 --- a/nle/scripts/collect_env.py +++ b/nle/scripts/collect_env.py @@ -6,10 +6,7 @@ # Original version from: # https://github.com/pytorch/pytorch/blob/fa5bc9fa/torch/utils/collect_env.py -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import absolute_import, division, print_function, unicode_literals import locale import os diff --git a/nle/tests/test_dataset.py b/nle/tests/test_dataset.py index fbd183458..82f85cd40 100644 --- a/nle/tests/test_dataset.py +++ b/nle/tests/test_dataset.py @@ -4,16 +4,19 @@ import numpy as np import pytest -from test_converter import COLSROWS -from test_converter import FINALFRAME -from test_converter import FINALFRAMECOLORS -from test_converter import TIMESTAMPS -from test_converter import getfilename -from test_db import conn # noqa: F401 -from test_db import mockdata # noqa: F401 - -from nle.dataset import dataset -from nle.dataset import db +from test_converter import ( + COLSROWS, + FINALFRAME, + FINALFRAMECOLORS, + TIMESTAMPS, + getfilename, +) +from test_db import ( + conn, # noqa: F401 + mockdata, # noqa: F401 +) + +from nle.dataset import dataset, db class TestDataset: diff --git a/nle/tests/test_db.py b/nle/tests/test_db.py index 770cada33..3da9baa90 100644 --- a/nle/tests/test_db.py +++ b/nle/tests/test_db.py @@ -4,8 +4,7 @@ import test_converter import nle.env.tasks -from nle.dataset import db -from nle.dataset import populate_db +from nle.dataset import db, populate_db TTYRECS = [ ("aaa", test_converter.TTYREC_2020), diff --git a/nle/tests/test_nethack.py b/nle/tests/test_nethack.py index aa80b0618..0940ee6bd 100644 --- a/nle/tests/test_nethack.py +++ b/nle/tests/test_nethack.py @@ -7,8 +7,7 @@ import numpy as np import pytest -from nle import _pynethack -from nle import nethack +from nle import _pynethack, nethack # MORE + compass directions + long compass directions. ACTIONS = [ diff --git a/nle/tests/test_populate_db.py b/nle/tests/test_populate_db.py index 3ee5438fe..7d97aaadd 100644 --- a/nle/tests/test_populate_db.py +++ b/nle/tests/test_populate_db.py @@ -2,8 +2,10 @@ import pytest # NOQA: F401 from test_converter import getfilename -from test_db import conn # NOQA: F401 -from test_db import mockdata # NOQA: F401 +from test_db import ( + conn, # NOQA: F401 + mockdata, # NOQA: F401 +) from nle import nethack diff --git a/pyproject.toml b/pyproject.toml index 25b30538d..ab0b761b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,6 @@ dev = ["nle[dev]"] agent = ["torch>=1.3.1"] dev = [ "pre-commit>=2.0.1", - "isort>=5.13.2", "cmake_format>=0.6.10", "memory-profiler>=0.60.0", "pytest>=6.2.5", @@ -55,31 +54,13 @@ dev = [ ] all = ["nle[agent,dev]"] -[tool.black] -line-length = 88 -target-version = ['py38'] -include = '\.pyi?$' -exclude = ''' -/( - \.eggs - | \.git - | src - | win/rl/nethack_rl -)/ -''' - -[tool.isort] -force_single_line = true -profile = "black" -skip_glob = "**/__init__.py" - [tool.ruff] # See https://docs.astral.sh/ruff/rules/. extend-exclude = ["third_party"] exclude = ["win/rl/nle"] [tool.ruff.lint] ignore = ["B008", "B905", "C901", "E501", "E731"] -select = ["B", "B9", "C", "E", "F", "W", "R"] +select = ["B", "B9", "C", "E", "F", "I", "R", "W"] [tool.ruff.lint.flake8-comprehensions] allow-dict-calls-with-keyword-arguments = true [tool.ruff.lint.per-file-ignores] diff --git a/uv.lock b/uv.lock index 5fe140316..170285647 100644 --- a/uv.lock +++ b/uv.lock @@ -299,15 +299,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" }, ] -[[package]] -name = "isort" -version = "7.0.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/63/53/4f3c058e3bace40282876f9b553343376ee687f3c35a525dc79dbd450f88/isort-7.0.0.tar.gz", hash = "sha256:5513527951aadb3ac4292a41a16cbc50dd1642432f5e8c20057d414bdafb4187", size = 805049, upload-time = "2025-10-11T13:30:59.107Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/7f/ed/e3705d6d02b4f7aea715a353c8ce193efd0b5db13e204df895d38734c244/isort-7.0.0-py3-none-any.whl", hash = "sha256:1bcabac8bc3c36c7fb7b98a76c8abb18e0f841a3ba81decac7691008592499c1", size = 94672, upload-time = "2025-10-11T13:30:57.665Z" }, -] - [[package]] name = "jinja2" version = "3.1.6" @@ -467,7 +458,6 @@ agent = [ ] all = [ { name = "cmake-format" }, - { name = "isort" }, { name = "memory-profiler" }, { name = "pre-commit" }, { name = "pytest" }, @@ -481,7 +471,6 @@ all = [ ] dev = [ { name = "cmake-format" }, - { name = "isort" }, { name = "memory-profiler" }, { name = "pre-commit" }, { name = "pytest" }, @@ -502,7 +491,6 @@ dev = [ requires-dist = [ { name = "cmake-format", marker = "extra == 'dev'", specifier = ">=0.6.10" }, { name = "gymnasium", specifier = "==1.2.0" }, - { name = "isort", marker = "extra == 'dev'", specifier = ">=5.13.2" }, { name = "memory-profiler", marker = "extra == 'dev'", specifier = ">=0.60.0" }, { name = "nle", extras = ["agent", "dev"], marker = "extra == 'all'" }, { name = "numpy", specifier = ">=1.16" },