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

Splits tox into multiple jobs #250

Merged
merged 5 commits into from
Oct 18, 2024
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
29 changes: 26 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
- main

jobs:
tox:
tox_tests:
if: ${{ !github.event.pull_request.draft }}
strategy:
matrix:
Expand All @@ -38,7 +38,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
pip install tox

- name: Run tox
Expand All @@ -49,6 +48,27 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

tox_check:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4 # Use v4 for compatibility with pyproject.toml
with:
python-version: 3.12
cache: pip

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

- name: Run tox
run: tox -e check

prevent_docs_absolute_links:
runs-on: ubuntu-latest
steps:
Expand All @@ -63,7 +83,10 @@ jobs:

check:
if: ${{ !github.event.pull_request.draft }}
needs: tox
needs:
- tox_tests
- prevent_docs_absolute_links
- tox_check
runs-on: ubuntu-latest
steps:
- name: Decide whether all tests and notebooks succeeded
Expand Down
26 changes: 17 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ See below for details on how to [add tests](#adding-tests) and properly [documen

Lastly, you should make sure that the existing tests all run successfully and that the codebase is formatted properly:

> [!TIP]
> The [NeMoS GitHub action](.github/workflows/ci.yml) runs tests and some additional style checks in an isolated environment using [`tox`](https://tox.wiki/en/). `tox` is not included in our optional dependencies, so if you want to replicate the action workflow locally, you need to install `tox` via pip and then run it. From the package directory:
> ```sh
> pip install tox
> tox -e check,py
> ```
> This will execute `tox` with a Python version that matches your local environment. If the above passes, then the Github action will pass and your PR is mergeable
>
> You can also use `tox` to use `black` and `isort` to try and fix your code if either of those are failing. To do so, run `tox -e fix`
>
> `tox` configurations can be found in the [`tox.ini`](tox.ini) file.


```bash
# run tests and make sure they all pass
pytest tests/
Expand All @@ -105,7 +118,10 @@ pytest --doctest-modules src/nemos/

# format the code base
black src/
isort src
isort src --profile=black
isort docs/how_to_guide --profile=black
isort docs/background --profile=black
isort docs/tutorials --profile=black
flake8 --config=tox.ini src
```

Expand All @@ -129,14 +145,6 @@ changes.

Additionally, every PR to `main` or `development` will automatically run linters and tests through a [GitHub action](https://docs.github.com/en/actions). Merges can happen only when all check passes.

> [!NOTE]
> The [NeMoS GitHub action](.github/workflows/ci.yml) runs tests in an isolated environment using [`tox`](https://tox.wiki/en/). `tox` is not included in our optional dependencies, so if you want to replicate the action workflow locally, you need to install `tox` via pip and then run it. From the package directory:
> ```sh
> pip install tox
> tox -e py
> ```
> This will execute `tox` with a Python version that matches your local environment. `tox` configurations can be found in the [`tox.ini`](tox.ini) file.

Once your changes are integrated, you will be added as a GitHub contributor and as one of the authors of the package. Thank you for being part of `nemos`!

### Style Guide
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dev = [
"isort", # Import sorter
"pip-tools", # Dependency management
"pytest", # Testing framework
"pytest-xdist", # Parallelize pytest
"flake8", # Code linter
"coverage", # Test coverage measurement
"pytest-cov", # Test coverage plugin for pytest
Expand Down Expand Up @@ -112,6 +113,7 @@ profile = "black"
# Configure pytest
[tool.pytest.ini_options]
testpaths = ["tests"] # Specify the directory where test files are located
addopts = "-n auto"

[tool.coverage.run]
omit = [
Expand Down
21 changes: 15 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = True
envlist = py310, py311, py312
envlist = py,fix


[testenv]
Expand All @@ -12,17 +12,26 @@ extras = dev
package_cache = .tox/cache

# Run both pytest and coverage since pytest was initialized with the --cov option in the pyproject.toml
# while black, isort and flake8 are also i
commands =
black --check src
pytest --doctest-modules src/nemos/
pytest --cov=nemos --cov-config=pyproject.toml --cov-report=xml

[testenv:fix]
commands=
black src
isort src --profile=black
isort docs/how_to_guide --profile=black
isort docs/background --profile=black
isort docs/tutorials --profile=black
flake8 --config={toxinidir}/tox.ini src
pytest --doctest-modules src/nemos/
pytest --cov=nemos --cov-config=pyproject.toml --cov-report=xml

[testenv:check]
commands=
black --check src
isort --check src --profile=black
isort --check docs/how_to_guide --profile=black
isort --check docs/background --profile=black
isort --check docs/tutorials --profile=black
flake8 --config={toxinidir}/tox.ini src

[gh-actions]
python =
Expand Down
Loading