Skip to content

Commit ed8407f

Browse files
committed
more code quality fixes
1 parent 39f677a commit ed8407f

20 files changed

+102
-107
lines changed

Makefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
.PHONY: quality style test unity-test
22

3-
check_dirs := tests godot_rl
4-
53
# Format source code automatically
64
style:
7-
black --line-length 120 --target-version py310 tests godot_rl
8-
isort -w 120 tests godot_rl
5+
black --line-length 120 --target-version py310 tests godot_rl examples
6+
isort -w 120 tests godot_rl examples
97
# Check that source code meets quality standards
108
quality:
11-
black --check --line-length 120 --target-version py310 tests godot_rl
12-
isort -w 120 --check-only tests godot_rl
13-
flake8 --max-line-length 120 tests godot_rl
9+
black --check --line-length 120 --target-version py310 tests godot_rl examples
10+
isort -w 120 --check-only tests godot_rl examples
11+
flake8 --max-line-length 120 tests godot_rl examples
1412

1513
# Run tests for the library
1614
test:

examples/clean_rl_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import pathlib
55
import random
66
import time
7-
from distutils.util import strtobool
87
from collections import deque
8+
from distutils.util import strtobool
9+
910
import numpy as np
1011
import torch
1112
import torch.nn as nn
1213
import torch.optim as optim
1314
from torch.distributions.normal import Normal
1415
from torch.utils.tensorboard import SummaryWriter
16+
1517
from godot_rl.wrappers.clean_rl_wrapper import CleanRLGodotEnv
1618

1719

examples/sample_factory_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
2-
from godot_rl.wrappers.sample_factory_wrapper import sample_factory_training, sample_factory_enjoy
2+
3+
from godot_rl.wrappers.sample_factory_wrapper import sample_factory_enjoy, sample_factory_training
34

45

56
def get_args():

examples/stable_baselines3_example.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import pathlib
44
from typing import Callable
55

6+
from stable_baselines3 import PPO
67
from stable_baselines3.common.callbacks import CheckpointCallback
8+
from stable_baselines3.common.vec_env.vec_monitor import VecMonitor
9+
710
from godot_rl.core.utils import can_import
8-
from godot_rl.wrappers.stable_baselines_wrapper import StableBaselinesGodotEnv
911
from godot_rl.wrappers.onnx.stable_baselines_export import export_ppo_model_as_onnx
10-
from stable_baselines3 import PPO
11-
from stable_baselines3.common.vec_env.vec_monitor import VecMonitor
12+
from godot_rl.wrappers.stable_baselines_wrapper import StableBaselinesGodotEnv
1213

1314
# To download the env source and binary:
1415
# 1. gdrl.env_from_hub -r edbeeching/godot_rl_BallChase
@@ -214,7 +215,8 @@ def func(progress_remaining: float) -> float:
214215
model.learn(**learn_arguments)
215216
except KeyboardInterrupt:
216217
print(
217-
"Training interrupted by user. Will save if --save_model_path was used and/or export if --onnx_export_path was used."
218+
"""Training interrupted by user. Will save if --save_model_path was
219+
used and/or export if --onnx_export_path was used."""
218220
)
219221

220222
close_env()

examples/stable_baselines3_hp_tuning.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,30 @@
88
99
You can run this example as follows:
1010
$ python examples/stable_baselines3_hp_tuning.py --env_path=<path/to/your/env> --speedup=8 --n_parallel=1
11-
12-
Feel free to copy this script and update, add or remove the hp values to your liking.
11+
12+
Feel free to copy this script and update, add or remove the hp values to your liking.
1313
"""
1414

1515
try:
1616
import optuna
1717
from optuna.pruners import MedianPruner
1818
from optuna.samplers import TPESampler
1919
except ImportError as e:
20+
print(e)
2021
print("You need to install optuna to use the hyperparameter tuning script. Try: pip install optuna")
2122
exit()
2223

23-
from typing import Any
24-
from typing import Dict
24+
import argparse
25+
from typing import Any, Dict
2526

2627
import gymnasium as gym
27-
28-
from godot_rl.wrappers.stable_baselines_wrapper import StableBaselinesGodotEnv
29-
from godot_rl.core.godot_env import GodotEnv
30-
28+
import torch
3129
from stable_baselines3 import PPO
3230
from stable_baselines3.common.callbacks import EvalCallback
3331
from stable_baselines3.common.vec_env.vec_monitor import VecMonitor
3432

35-
import torch
36-
import torch.nn as nn
37-
38-
import argparse
33+
from godot_rl.core.godot_env import GodotEnv
34+
from godot_rl.wrappers.stable_baselines_wrapper import StableBaselinesGodotEnv
3935

4036
parser = argparse.ArgumentParser(allow_abbrev=False)
4137
parser.add_argument(

godot_rl/core/godot_env.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ def check_platform(self, filename: str):
9999
# Linux
100100
assert (
101101
pathlib.Path(filename).suffix == ".x86_64"
102-
), f"Incorrect file suffix for filename {filename} suffix {pathlib.Path(filename).suffix}. Please provide a .x86_64 file"
102+
), f"Incorrect file suffix for {filename=} {pathlib.Path(filename).suffix=}. Please provide a .x86_64 file"
103103
elif platform == "darwin":
104104
# OSX
105105
assert (
106106
pathlib.Path(filename).suffix == ".app"
107-
), f"Incorrect file suffix for filename {filename} suffix {pathlib.Path(filename).suffix}. Please provide a .app file"
107+
), f"Incorrect file suffix for {filename=} {pathlib.Path(filename).suffix=}. Please provide a .app file"
108108
elif platform == "win32":
109109
# Windows...
110110
assert (
111111
pathlib.Path(filename).suffix == ".exe"
112-
), f"Incorrect file suffix for filename {filename} suffix {pathlib.Path(filename).suffix}. Please provide a .exe file"
112+
), f"Incorrect file suffix for {filename=} {pathlib.Path(filename).suffix=}. Please provide a .exe file"
113113
else:
114114
assert 0, f"unknown filetype {pathlib.Path(filename).suffix}"
115115

@@ -132,7 +132,7 @@ def from_numpy(self, action, order_ij=False):
132132
env_action = {}
133133

134134
for j, k in enumerate(self._action_space.keys()):
135-
if order_ij == True:
135+
if order_ij is True:
136136
v = action[i][j]
137137
else:
138138
v = action[j][i]
@@ -263,7 +263,7 @@ def _launch_env(self, env_path, port, show_window, framerate, seed, action_repea
263263

264264
launch_cmd = f"{path} --port={port} --env_seed={seed}"
265265

266-
if show_window == False:
266+
if show_window is False:
267267
launch_cmd += " --disable-render-loop --headless"
268268
if framerate is not None:
269269
launch_cmd += f" --fixed-fps {framerate}"
@@ -382,7 +382,7 @@ def _clear_socket(self):
382382
data = self.connection.recv(4)
383383
if not data:
384384
break
385-
except BlockingIOError as e:
385+
except BlockingIOError:
386386
pass
387387
self.connection.setblocking(True)
388388

godot_rl/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def convert_macos_path(env_path):
2424
"""
2525

