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

Misc/tox #239

Merged
merged 21 commits into from
Jan 31, 2023
Merged
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
35 changes: 21 additions & 14 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,38 @@ on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ${{ matrix.os }}
name: Lint ${{ matrix.lint-kind }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: [3.8]
os: [ubuntu-latest]
lint-kind: [code, docs]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: precommit-${{ env.pythonLocation }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
python-version: '3.10'

- name: Install pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
python -m pip install tox

- name: Install PyEnchant
if: ${{ matrix.lint-kind == 'docs' }}
run: |
sudo apt update -y
sudo apt install libenchant-2-dev
python -m pip install pyenchant

- name: Lint
- name: Lint ${{ matrix.lint-kind }}
run: |
pre-commit run --all-files --show-diff-on-failure
tox -e lint-${{ matrix.lint-kind }}
45 changes: 0 additions & 45 deletions .github/workflows/notebook_tests.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox

- name: Build package
run: tox -e build-package

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
31 changes: 0 additions & 31 deletions .github/workflows/publish_to_pypi.yml

This file was deleted.

70 changes: 43 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,73 @@ on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-test:
fast-tests:
name: Fast tests Python 3.9 on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: Setup environment
run: |
tox -e py39 --notest -v

- name: Run tests
run: |
tox -e py39 --skip-pkg-install -- -m fast --memray -n auto -vv

tests:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.8]
python-version: ['3.8', '3.10', '3.11']
os: [ubuntu-latest]
test_mark: [fast, all]
include:
- python-version: '3.9'
os: macos-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
if: runner.os == 'Linux'
run: |
sudo apt install libsuitesparse-dev

- name: Build
run: |
set -xe
python -VV
pip install --upgrade pip
pip install pytest-memray
pip install -e '.[test,experimental]'

- name: Print versions
run: |
python -VV
python -c "import jax; print('jax==', jax.__version__)"
python -c "import jaxlib; print('jaxlib==', jaxlib.__version__)"
python -m pip install --upgrade pip
python -m pip install tox

- name: Run fast tests
if: ${{ matrix.test_mark == 'fast' }}
- name: Setup environment
run: |
python -m pytest --cov=ott --cov-append --cov-report=xml --cov-report=term-missing --cov-config=pyproject.toml --memray -m fast -n auto
tox -e py${{ matrix.python-version }} --notest -v

- name: Run all tests
if: ${{ matrix.test_mark == 'all' }}
- name: Run tests
run: |
python -m pytest --cov=ott --cov-append --cov-report=xml --cov-report=term-missing --cov-config=pyproject.toml --memray
tox -e py${{ matrix.python-version }} --skip-pkg-install
env:
PYTEST_ADDOPTS: --memray --durations 10 -vv

- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: tests-${{ matrix.test_mark }}
flags: tests-${{ matrix.os }}-${{ matrix.python-version }}
name: unittests
env_vars: OS,PYTHON
fail_ci_if_error: false
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ repos:
- id: yapf
additional_dependencies: [toml]
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.0
rev: 1.6.1
hooks:
- id: nbqa-pyupgrade
args: [--py38-plus]
- id: nbqa-black
- id: nbqa-isort
- repo: https://github.com/PyCQA/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/asottile/yesqa
Expand All @@ -33,7 +33,7 @@ repos:
- flake8-bugbear
- flake8-blind-except
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.5.0
rev: v2.6.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
Expand Down
61 changes: 33 additions & 28 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Contributing to OTT

We'd love to accept your contributions to this project.

There are many ways to contribute to OTT, with the most common ones being contribution of code, documentation
Expand All @@ -8,49 +7,55 @@ to the project, participating in discussions or raising issues.
## Contributing code or documentation
1. fork the repository using the **Fork** button on GitHub or the following
[link](https://github.com/ott-jax/ott/fork)
2. ```bash
2. ```shell
git clone https://github.com/<YOUR_USERNAME>/ott
cd ott
pip install -e .'[dev,test]'
pip install -e .'[dev]'
pre-commit install
```

When committing changes, sometimes you might want or need to bypass the pre-commit checks. This can be
done via the ``--no-verify`` flag as:
```bash
git commit --no-verify -m "The commit message"
```shell
git commit --no-verify -m "<SOME_COMMIT_MESSAGE>"
```

## Running tests
In order to run tests, you can:
```bash
pytest # run all tests
pytest -m fast # run only fast tests
pytest tests/core/sinkhorn_test.py # only test within a specific file
pytest -k "test_euclidean_point_cloud" # only tests which contain the expression
In order to run tests, we utilize [tox](https://tox.wiki/):
```shell
tox run # run linter and all tests on all available Python versions
tox run -- -n auto -m fast # run linter and fast tests in parallel
tox -e py38 # run all tests on Python3.8
tox -e py39 -- -k "test_euclidean_point_cloud" # run tests matching the expression on Python3.9
tox -e py310 -- --memray # test also memory on Python3.10
```
Alternatively, tests can be also run using the [pytest](https://docs.pytest.org/):
```shell
python -m pytest
```
This requires the ``'[test]'`` extra requirements to be installed as ``pip install -e.'[test]'``.

In order to run memory related tests (used for low-rank solvers/geometries and online point clouds), we utilize
[pytest-memray](https://github.com/bloomberg/pytest-memray) (current available only on Linux).
Whenever running the ``pytest`` commands mentioned above, the ``--memray`` option needs to be specified as well.

Lastly, to the run notebook regression tests, use ``pytest -m notebook``. Cell execution limit can be adjusted
using ``--notebook-cell-timeout=...`` (in seconds), Jupyter kernel name can be set using ``--kernel-name=...``.

## Building documentation
## Documentation
From the root of the repository, run:
```bash
pip install -e.'[docs]'
cd docs
make html # use `-j 4` to run using 4 jobs
<your favorite browser> _build/html/index.html
# run `make clean` to remove generated files
```shell
tox -e build-docs # build documentation
tox -e clean-docs # remove documentation
tox -e lint-docs # run spellchecker and linkchecker
```
Installing ``pyEnchant`` is required to run spellchecker, please refer to the
[installation instructions](https://pyenchant.github.io/pyenchant/install.html). On macOS Silicon, it may be necessary
to also set ``PYENCHANT_LIBRARY_PATH`` environment variable.

## Building the package
The package can be built using:
```shell
tox -e build-package
```
Afterwards, the built package will be located under ``dist/``.

## Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
All submissions, including submissions by project members, require review. We use GitHub
[pull requests](https://github.com/ott-jax/ott/pulls) for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more information on using pull requests.

# Community Guidelines
Expand Down
Loading