Skip to content

Commit

Permalink
Update and rerun pre-commit hooks for better code quality (openai#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan authored Dec 4, 2022
1 parent 9157a97 commit 7e88559
Show file tree
Hide file tree
Showing 185 changed files with 1,423 additions and 762 deletions.
11 changes: 5 additions & 6 deletions .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ body:
- type: markdown
attributes:
value: >
If you're a beginner and have basic questions, please ask on
[r/reinforcementlearning](https://www.reddit.com/r/reinforcementlearning/) or in the
[RL Discord](https://discord.com/invite/xhfNqQv) (if you're new please use the beginners channel).
Basic questions that are not bugs or feature requests will be closed without reply, because GitHub
issues are not an appropriate venue for these. Advanced/nontrivial questions, especially in areas where
If you're a beginner and have basic questions, please ask on
[r/reinforcementlearning](https://www.reddit.com/r/reinforcementlearning/) or in the
[RL Discord](https://discord.com/invite/xhfNqQv) (if you're new please use the beginners channel).
Basic questions that are not bugs or feature requests will be closed without reply, because GitHub
issues are not an appropriate venue for these. Advanced/nontrivial questions, especially in areas where
documentation is lacking, are very much welcome.
- type: textarea
id: question
attributes:
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Please delete options that are not relevant.
- [ ] This change requires a documentation update

### Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Expand Down
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ only: issues

# issues:
# exemptLabels:
# - confirmed
# - confirmed
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
with:
folder: _build
target-folder: main
clean: false
clean: false
2 changes: 1 addition & 1 deletion .github/workflows/docs-manual-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ jobs:
folder: _build
clean-exclude: |
*.*.*/
main
main
2 changes: 1 addition & 1 deletion .github/workflows/docs-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
folder: _build
clean-exclude: |
*.*.*/
main
main
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
.DS_Store
.cache
.pytest_cache/
__pycache__/

# Setuptools distribution and build folders.
/dist/
/build
/wheels
/wheelhouse

# Virtualenv
/env
/venv

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info
Expand Down
40 changes: 28 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/python/black
rev: 22.3.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: black
- id: check-symlinks
- id: destroyed-symlinks
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-ast
- id: check-added-large-files
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: detect-private-key
- id: debug-statements
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.2
hooks:
- id: codespell
args:
- --ignore-words-list=nd,reacher,thist,ths, ure, referenc,wile
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
args:
Expand All @@ -21,11 +34,19 @@ repos:
- --max-line-length=456
- --show-source
- --statistics
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/python/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
Expand All @@ -36,11 +57,6 @@ repos:
- --explain
- --convention=google
additional_dependencies: ["toml"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: local
hooks:
- id: pyright
Expand Down
1 change: 0 additions & 1 deletion CODE_OF_CONDUCT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@ Attribution
-----------
This Code of Conduct is adapted from `Python's Code of Conduct <https://www.python.org/psf/conduct/>`_, which is under a `Creative Commons License
<https://creativecommons.org/licenses/by-sa/3.0/>`_.

33 changes: 22 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,62 @@ Notably, we are not accepting these forms of contributions:
- New environments

# Development

This section contains technical instructions & hints for the contributors.

## Type checking
The project uses `pyright` to check types.
To type check locally, install `pyright` per official [instructions](https://github.com/microsoft/pyright#command-line).

The project uses `pyright` to check types.
To type check locally, install `pyright` per official [instructions](https://github.com/microsoft/pyright#command-line).
It's configuration lives within `pyproject.toml`. It includes list of included and excluded files currently supporting type checks.
To run `pyright` for the project, run the pre-commit process (`pre-commit run --all-files`) or `pyright --project=pyproject.toml`
Alternatively, pyright is a built-in feature of VSCode that will automatically provide type hinting.

### Adding typing to more modules and packages
If you would like to add typing to a module in the project,
the list of included, excluded and strict files can be found in pyproject.toml (pyproject.toml -> [tool.pyright]).

If you would like to add typing to a module in the project,
the list of included, excluded and strict files can be found in pyproject.toml (pyproject.toml -> [tool.pyright]).
To run `pyright` for the project, run the pre-commit process (`pre-commit run --all-files`) or `pyright`

## Git hooks

The CI will run several checks on the new code pushed to the Gymnasium repository. These checks can also be run locally without waiting for the CI by following the steps below:

1. [install `pre-commit`](https://pre-commit.com/#install),
2. Install the Git hooks by running `pre-commit install`.

Once those two steps are done, the Git hooks will be run automatically at every new commit.
The Git hooks can also be run manually with `pre-commit run --all-files`, and if needed they can be skipped (not recommended) with `git commit --no-verify`.
Once those two steps are done, the Git hooks will be run automatically at every new commit.
The Git hooks can also be run manually with `pre-commit run --all-files`, and if needed they can be skipped (not recommended) with `git commit --no-verify`.
**Note:** you may have to run `pre-commit run --all-files` manually a couple of times to make it pass when you commit, as each formatting tool will first format the code and fail the first time but should pass the second time.

Additionally, for pull requests, the project runs a number of tests for the whole project using [pytest](https://docs.pytest.org/en/latest/getting-started.html#install-pytest).
These tests can be run locally with `pytest` in the root folder.
These tests can be run locally with `pytest` in the root folder.

## Docstrings

Pydocstyle has been added to the pre-commit process such that all new functions follow the [google docstring style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
All new functions require either a short docstring, a single line explaining the purpose of a function
or a multiline docstring that documents each argument and the return type (if there is one) of the function.
In addition, new file and class require top docstrings that should outline the purpose of the file/class.
For classes, code block examples can be provided in the top docstring and not the constructor arguments.

To check your docstrings are correct, run `pre-commit run --all-files` or `pydocstyle --source --explain --convention=google`.
If all docstrings that fail, the source and reason for the failure is provided.
If all docstrings that fail, the source and reason for the failure is provided.

## Building the docs

Make sure that you have install the requirements:

```shell
cd docs
pip install -r requirements.txt
```

Then run
```
python scripts/gen_mds.py

```shell
python scripts/gen_mds.py
make dirhtml
```
Now, navigate to `_build/dirhtml` and open `index.html` in your browser.

Now, navigate to `_build/dirhtml` and open `index.html` in your browser.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
<img src="https://raw.githubusercontent.com/Farama-Foundation/Gymnasium/main/gymnasium-text.png" width="500px"/>
</p>


Gymnasium is an open source Python library for developing and comparing reinforcement learning algorithms by providing a standard API to communicate between learning algorithms and environments, as well as a standard set of environments compliant with that API. This is a fork of OpenAI's [Gym](https://github.com/openai/gym) library by the maintainers (OpenAI handed over maintenance a few years ago to an outside team), and is where future maintenance will occur going forward

The documentation website is at [gymnasium.farama.org](https://gymnasium.farama.org), and we have a public discord server (which we also use to coordinate development work) that you can join here: https://discord.gg/bnJ6kubTg6


## Environments

Gymnasium includes the following families of environments along with a wide variety of third-party environments
Expand All @@ -20,7 +18,6 @@ Gymnasium includes the following families of environments along with a wide vari
* [Atari](https://gymnasium.farama.org/environments/atari/) - A set of 57 Atari 2600 environments simulated through Stella and the Arcade Learning Environment that have a high range of complexity for agents to learn.
* [Third-party](https://gymnasium.farama.org/environments/third_party_environments/) - A number of environments have been created that are compatible with the Gymnasium API. Be aware of the version that the software was created for and use the `apply_env_compatibility` in `gymnasium.make` if necessary.


## Installation

To install the base Gymnasium library, use `pip install gymnasium`
Expand Down Expand Up @@ -59,8 +56,6 @@ Please note that this is an incomplete list, and just includes libraries that th

Gymnasium keeps strict versioning for reproducibility reasons. All environments end in a suffix like "\_v0". When changes are made to environments that might impact learning results, the number is increased by one to prevent potential confusion. These inherent from Gym.


## Development Roadmap

We have a roadmap for future development work for Gymnasium available here: https://github.com/Farama-Foundation/Gymnasium/issues/12

2 changes: 1 addition & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ environments/box2d/*.md
environments/classic_control/*.md
environments/mujoco/*.md
environments/third_party_environments/*.md
environments/toy_text/*.md
environments/toy_text/*.md
2 changes: 1 addition & 1 deletion docs/_static/img/github_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions docs/api/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ title: Utils
.. autoattribute:: gymnasium.Env.action_space
The Space object corresponding to valid actions, all valid actions should be contained with the space. For example, if the action space is of type `Discrete` and gives the value `Discrete(2)`, this means there are two valid discrete actions: 0 & 1.
.. code::
>>> env.action_space
Expand All @@ -33,9 +33,9 @@ title: Utils
Box(-3.4028234663852886e+38, 3.4028234663852886e+38, (4,), float32)
.. autoattribute:: gymnasium.Env.observation_space
The Space object corresponding to valid observations, all valid observations should be contained with the space. For example, if the observation space is of type :class:`Box` and the shape of the object is ``(4,)``, this denotes a valid observation will be an array of 4 numbers. We can check the box bounds as well with attributes.
.. code::
>>> env.observation_space.high
Expand All @@ -46,19 +46,19 @@ title: Utils
.. autoattribute:: gymnasium.Env.metadata
The metadata of the environment containing rendering modes, rendering fps, etc
.. autoattribute:: gymnasium.Env.render_mode
The render mode of the environment determined at initialisation
.. autoattribute:: gymnasium.Env.reward_range
A tuple corresponding to the minimum and maximum possible rewards for an agent over an episode. The default reward range is set to :math:`(-\infty,+\infty)`.
.. autoattribute:: gymnasium.Env.spec
The ``EnvSpec`` of the environment normally set during :py:meth:`gymnasium.make`
```
```

### Additional Methods

Expand Down
Loading

0 comments on commit 7e88559

Please sign in to comment.