Skip to content

Commit

Permalink
Merge pull request #16 from tbrlpld/pre-commit-tools-as-normal-depend…
Browse files Browse the repository at this point in the history
…encies

Pre commit tools as normal dependencies
  • Loading branch information
tbrlpld authored Feb 2, 2024
2 parents 05c356a + aa2aeee commit 90fb2c5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/scripts/report_nightly_build_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This reports an error to the #nightly-build-failures Slack channel.
"""

import os

import requests
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.11'
- name: Install
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev]
- uses: pre-commit/[email protected]

test:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11']
python: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand All @@ -44,7 +48,7 @@ jobs:
- name: Install
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[ci]
python -m pip install .[dev]
- name: Test
run: tox
- name: Upload coverage reports to Codecov
Expand Down
36 changes: 17 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,25 @@ repos:
args: ['--unsafe']
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
- repo: local
hooks:
- id: black
language_version: python3
args: ['--target-version', 'py38']
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
name: black
entry: black
language: system
types: [python]
- id: blacken-docs
additional_dependencies: [black==23.9.1]
- repo: https://github.com/pycqa/isort
# isort config is in setup.cfg
rev: 5.12.0
hooks:
name: blacken-docs
entry: blacken-docs
language: system
files: '\.(rst|md|markdown|py|tex)$'
- id: isort
- repo: https://github.com/pycqa/flake8
# flake8 config is in setup.cfg
rev: 6.1.0
hooks:
name: isort
entry: isort
language: system
types: [python]
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
name: flake8
entry: flake8
language: system
types: [python]
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ With your preferred virtualenv activated, install testing dependencies:

```sh
$ python -m pip install --upgrade pip>=21.3
$ python -m pip install -e '.[testing]' -U
$ python -m pip install -e '.[dev]' -U
```

#### Using flit
Expand Down Expand Up @@ -340,22 +340,41 @@ You can now visit `http://localhost:8020/`.

#### Testing with coverage

To run tests with coverage, use:
`tox` is configured to run tests with coverage.
The coverage report is combined for all environments.
This is done by using the `--append` flag when running coverage in `tox`.
This means it will also include previous results.

You can see the coverage report by running:

```sh
$ coverage run ./testmanage.py test
$ coverage report
```

Then see the results with
To get a clean report, you can run `coverage erase` before running `tox`.

#### Running tests without tox

If you want to run tests without `tox`, you can use the `testmanage.py` script.
This script is a wrapper around Django's `manage.py` and will run tests with the correct settings.

To make this work, you need to have the `testing` dependencies installed.

```sh
$ coverage report
$ python -m pip install -e '.[testing]' -U
```

When the tests are run with `tox`, the coverage report is combined for all environments.
This is done by using the `--append` flag when running coverage in `tox`.
This means it will also include previous results.
To get a clean report, you can run `coverage erase` before running `tox`.
Then you can run tests with:

```sh
$ ./testmanage.py test
````

To run tests with coverage, use:

```sh
$ coverage run ./testmanage.py test
```

### Python version management

Expand Down
1 change: 1 addition & 0 deletions laces/test/example/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This is unlikely to be an exhaustive list of examples, but it should be enough to
demonstrate the basic concepts of how components work.
"""

from dataclasses import asdict, dataclass

from django.utils.html import format_html
Expand Down
1 change: 1 addition & 0 deletions laces/test/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
These tests are very basic and only ensure that the examples are configured as
desired. More thorough tests can be found in the `laces.tests.test_components` module.
"""

from django.test import SimpleTestCase

from laces.test.example.components import (
Expand Down
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,26 @@ dependencies = [
[project.optional-dependencies]
testing = [
"dj-database-url==2.1.0",
"pre-commit==3.4.0",
# Running tests with coverage inside the tox test environment.
"coverage==7.3.4",
]
ci = [
dev = [
"tox==4.12.1",
"tox-gh-actions==3.2.0",
# Allow use of pyenv for virtual environments. To enable you need to set `VIRTUALENV_DISCOVERY=pyenv` in the shell.
# This is useful to help tox find the correct python version when using pyenv.
"virtualenv-pyenv==0.4.0"
"virtualenv-pyenv==0.4.0",
# This is to have coverage available in the development environment.
# It's not great that it's duplicated, but I can't find a way to make it work with tox otherwise.
"coverage==7.3.4",
# Linting etc.
"pre-commit==3.4.0",
"black==24.1.1",
"blacken-docs==1.16.0",
"isort==5.13.2",
"flake8==7.0.0",
"flake8-bugbear",
"flake8-comprehensions",
]

[project.urls]
Expand Down

0 comments on commit 90fb2c5

Please sign in to comment.