Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade package versioning to use Poetry #1681

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.6.1

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
poetry config virtualenvs.create false
poetry install --no-root --all-extras
# cpu version of pytorch
pip install torch==1.13+cpu -f https://download.pytorch.org/whl/torch_stable.html

# Install Atari Roms
pip install autorom
wget https://gist.githubusercontent.com/jjshoots/61b22aefce4456920ba99f2c36906eda/raw/00046ac3403768bfe45857610a3d333b8e35e026/Roms.tar.gz.b64
base64 Roms.tar.gz.b64 --decode &> Roms.tar.gz
AutoROM --accept-license --source-file Roms.tar.gz

pip install .[extra_no_roms,tests,docs]
# Use headless version
pip install opencv-python-headless
if: steps.cache.outputs.cache-hit != 'true'
- name: Lint with ruff
run: |
make lint
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cd stable-baselines3/
2. Install Stable-Baselines3 in develop mode, with support for building the docs and running tests:

```bash
pip install -e .[docs,tests,extra]
poetry install --all-extras
```

## Codestyle
Expand Down
26 changes: 15 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ ARG PARENT_IMAGE
FROM $PARENT_IMAGE
ARG PYTORCH_DEPS=cpuonly
ARG PYTHON_VERSION=3.10
ARG MAMBA_DOCKERFILE_ACTIVATE=1 # (otherwise python will not be found)

# (otherwise python will not be found)
ARG MAMBA_DOCKERFILE_ACTIVATE=1
USER root
# Install micromamba env and dependencies
RUN micromamba install -n base -y python=$PYTHON_VERSION \
pytorch $PYTORCH_DEPS -c conda-forge -c pytorch -c nvidia && \
micromamba clean --all --yes

ENV CODE_DIR /home/$MAMBA_USER
RUN apt-get update
RUN apt-get install -y build-essential

ENV CODE_DIR /home/$MAMBA_USER
WORKDIR ${CODE_DIR}/stable-baselines3
# Copy setup file only to install dependencies
COPY --chown=$MAMBA_USER:$MAMBA_USER ./setup.py ${CODE_DIR}/stable-baselines3/setup.py
COPY --chown=$MAMBA_USER:$MAMBA_USER ./stable_baselines3/version.txt ${CODE_DIR}/stable-baselines3/stable_baselines3/version.txt

RUN cd ${CODE_DIR}/stable-baselines3 && \
pip install -e .[extra,tests,docs] && \
# Use headless version for docker
pip uninstall -y opencv-python && \
pip install opencv-python-headless && \
pip cache purge
COPY --chown=$MAMBA_USER:$MAMBA_USER ./pyproject.toml .

RUN pip install poetry>=1.6.1
RUN poetry config virtualenvs.create false
RUN poetry install --all-extras --no-root --no-cache
RUN pip uninstall -y opencv-python
RUN pip install opencv-python-headless
RUN pip cache purge

CMD /bin/bash
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SHELL=/bin/bash
LINT_PATHS=stable_baselines3/ tests/ docs/conf.py setup.py
LINT_PATHS=stable_baselines3/ tests/ docs/conf.py

pytest:
./scripts/run_tests.sh
Expand Down Expand Up @@ -60,12 +60,13 @@ docker-gpu:

