From 81e50272d74565df42037977f5813cb824bd55c8 Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Mon, 13 Jan 2020 21:05:47 -0800 Subject: [PATCH 1/6] black: reformat setup.py and make flake8 config compatible --- ci/code_checks.sh | 3 +- setup.cfg | 4 +++ setup.py | 85 +++++++++++++++++++++-------------------------- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 39f9f7c..161c2ee 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -8,7 +8,8 @@ set -e # quit immediately on error echo "Source format checking" flake8 ${SRC_FILES[@]} -codespell -I .codespell.skip --skip='*.pyc,tests/data/*,*.ipynb,*.csv' ${SRC_FILES[@]} +black --check ${SRC_FILES} +codespell -I .codespell.skip --skip='*.pyc' ${SRC_FILES[@]} if [ -x "`which circleci`" ]; then circleci config validate diff --git a/setup.cfg b/setup.cfg index 4e00f7a..7b8e85b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,10 @@ source = src/benchmark_environments *venv/lib/python*/site-packages/benchmark_environments +[flake8] +ignore = E203, W503 +max-line-length = 88 + [isort] line_length=80 known_first_party=benchmark_environments,tests diff --git a/setup.py b/setup.py index f659846..9b868e1 100644 --- a/setup.py +++ b/setup.py @@ -1,68 +1,57 @@ from setuptools import find_packages, setup import src.benchmark_environments # pytype: disable=import-error -TF_VERSION = '>=1.15.0,<2.0' +TF_VERSION = ">=1.15.0,<2.0" TESTS_REQUIRE = [ # remove pin once https://github.com/nedbat/coveragepy/issues/881 fixed - 'black', - 'coverage==4.5.4', - 'codecov', - 'codespell', - 'isort', - 'flake8', - 'flake8-blind-except', - 'flake8-builtins', - 'flake8-commas', - 'flake8-debugger', - 'flake8-isort', - 'pytest', - 'pytest-cov', - 'pytest-shard', - 'pytest-xdist', - 'pytype', - 'sphinx', - 'sphinxcontrib-napoleon', + "black", + "coverage==4.5.4", + "codecov", + "codespell", + "isort", + "flake8", + "flake8-blind-except", + "flake8-builtins", + "flake8-debugger", + "flake8-isort", + "pytest", + "pytest-cov", + "pytest-shard", + "pytest-xdist", + "pytype", + "sphinx", + "sphinxcontrib-napoleon", ] setup( - name='benchmark_environments', + name="benchmark_environments", version=src.benchmark_environments.__version__, - description=( - 'Implementation of modern IRL and imitation learning algorithms.'), - author='Center for Human-Compatible AI and Google', - python_requires='>=3.7.0', - packages=find_packages('src'), - package_dir={'': 'src'}, + description=("Implementation of modern IRL and imitation learning algorithms."), + author="Center for Human-Compatible AI and Google", + python_requires=">=3.7.0", + packages=find_packages("src"), + package_dir={"": "src"}, package_data={ - 'benchmark_environments': [ - 'py.typed', - 'envs/examples/airl_envs/assets/*.xml', - ], + "benchmark_environments": ["py.typed", "envs/examples/airl_envs/assets/*.xml"], }, - install_requires=[ - 'gym[mujoco]', - ], + install_requires=["gym[mujoco]"], tests_require=TESTS_REQUIRE, extras_require={ # recommended packages for development - 'dev': [ - 'ipdb', - 'jupyter', - *TESTS_REQUIRE, - ], - 'test': TESTS_REQUIRE, + "dev": ["ipdb", "jupyter", *TESTS_REQUIRE], + "test": TESTS_REQUIRE, }, - url='https://github.com/HumanCompatibleAI/benchmark-environments', - license='MIT', + url="https://github.com/HumanCompatibleAI/benchmark-environments", + license="MIT", classifiers=[ # Trove classifiers # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", ], ) From 886185a13347492dd7697e4ecb1fec5cdd337acd Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Mon, 13 Jan 2020 21:23:52 -0800 Subject: [PATCH 2/6] Add enough tests to ensure at least one test collected per shard --- tests/test_dummy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_dummy.py b/tests/test_dummy.py index 2583082..e8e32f9 100644 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -1,3 +1,7 @@ -def test_dummy(): +import pytest + + +@pytest.mark.parametrize("i", range(10)) +def test_dummy(i): # TODO(adam): remove me once we have real tests! assert True From da304259c6f4d017672d44a988a5e8d72877556b Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Mon, 13 Jan 2020 21:29:16 -0800 Subject: [PATCH 3/6] more dummy tests! --- tests/test_dummy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_dummy.py b/tests/test_dummy.py index e8e32f9..c9a54e7 100644 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -1,7 +1,7 @@ import pytest -@pytest.mark.parametrize("i", range(10)) +@pytest.mark.parametrize("i", range(20)) def test_dummy(i): # TODO(adam): remove me once we have real tests! assert True From 788079b1425ad588d705571a7da792fcaee7f898 Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Mon, 13 Jan 2020 21:32:38 -0800 Subject: [PATCH 4/6] Draft README --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..742419d --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +[![CircleCI](https://circleci.com/gh/HumanCompatibleAI/benchmark-environments.svg?style=svg)](https://circleci.com/gh/HumanCompatibleAI/benchmark-environments) [![codecov](https://codecov.io/gh/HumanCompatibleAI/benchmark-environments/branch/master/graph/badge.svg)](https://codecov.io/gh/HumanCompatibleAI/benchmark-environments) + +**Status**: alpha, pre-release. + +# Usage + +To install the latest release from PyPi, run: + +```bash +pip install benchmark-environments +``` + +To install from source code: + +``` +git clone git@github.com:HumanCompatibleAI/benchmark-environments.git +cd benchmark-environments +pip install . +``` + +# Contributing + +For development, clone the source code and create a virtual environment for this project: + + ``` +git clone git@github.com:HumanCompatibleAI/benchmark-environments.git +cd benchmark-environments +./ci/build_venv.sh +pip install .[dev] # install extra tools useful for development +``` + +## Code style + +We follow a PEP8 code style, and typically follow the [Google Code Style Guide](http://google.github.io/styleguide/pyguide.html), +but defer to PEP8 where they conflict. We use the `black` autoformatter to avoid arguing over formatting. +Docstrings follow the Google docstring convention defined [here](http://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings), +with an extensive example in the [Sphinx docs](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). + +All PRs must pass linting via the `ci/code_checks.sh` script. It is convenient to install this as a commit hook: + +```bash +ln -s ../../ci/code_checks.sh .git/hooks/pre-commit +``` + +## Tests + +We use [pytest](https://docs.pytest.org/en/latest/) for unit tests +and [codecov](http://codecov.io/) for code coverage. +We also use [pytype](https://github.com/google/pytype) for type checking. + +## Workflow + +Trivial changes (e.g. typo fixes) may be made directly by maintainers. Any non-trivial changes +must be proposed in a PR and approved by at least one maintainer. PRs must pass the continuous +integration tests (CircleCI linting, type checking, unit tests and CodeCov) to be merged. + +It is often helpful to open an issue before proposing a PR, to allow for discussion of the design +before coding commences. \ No newline at end of file From b0e313c521ca65af0652444e770216c04b0e74fe Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Mon, 13 Jan 2020 22:00:56 -0800 Subject: [PATCH 5/6] Address comments --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 742419d..314a49b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,14 @@ **Status**: alpha, pre-release. +benchmark-environments is a suite of benchmarks for imitation-learning and +reward-learning algorithms. It is currently a work-in-progress, but we intend for it to eventually +contain a suite of diagnostic tasks for reward-learning, wrappers around common RL benchmark +environments that help to avoid common pitfalls in benchmarking (e.g. by masking visible score +counters in Gym Atari tasks), and new challenge tasks for imitation- and reward-learning. This +benchmark suite is a complement to our [https://github.com/humancompatibleai/imitation/](imitation) +package of baseline algorithms for imitation learning. + # Usage To install the latest release from PyPi, run: @@ -10,12 +18,10 @@ To install the latest release from PyPi, run: pip install benchmark-environments ``` -To install from source code: +To install from Git master: ``` -git clone git@github.com:HumanCompatibleAI/benchmark-environments.git -cd benchmark-environments -pip install . +pip install git+https://github.com/HumanCompatibleAI/benchmark-environments.git ``` # Contributing @@ -26,7 +32,7 @@ For development, clone the source code and create a virtual environment for this git clone git@github.com:HumanCompatibleAI/benchmark-environments.git cd benchmark-environments ./ci/build_venv.sh -pip install .[dev] # install extra tools useful for development +pip install -e .[dev] # install extra tools useful for development ``` ## Code style From 137ff049784aea435c78224157b0acfc2e9aa53a Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Tue, 14 Jan 2020 11:33:28 -0800 Subject: [PATCH 6/6] Update README.md Co-Authored-By: Steven H. Wang --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 314a49b..5eebf9e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ package of baseline algorithms for imitation learning. # Usage -To install the latest release from PyPi, run: +To install the latest release from PyPI, run: ```bash pip install benchmark-environments @@ -61,4 +61,4 @@ must be proposed in a PR and approved by at least one maintainer. PRs must pass integration tests (CircleCI linting, type checking, unit tests and CodeCov) to be merged. It is often helpful to open an issue before proposing a PR, to allow for discussion of the design -before coding commences. \ No newline at end of file +before coding commences.