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

Add pyproject, pre commit #414

Closed
wants to merge 7 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 38 additions & 0 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
---
name: Python tests

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
linux-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
# - uses: openrndr/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install python3-opengl xvfb
pip install -e .[testing]
- name: Source distribution test
run: |
python setup.py sdist
pip install dist/*.tar.gz
- name: Release Test
run: |
xvfb-run -s "-screen 0 1024x768x24" pytest -v --cov=metaworld --cov-report term
27 changes: 27 additions & 0 deletions .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
---
name: MacOS tests

on:
push:
branches: [master]

permissions:
contents: read

jobs:
macos-test:
runs-on: macos-11
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Install dependencies
run: |
pip install -e .[testing]
- name: Full Python tests
run: |
pytest -v
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://pre-commit.com
# This GitHub Action assumes that the repo contains a valid .pre-commit-config.yaml file.
---
name: pre-commit
on:
pull_request:
push:
branches: [master]

permissions:
contents: read

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install pre-commit
- run: pre-commit --version
- run: pre-commit install
- run: pre-commit run --all-files
61 changes: 61 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
repos:
- repo: https://github.com/python/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
args:
- --skip=*.css,*.js,*.map,*.scss,*.svg,*.ipynb
- --ignore-words-list=magent
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args:
- '--per-file-ignores=*/__init__.py:F401'
- --extend-ignore=E203,W605,F841,E731,E741,F401 # TODO: fix some of these
- --max-complexity=205
- --max-line-length=300
- --show-source
- --statistics
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args:
- --source
- --explain
- --convention=google
- --count
# TODO: Remove ignoring rules D101, D102, D103, D105
- --add-ignore=D100,D107,D101,D102,D103,D105
exclude: "__init__.py$|^metaworld.tests|^docs"
additional_dependencies: ["tomli"]
- repo: local
hooks:
- id: pyright
name: pyright
entry: pyright
language: node
pass_filenames: false
types: [python]
additional_dependencies: ["pyright"]
18 changes: 11 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ To be submitted, a pull request must satisfy the following criteria:
These criteria may be satisfied in any order, but in practice your PR is unlikely to get attention from contributors until 1-3 are satisfied. Maintainer attention is a scarce resource, so generally maintainers wait for a review from a non-maintainer contributor before reviewing your PR.

## Preparing your repo to make contributions
After following the standard Meta-World setup steps, make sure to run to install the pre-commit hooks into your repository. pre-commit helps streamline the pull request process by catching basic problems locally before they are checked by the CI.
First, install the Metaworld locally in editable mode, with testing dependencies:

```
pip install -e .[testing]
```

Then, make sure to run to install the pre-commit hooks into your repository. pre-commit helps streamline the pull request process by catching basic problems locally before they are checked by the CI.

To setup pre-commit in your repo:
```sh
Expand All @@ -42,12 +48,10 @@ To setup pre-commit in your repo:
# pipenv shell
# poetry shell
# source venv/bin/activate
pre-commit install -t pre-commit
pre-commit install -t pre-push
pre-commit install -t commit-msg
pre-commit install
```

Once you've installed pre-commit, it will automatically run every time you type `git commit`.
Once you've installed pre-commit, it will automatically run every time you type `git commit`, or you can run it manually using `pre-commit run --all-files`.

## Code style
The Python code in metaworld conforms to the [PEP8](https://www.python.org/dev/peps/pep-0008/) standard. Please read and understand it in detail.
Expand Down Expand Up @@ -143,7 +147,7 @@ These are Meta-World specific rules which are not part of the aforementioned sty

* When using external dependencies, use the `import` statement only to import whole modules, not individual classes or functions.

This applies to both packages from the standard library and 3rd-party dependencies. If a package has a long or cumbersome full path, or is used very frequently (e.g. `numpy`, `tensorflow`), you may use the keyword `as` to create a file-specific name which makes sense. Additionally, you should always follow the community concensus short names for common dependencies (see below).
This applies to both packages from the standard library and 3rd-party dependencies. If a package has a long or cumbersome full path, or is used very frequently (e.g. `numpy`, `tensorflow`), you may use the keyword `as` to create a file-specific name which makes sense. Additionally, you should always follow the community consensus short names for common dependencies (see below).

*Do*
```python
Expand Down Expand Up @@ -172,7 +176,7 @@ These are Meta-World specific rules which are not part of the aforementioned sty
m = MLPModel(output_dim=2)
```

*Known community-concensus imports*
*Known community-consensus imports*
```python
import numpy as np
import matplotlib.pyplot as plt
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ RUN python3 -m venv $HOME/venv
# Copy setup.py first, so that the Docker cache doesn't expire until
# dependencies change
COPY --chown=$USER:$USER setup.py $HOME/code/metaworld/setup.py
COPY --chown=$USER:$USER pyproject.toml $HOME/code/metaworld/pyproject.toml
WORKDIR $HOME/code/metaworld

# Install metaworld dependencies
RUN . $HOME/venv/bin/activate && exec pip install -e .[dev]
RUN . $HOME/venv/bin/activate && exec pip install -e .[testing]

# Add code stub last
COPY --chown=$USER:$USER . $HOME/code/metaworld
Expand Down
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ or specify the corresponding path through the MJKEY_PATH variable:
make run-headless RUN_CMD="..." MJKEY_PATH="/home/user/mjkey.txt"
```

If you require to pass addtional arguments to the the make commands, you can
If you require to pass additional arguments to the make commands, you can
use the variable ADD_ARGS, for example:
```
make build-headless ADD_ARGS="--build-arg MY_VAR=123"
Expand Down
Loading
Loading