# PyPi package release
release:
python -m build
twine upload dist/*
poetry build
poetry publish

# Test PyPi package release
test-release:
python -m build
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
poetry build
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry publish

.PHONY: clean spelling doc lint format check-codestyle commit-checks
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Actions `gym.spaces`:
## Testing the installation
### Install dependencies
```sh
pip install -e .[docs,tests,extra]
poetry install --all-extras
```
### Run tests
All unit tests in stable baselines3 can be run using `pytest` runner:
Expand Down
9 changes: 6 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import datetime
import os
import sys
from pathlib import Path
from typing import Dict

import toml

# We CANNOT enable 'sphinxcontrib.spelling' because ReadTheDocs.org does not support
# PyEnchant.
try:
Expand All @@ -37,9 +40,9 @@
sys.path.insert(0, os.path.abspath(".."))

# Read version from file
version_file = os.path.join(os.path.dirname(__file__), "../stable_baselines3", "version.txt")
with open(version_file) as file_handler:
__version__ = file_handler.read().strip()
pyproject = toml.load(Path(__file__).parent.parent / "pyproject.toml") # This is in a nested directory, 2 directories down

__version__ = pyproject["tool"]["poetry"]["version"]

# -- Project information -----------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions docs/guide/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ Bleeding-edge version

.. code-block:: bash

pip install git+https://github.com/DLR-RM/stable-baselines3
poetry install git+https://github.com/DLR-RM/stable-baselines3.git

with extras:

.. code-block:: bash

pip install "stable_baselines3[extra,tests,docs] @ git+https://github.com/DLR-RM/stable-baselines3"
poetry install --all-extras git+https://github.com/DLR-RM/stable-baselines3.git


Development version
Expand All @@ -69,7 +69,7 @@ To contribute to Stable-Baselines3, with support for running tests and building
.. code-block:: bash

git clone https://github.com/DLR-RM/stable-baselines3 && cd stable-baselines3
pip install -e .[docs,tests,extra]
poetry install --all-extras


Using Docker Images
Expand Down
2 changes: 1 addition & 1 deletion docs/misc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Release 2.2.0a3 (WIP)
Breaking Changes:
^^^^^^^^^^^^^^^^^
- Switched to ``ruff`` for sorting imports (isort is no longer needed), black and ruff version now require a minimum version

- Switched to using Poetry for package management
New Features:
^^^^^^^^^^^^^

Expand Down
107 changes: 105 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,107 @@
[tool.poetry]
name = "stable-baselines3"
version = "2.2.0a2"
description = "Pytorch version of Stable Baselines, implementations of reinforcement learning algorithms."
authors = ["Antonin Raffin <[email protected]>"]
readme = "README.md"
packages = [{include = "stable_baselines3"}]

keywords = [
"reinforcement-learning-algorithms",
"reinforcement-learning",
"machine-learning",
"gymnasium",
"gym",
"openai",
"stable",
"baselines",
"toolbox",
"python",
"data-science"]
license = "MIT"
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

[tool.poetry.urls]
Code = "https://github.com/DLR-RM/stable-baselines3"
Documentation = "https://stable-baselines3.readthedocs.io/"
Changelog = "https://stable-baselines3.readthedocs.io/en/master/misc/changelog.html"
SB3-Contrib = "https://github.com/Stable-Baselines-Team/stable-baselines3-contrib"
RL-Zoo = "https://github.com/DLR-RM/rl-baselines3-zoo"
SBX = "https://github.com/araffin/sbx"

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
gymnasium = { version = ">=0.28.1,<0.30", extras = ["atari", "accept-rom-license"]}
numpy = ">=1.20"
torch = ">=1.13"
cloudpickle = "*"
pandas = "*"
matplotlib = "*"
pytest = {version = "*", optional = true}
pytest-cov = {version = "*", optional = true}
pytest-env = {version = "*", optional = true}
pytest-xdist = {version = "*", optional = true}
pytype = {version = "2023.09.11", optional = true, python = "<3.11"}
mypy = {version = "*", optional = true}
ruff = {version = "*", optional = true}
isort = {version = ">=5.0", optional = true}
black = {version = "*", optional = true}
sphinx = {version = ">=5.3,<7.0", optional = true}
sphinx-autobuild = {version = "*", optional = true}
sphinx-rtd-theme = {version = "*", optional = true}
"sphinxcontrib.spelling" = {version = "*", optional = true}
sphinx-autodoc-typehints = {version = "*", optional = true}
sphinx_copybutton = {version = "*", optional = true}
autorom = {version = ">=0.4.2,<0.5.0", extras=["accept-rom-license"], optional = true}
tqdm = "^4.66.1"
toml = "^0.10.2"
tensorboard = {version = "^2.14.0", optional = true}
types-toml = "^0.10.8.7"
rich = {version = "*", optional = true}
pygame = {version = "*", optional = true}
opencv-python = {version = "*", optional = true}

[tool.poetry.extras]
tests = [
# Run tests and coverage
"pytest",
"pytest-cov",
"pytest-env",
"pytest-xdist",
# Type check
"pytype",
"mypy",
# Lint code (flake8 replacement)
"ruff",
# Sort imports
"isort",
# Reformat
"black",
]
docs = [
"sphinx",
"sphinx-autobuild",
"sphinx-rtd-theme",
# For spelling
"sphinxcontrib.spelling",
# Type hints support
"sphinx-autodoc-typehints",
# Copy button for code snippets
"sphinx_copybutton",
]

extra = ["autorom", "tqdm", "tensorboard", "rich", "pygame", "opencv-python"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
# Same as Black.
line-length = 127
Expand Down Expand Up @@ -65,12 +169,11 @@ disable_warnings = ["couldnt-parse"]
branch = false
omit = [
"tests/*",
"setup.py",
# Require graphical interface
"stable_baselines3/common/results_plotter.py",
# Require ffmpeg
"stable_baselines3/common/vec_env/vec_video_recorder.py",
]

[tool.coverage.report]
exclude_lines = [ "pragma: no cover", "raise NotImplementedError()", "if typing.TYPE_CHECKING:"]
exclude_lines = [ "pragma: no cover", "raise NotImplementedError()", "if typing.TYPE_CHECKING:"]
2 changes: 1 addition & 1 deletion scripts/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CPU_PARENT=mambaorg/micromamba:1.5-jammy
GPU_PARENT=mambaorg/micromamba:1.5-jammy-cuda-11.7.1

TAG=stablebaselines/stable-baselines3
VERSION=$(cat ./stable_baselines3/version.txt)
VERSION=$(grep -m 1 version pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)

if [[ ${USE_GPU} == "True" ]]; then
PARENT=${GPU_PARENT}
Expand Down
Loading