Skip to content

Commit 0da6a6c

Browse files
Pre-commit
1 parent 382bb3d commit 0da6a6c

File tree

14 files changed

+97
-54
lines changed

14 files changed

+97
-54
lines changed

.pre-commit-config.yaml

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,61 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
13
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.5.0
46
hooks:
5-
- id: check-yaml
6-
- id: end-of-file-fixer
7-
- id: trailing-whitespace
8-
- id: debug-statements
9-
- repo: https://github.com/psf/black
10-
rev: 22.3.0
7+
- id: check-symlinks
8+
- id: destroyed-symlinks
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-yaml
12+
- id: check-toml
13+
- id: check-ast
14+
- id: check-added-large-files
15+
- id: check-merge-conflict
16+
- id: check-executables-have-shebangs
17+
- id: check-shebang-scripts-are-executable
18+
- id: detect-private-key
19+
- id: debug-statements
20+
# - repo: https://github.com/codespell-project/codespell
21+
# rev: v2.2.6
22+
# exclude: ^(src/common)|(src/emucore)|(src/environment)|(src/games)
23+
# hooks:
24+
# - id: codespell
25+
# args:
26+
# - --ignore-words-list=
27+
- repo: https://github.com/PyCQA/flake8
28+
rev: 7.0.0
1129
hooks:
12-
- id: black
30+
- id: flake8
31+
args:
32+
# - '--per-file-ignores='
33+
- --ignore=E203,W503,E741
34+
- --max-complexity=30
35+
- --max-line-length=456
36+
- --show-source
37+
- --statistics
38+
- repo: https://github.com/asottile/pyupgrade
39+
rev: v3.15.0
40+
hooks:
41+
- id: pyupgrade
42+
args: ["--py38-plus"]
43+
- repo: https://github.com/PyCQA/isort
44+
rev: 5.13.2
45+
hooks:
46+
- id: isort
47+
args: ["--profile", "black"]
48+
- repo: https://github.com/python/black
49+
rev: 23.12.1
50+
hooks:
51+
- id: black
52+
# - repo: https://github.com/pycqa/pydocstyle
53+
# rev: 6.3.0
54+
# hooks:
55+
# - id: pydocstyle
56+
## exclude: ^
57+
# args:
58+
# - --source
59+
# - --explain
60+
# - --convention=google
61+
# additional_dependencies: ["tomli"]

examples/python-interface/python_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# ALE provided in examples/sharedLibraryInterfaceExample.cpp
77
import sys
88
from random import randrange
9-
from ale_py import ALEInterface, SDL_SUPPORT
9+
10+
from ale_py import SDL_SUPPORT, ALEInterface
1011

1112
if len(sys.argv) < 2:
1213
print(f"Usage: {sys.argv[0]} rom_file")

examples/python-interface/python_example_with_modes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# ALE provided in doc/examples/sharedLibraryInterfaceWithModesExample.cpp
77
import sys
88
from random import randrange
9-
from ale_py import ALEInterface, SDL_SUPPORT
9+
10+
from ale_py import SDL_SUPPORT, ALEInterface
1011

1112
if len(sys.argv) < 2:
1213
print(f"Usage: {sys.argv[0]} rom_file")
@@ -40,7 +41,6 @@
4041
# Play one episode in each mode and in each difficulty
4142
for mode in avail_modes:
4243
for diff in avail_diff:
43-
4444
ale.setDifficulty(diff)
4545
ale.setMode(mode)
4646
ale.reset_game()

examples/python-rom-package/roms/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import sys
21
import pathlib
2+
import sys
33

44
if sys.version_info >= (3, 9):
55
import importlib.resources as resources

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def parse_version(version_file):
123123
semver_regex = r"(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"
124124
semver_prog = re.compile(semver_regex)
125125

126-
with open(version_file, "r") as fp:
126+
with open(version_file) as fp:
127127
version = fp.read().strip()
128128
assert semver_prog.match(version) is not None
129129

src/python/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@
4545
__version__ = "unknown"
4646

4747
# Import native shared library
48-
from ale_py._ale_py import SDL_SUPPORT, Action, ALEInterface, ALEState, LoggerMode
48+
from ale_py._ale_py import ( # noqa: E402
49+
SDL_SUPPORT,
50+
Action,
51+
ALEInterface,
52+
ALEState,
53+
LoggerMode,
54+
)
4955

5056
__all__ = ["Action", "ALEInterface", "ALEState", "LoggerMode", "SDL_SUPPORT"]
5157

5258

5359
try:
54-
import gymnasium
55-
5660
from ale_py.env import AtariEnv, AtariEnvStepMetadata
5761

5862
__all__ += ["AtariEnv", "AtariEnvStepMetadata"]

src/python/env.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4-
from typing import Any, Literal, Optional, Union
4+
from typing import Any, Literal
55