2626
filenames = re.findall(r"[^\/]+(?=\.)", env_path)
27-
assert len(filenames) == 1, f"An error occured while converting the env path for MacOS."
27+
assert len(filenames) == 1, "An error occured while converting the env path for MacOS."
2828
return env_path + "/Contents/MacOS/" + filenames[0]
2929

3030

godot_rl/download_utils/download_examples.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,35 @@
22

33
import os
44
import shutil
5-
from sys import platform
65
from zipfile import ZipFile
76

87
import wget
98

10-
BANCHES = {"4": "main", "3": "godot3.5"}
9+
BRANCHES = {"4": "main", "3": "godot3.5"}
1110

1211
BASE_URL = "https://github.com/edbeeching/godot_rl_agents_examples"
1312

1413

1514
def download_examples():
1615
# select branch
1716
print("Select Godot version:")
18-
for key in BANCHES.keys():
19-
print(f"{key} : {BANCHES[key]}")
17+
for key in BRANCHES.keys():
18+
print(f"{key} : {BRANCHES[key]}")
2019

2120
branch = input("Enter your choice: ")
22-
BRANCH = BANCHES[branch]
21+
BRANCH = BRANCHES[branch]
2322
os.makedirs("examples", exist_ok=True)
2423
URL = f"{BASE_URL}/archive/refs/heads/{BRANCH}.zip"
2524
print(f"downloading examples from {URL}")
2625
wget.download(URL, out="")
2726
print()
28-
print(f"unzipping")
27+
print("unzipping")
2928
with ZipFile(f"{BRANCH}.zip", "r") as zipObj:
3029
# Extract all the contents of zip file in different directory
3130
zipObj.extractall("examples/")
32-
print(f"cleaning up")
31+
print("cleaning up")
3332
os.remove(f"{BRANCH}.zip")
34-
print(f"moving files")
33+
print("moving files")
3534
for file in os.listdir(f"examples/godot_rl_agents_examples-{BRANCH}"):
3635
shutil.move(f"examples/godot_rl_agents_examples-{BRANCH}/{file}", "examples")
3736
os.rmdir(f"examples/godot_rl_agents_examples-{BRANCH}")

godot_rl/download_utils/download_godot_editor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import shutil
32
from sys import platform
43
from zipfile import ZipFile
54

@@ -50,9 +49,9 @@ def download_editor():
5049
print(f"downloading editor {FILENAME} for platform: {platform}")
5150
wget.download(URL, out="")
5251
print()
53-
print(f"unzipping")
52+
print("unzipping")
5453
with ZipFile(FILENAME, "r") as zipObj:
5554
# Extract all the contents of zip file in different directory
5655
zipObj.extractall("editor/")
57-
print(f"cleaning up")
56+
print("cleaning up")
5857
os.remove(FILENAME)

godot_rl/download_utils/from_hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def main():
1818
parser.add_argument(
1919
"-r",
2020
"--hf_repository",
21-
help="Repo id of the dataset / environment repository from the Hugging Face Hub in the form user_name/repo_name",
21+
help="Repo id of the dataset / environment repo from the Hugging Face Hub in the form user_name/repo_name",
2222
type=str,
2323
)
2424
parser.add_argument(

0 commit comments

Comments
 (0)