From 80245bccc86bbf7c71f1decb865c2f6e65e91160 Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Mon, 23 Oct 2023 19:42:34 +0200 Subject: [PATCH 1/6] Update dependencies (shimmy, sphinx) --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index cdaf263..496caf7 100644 --- a/setup.py +++ b/setup.py @@ -85,7 +85,7 @@ extra_no_roms = [ "tqdm", "rich", # For atari games, - "shimmy[atari]~=1.1.0", + "shimmy[atari]~=1.3.0", "pillow", ] @@ -126,7 +126,7 @@ setup( "black>=23.9.1,<24", ], "docs": [ - "sphinx>=5.3,<7.0", + "sphinx", "sphinx-autobuild", "sphinx-rtd-theme", # For spelling From d672008a32941ef515107fd2b27cc0f72d90eaa0 Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Mon, 23 Oct 2023 20:12:51 +0200 Subject: [PATCH 2/6] Update dependencies (remove sphinx type hint plugin), protect type aliases --- docs/conf.py | 3 ++- docs/misc/changelog.rst | 3 ++- stable_baselines3/common/callbacks.py | 7 +++++-- stable_baselines3/common/type_aliases.py | 12 +++++++----- stable_baselines3/version.txt | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8aeae8b..bd63657 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -64,7 +64,6 @@ release = __version__ # ones. extensions = [ "sphinx.ext.autodoc", - "sphinx_autodoc_typehints", "sphinx.ext.autosummary", "sphinx.ext.mathjax", "sphinx.ext.ifconfig", @@ -73,6 +72,8 @@ extensions = [ # 'sphinx.ext.doctest' ] +autodoc_typehints = "description" + if enable_spell_check: extensions.append("sphinxcontrib.spelling") diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index 616c859..ffe1d7e 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -3,7 +3,7 @@ Changelog ========== -Release 2.2.0a7 (WIP) +Release 2.2.0a8 (WIP) -------------------------- Breaking Changes: @@ -55,6 +55,7 @@ Others: - Fixed ``stable_baselines3/her/her_replay_buffer.py`` type hints - Buffers do no call an additional ``.copy()`` when storing new transitions - Fixed ``ActorCriticPolicy.extract_features()`` signature by adding an optional ``features_extractor`` argument +- Update dependencies (accept newer Shimmy/Sphinx version and remove ``sphinx_autodoc_typehints``) Documentation: ^^^^^^^^^^^^^^ diff --git a/stable_baselines3/common/callbacks.py b/stable_baselines3/common/callbacks.py index 5089bba..2898df8 100644 --- a/stable_baselines3/common/callbacks.py +++ b/stable_baselines3/common/callbacks.py @@ -1,7 +1,7 @@ import os import warnings from abc import ABC, abstractmethod -from typing import Any, Callable, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union import gymnasium as gym import numpy as np @@ -19,10 +19,13 @@ except ImportError: # if the progress bar is used tqdm = None -from stable_baselines3.common import base_class + from stable_baselines3.common.evaluation import evaluate_policy from stable_baselines3.common.vec_env import DummyVecEnv, VecEnv, sync_envs_normalization +if TYPE_CHECKING: + from stable_baselines3.common import base_class + class BaseCallback(ABC): """ diff --git a/stable_baselines3/common/type_aliases.py b/stable_baselines3/common/type_aliases.py index 2f98ee1..4a0a878 100644 --- a/stable_baselines3/common/type_aliases.py +++ b/stable_baselines3/common/type_aliases.py @@ -1,15 +1,17 @@ """Common aliases for type hints""" - from enum import Enum -from typing import Any, Callable, Dict, List, NamedTuple, Optional, Protocol, SupportsFloat, Tuple, Union +from typing import TYPE_CHECKING, Any, Callable, Dict, List, NamedTuple, Optional, Protocol, SupportsFloat, Tuple, Union import gymnasium as gym import numpy as np import torch as th -from stable_baselines3.common import callbacks, vec_env +# Avoid circular imports, we use type hint as string to avoid it too +if TYPE_CHECKING: + from stable_baselines3.common.callbacks import BaseCallback + from stable_baselines3.common.vec_env import VecEnv -GymEnv = Union[gym.Env, vec_env.VecEnv] +GymEnv = Union[gym.Env, "VecEnv"] GymObs = Union[Tuple, Dict[str, Any], np.ndarray, int] GymResetReturn = Tuple[GymObs, Dict] AtariResetReturn = Tuple[np.ndarray, Dict[str, Any]] @@ -17,7 +19,7 @@ GymStepReturn = Tuple[GymObs, float, bool, bool, Dict] AtariStepReturn = Tuple[np.ndarray, SupportsFloat, bool, bool, Dict[str, Any]] TensorDict = Dict[str, th.Tensor] OptimizerStateDict = Dict[str, Any] -MaybeCallback = Union[None, Callable, List[callbacks.BaseCallback], callbacks.BaseCallback] +MaybeCallback = Union[None, Callable, List["BaseCallback"], "BaseCallback"] # A schedule takes the remaining progress as input # and ouputs a scalar (e.g. learning rate, clip range, ...) diff --git a/stable_baselines3/version.txt b/stable_baselines3/version.txt index 9b9407a..f1f23b3 100644 --- a/stable_baselines3/version.txt +++ b/stable_baselines3/version.txt @@ -1 +1 @@ -2.2.0a7 +2.2.0a8 From 6c70993c8f1ed7fd5832b30230f78509242dd8cb Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Mon, 23 Oct 2023 20:26:33 +0200 Subject: [PATCH 3/6] Remove sphinx-autodoc-typehints --- docs/conda_env.yml | 5 ++--- setup.py | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/conda_env.yml b/docs/conda_env.yml index 8c71fe9..53fecf2 100644 --- a/docs/conda_env.yml +++ b/docs/conda_env.yml @@ -14,7 +14,6 @@ dependencies: - pandas - numpy - matplotlib - - sphinx_autodoc_typehints - - sphinx>=5.3,<7.0 - - sphinx_rtd_theme>=1.0 + - sphinx>=5,<8 + - sphinx_rtd_theme>=1.3.0 - sphinx_copybutton diff --git a/setup.py b/setup.py index 496caf7..0a1ab30 100644 --- a/setup.py +++ b/setup.py @@ -126,13 +126,11 @@ setup( "black>=23.9.1,<24", ], "docs": [ - "sphinx", + "sphinx>=5,<8", "sphinx-autobuild", - "sphinx-rtd-theme", + "sphinx-rtd-theme>=1.3.0", # For spelling "sphinxcontrib.spelling", - # Type hints support - "sphinx-autodoc-typehints", # Copy button for code snippets "sphinx_copybutton", ], From c1fc8e4c75d9ffec9d728c5998ccc6be162edf23 Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Mon, 23 Oct 2023 20:31:58 +0200 Subject: [PATCH 4/6] Update RTD config --- .readthedocs.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index 6753d87..38a95e3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,3 +14,9 @@ formats: all # Set requirements using conda env conda: environment: docs/conda_env.yml + +build: + os: ubuntu-22.04 + tools: + # Note: we are using a conda env, we specify one tool as it is required + python: "3.10" From 75a5b68e8a01e1ba0248fa5314b9d1809faa8efe Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Mon, 23 Oct 2023 20:34:20 +0200 Subject: [PATCH 5/6] Remove tools key --- .readthedocs.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 38a95e3..857bf5b 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -17,6 +17,3 @@ conda: build: os: ubuntu-22.04 - tools: - # Note: we are using a conda env, we specify one tool as it is required - python: "3.10" From 350931f441565904eccf373aca6e646ab0277bb7 Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Mon, 23 Oct 2023 20:38:48 +0200 Subject: [PATCH 6/6] Use mambaforge as tool --- .readthedocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index 857bf5b..dbb2fad 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -17,3 +17,5 @@ conda: build: os: ubuntu-22.04 + tools: + python: "mambaforge-22.9"