66
import ale_py
77
import gymnasium
@@ -35,14 +35,14 @@ class AtariEnv(gymnasium.Env, utils.EzPickle):
3535
def __init__(
3636
self,
3737
game: str,
38-
mode: Optional[int] = None,
39-
difficulty: Optional[int] = None,
38+
mode: int | None = None,
39+
difficulty: int | None = None,
4040
obs_type: Literal["rgb", "grayscale", "ram"] = "rgb",
41-
frameskip: Union[tuple[int, int], int] = 4,
41+
frameskip: tuple[int, int] | int = 4,
4242
repeat_action_probability: float = 0.25,
4343
full_action_space: bool = False,
44-
max_num_frames_per_episode: Optional[int] = None,
45-
render_mode: Optional[Literal["human", "rgb_array"]] = None,
44+
max_num_frames_per_episode: int | None = None,
45+
render_mode: Literal["human", "rgb_array"] | None = None,
4646
):
4747
"""
4848
Initialize the ALE for Gymnasium.
@@ -96,11 +96,11 @@ def __init__(
9696
)
9797
elif isinstance(frameskip, tuple) and frameskip[0] > frameskip[1]:
9898
raise error.Error(
99-
f"Invalid stochastic frameskip, lower bound is greater than upper bound."
99+
"Invalid stochastic frameskip, lower bound is greater than upper bound."
100100
)
101101
elif isinstance(frameskip, tuple) and frameskip[0] <= 0:
102102
raise error.Error(
103-
f"Invalid stochastic frameskip lower bound is greater than upper bound."
103+
"Invalid stochastic frameskip lower bound is greater than upper bound."
104104
)
105105

106106
if render_mode is not None and render_mode not in {"rgb_array", "human"}:
@@ -176,7 +176,7 @@ def __init__(
176176
else:
177177
raise error.Error(f"Unrecognized observation type: {self._obs_type}")
178178

179-
def seed_game(self, seed: Optional[int] = None) -> tuple[int, int]:
179+
def seed_game(self, seed: int | None = None) -> tuple[int, int]:
180180
"""Seeds the internal and ALE RNG."""
181181
ss = np.random.SeedSequence(seed)
182182
np_seed, ale_seed = ss.generate_state(n_words=2)
@@ -196,8 +196,8 @@ def load_game(self) -> None:
196196
def reset( # pyright: ignore[reportIncompatibleMethodOverride]
197197
self,
198198
*,
199-
seed: Optional[int] = None,
200-
options: Optional[dict[str, Any]] = None,
199+
seed: int | None = None,
200+
options: dict[str, Any] | None = None,
201201
) -> tuple[np.ndarray, AtariEnvStepMetadata]:
202202
"""Resets environment and returns initial observation."""
203203
super().reset(seed=seed, options=options)
@@ -253,7 +253,7 @@ def step( # pyright: ignore[reportIncompatibleMethodOverride]
253253

254254
return self._get_obs(), reward, is_terminal, is_truncated, self._get_info()
255255

256-
def render(self) -> Optional[np.ndarray]:
256+
def render(self) -> np.ndarray | None:
257257
"""
258258
Render is not supported by ALE. We use a paradigm similar to
259259
Gym3 which allows you to specify `render_mode` during construction.

src/python/registration.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
from __future__ import annotations
22

33
from collections import defaultdict
4-
from typing import Any, Callable, Mapping, NamedTuple, Sequence, Text, Union
4+
from typing import Any, Callable, Mapping, NamedTuple, Sequence
55

66
import ale_py.roms as roms
7-
from ale_py.roms import utils as rom_utils
8-
97
import gymnasium
8+
from ale_py.roms import utils as rom_utils
109

1110

1211
class EnvFlavour(NamedTuple):
1312
suffix: str
14-
kwargs: Union[Mapping[Text, Any], Callable[[str], Mapping[Text, Any]]]
13+
kwargs: Mapping[str, Any] | Callable[[str], Mapping[str, Any]]
1514

1615

1716
class EnvConfig(NamedTuple):
1817
version: str
19-
kwargs: Mapping[Text, Any]
18+
kwargs: Mapping[str, Any]
2019
flavours: Sequence[EnvFlavour]
2120

2221

src/python/roms/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __dir__() -> List[str]:
9797
md5s = resources.files(__name__).joinpath("md5.txt")
9898
if not md5s.exists():
9999
raise FileNotFoundError(
100-
f"ROM md5 resource couldn't be found. "
100+
"ROM md5 resource couldn't be found. "
101101
"Are you running from a development environment? "
102102
)
103103
with md5s.open() as fp:

tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
import pytest
34

45

@@ -13,6 +14,3 @@ def __getitem__(self, file_name):
1314
@pytest.fixture(scope="module")
1415
def resources():
1516
return Resources(os.path.abspath(os.path.dirname(__file__)))
16-
17-
18-
from fixtures import *

0 commit comments

Comments
 (0)