From 6629c969ab0daf346fc1619f15247274aeb226a3 Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 19:57:18 -0800 Subject: [PATCH 1/8] Rename ci dependency section to dev and add coverage into it This is to make sure that coverage is available in the dev environment to be able to do things like show the coverage report or erase the coverage database. The nameing change is to better reflect the usage. --- .github/workflows/test.yml | 4 ++-- README.md | 37 ++++++++++++++++++++++++++++--------- pyproject.toml | 11 ++++++++--- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 171e865..fc7b616 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: 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 @@ -44,7 +44,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 diff --git a/README.md b/README.md index db24ffa..405953d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index f9cf8c2..40357f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,15 +35,20 @@ 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", ] [project.urls] From 97597a974d857b7af5f4f78e1032cb3d5339a5a5 Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:01:34 -0800 Subject: [PATCH 2/8] Replace black hook with local version --- .pre-commit-config.yaml | 10 ++++++---- pyproject.toml | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9d4c77..16eb58e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,12 +18,14 @@ 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'] + name: black + entry: black + language: system + types: [python] + files: \.(py)$ - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 40357f5..744c6cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ dev = [ "coverage==7.3.4", # Linting etc. "pre-commit==3.4.0", + "black==24.1.1", ] [project.urls] From f9371d866146b97d3bfeafe09fd98e7a9949751a Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:07:28 -0800 Subject: [PATCH 3/8] Use local isort --- .pre-commit-config.yaml | 11 ++++++----- pyproject.toml | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 16eb58e..9c0398f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,16 +26,17 @@ repos: language: system types: [python] files: \.(py)$ + - id: isort + name: isort + entry: isort + language: system + types: [python] + files: \.(py)$ - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: - 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: - - id: isort - repo: https://github.com/pycqa/flake8 # flake8 config is in setup.cfg rev: 6.1.0 diff --git a/pyproject.toml b/pyproject.toml index 744c6cc..4b655c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ dev = [ # Linting etc. "pre-commit==3.4.0", "black==24.1.1", + "isort==5.13.2", ] [project.urls] From ee6f8e321fe221532adf4f2707e6b66a37f392e1 Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:14:31 -0800 Subject: [PATCH 4/8] Use local flake8 --- .pre-commit-config.yaml | 14 ++++++-------- pyproject.toml | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c0398f..90c2a49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,16 +32,14 @@ repos: language: system types: [python] files: \.(py)$ + - id: flake8 + name: flake8 + entry: flake8 + language: system + types: [python] + files: \.(py)$ - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: - id: blacken-docs additional_dependencies: [black==23.9.1] - - repo: https://github.com/pycqa/flake8 - # flake8 config is in setup.cfg - rev: 6.1.0 - hooks: - - id: flake8 - additional_dependencies: - - flake8-bugbear - - flake8-comprehensions diff --git a/pyproject.toml b/pyproject.toml index 4b655c8..ed3df36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,9 @@ dev = [ "pre-commit==3.4.0", "black==24.1.1", "isort==5.13.2", + "flake8==7.0.0", + "flake8-bugbear", + "flake8-comprehensions", ] [project.urls] From e39abffe3874acbb5cd4bed5203474c4e0ebb4e3 Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:26:51 -0800 Subject: [PATCH 5/8] Remove unnecessary file extension patterns The types should be enough and leave the file identification to the identity library. --- .pre-commit-config.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90c2a49..8edc32e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,19 +25,16 @@ repos: entry: black language: system types: [python] - files: \.(py)$ - id: isort name: isort entry: isort language: system types: [python] - files: \.(py)$ - id: flake8 name: flake8 entry: flake8 language: system types: [python] - files: \.(py)$ - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: From 183fcfbf7e6e2bf9418ea6e9ac97aa1791a3a84c Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:35:25 -0800 Subject: [PATCH 6/8] Use local hook for blacken-docs --- .pre-commit-config.yaml | 10 +++++----- pyproject.toml | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8edc32e..95eefcb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,11 @@ repos: entry: black language: system types: [python] + - id: blacken-docs + name: blacken-docs + entry: blacken-docs + language: system + files: '\.(rst|md|markdown|py|tex)$' - id: isort name: isort entry: isort @@ -35,8 +40,3 @@ repos: entry: flake8 language: system types: [python] - - repo: https://github.com/adamchainz/blacken-docs - rev: 1.16.0 - hooks: - - id: blacken-docs - additional_dependencies: [black==23.9.1] diff --git a/pyproject.toml b/pyproject.toml index ed3df36..8299329 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ dev = [ # 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", From eae630f7e5d1318e5c7889f25b1b70e1a11c09bc Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:36:04 -0800 Subject: [PATCH 7/8] Run pre-commit against all files --- .github/scripts/report_nightly_build_failure.py | 1 + laces/test/example/components.py | 1 + laces/test/tests/test_components.py | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/scripts/report_nightly_build_failure.py b/.github/scripts/report_nightly_build_failure.py index 8cf12f7..a04db4b 100644 --- a/.github/scripts/report_nightly_build_failure.py +++ b/.github/scripts/report_nightly_build_failure.py @@ -3,6 +3,7 @@ This reports an error to the #nightly-build-failures Slack channel. """ + import os import requests diff --git a/laces/test/example/components.py b/laces/test/example/components.py index 43ea303..53f63b8 100644 --- a/laces/test/example/components.py +++ b/laces/test/example/components.py @@ -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 diff --git a/laces/test/tests/test_components.py b/laces/test/tests/test_components.py index ccb041b..0530334 100644 --- a/laces/test/tests/test_components.py +++ b/laces/test/tests/test_components.py @@ -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 ( From aa2aeeef7ac6db0b9007cd204732b50fae76a682 Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 1 Feb 2024 20:45:35 -0800 Subject: [PATCH 8/8] Update CI installation instructions --- .github/workflows/test.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc7b616..bffdc59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,10 +22,14 @@ 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/action@v3.0.0 test: