Repository: Ultraplot/ultraplot
Pull request #121: feat: enable test coverage with codecov
Author: login: beckermr
Created: 2025-03-07T19:41:35Z | Merged: 2025-03-08T09:02:19Z

This PR enables test coverage measurements with codecov.


Diff:
diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml
index b3ae53dd3..8288aeca6 100644
--- a/.github/workflows/build-ultraplot.yml
+++ b/.github/workflows/build-ultraplot.yml
@@ -18,6 +18,9 @@ jobs:
     name: Test Python ${{ inputs.python-version }} with ${{ inputs.matplotlib-version }}
     runs-on: ubuntu-latest
     timeout-minutes: 15
+    defaults:
+      run: 
+        shell: bash -el {0}
     steps:
       - uses: actions/checkout@v4
         with:
@@ -35,22 +38,28 @@ jobs:
           cache-downloads: false
 
       - name: Build Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pip install .
+          pip install --no-build-isolation --no-deps .
 
       - name: Test Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pytest
+          pytest --cov=ultraplot --cov-branch --cov-report term-missing --cov-report=xml ultraplot
 
+      - name: Upload coverage reports to Codecov
+        uses: codecov/codecov-action@v5
+        with:
+          token: ${{ secrets.CODECOV_TOKEN }}
+          slug: Ultraplot/ultraplot
+  
   compare-baseline:
     needs: build-ultraplot
     runs-on: ubuntu-latest
+    defaults:
+      run: 
+        shell: bash -el {0}    
     steps:
       - uses: actions/checkout@v4
+
       - uses: mamba-org/setup-micromamba@v2.0.4
         with:
           environment-file: ./environment.yml
@@ -63,11 +72,8 @@ jobs:
           cache-downloads: false
 
       - name: Generate baseline from main
-        shell: bash -el {0}
         run: |
-          cd $GITHUB_WORKSPACE
           mkdir -p baseline
-          micromamba activate ultraplot-dev
           git fetch origin ${{ github.event.pull_request.base.sha }}
           git checkout ${{ github.event.pull_request.base.sha }}
           python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
@@ -75,10 +81,7 @@ jobs:
           git checkout ${{ github.sha }}  # Return to PR branch
 
       - name: Image Comparison Ultraplot
-        shell: bash -el {0}
         run: |
-          cd $GITHUB_WORKSPACE
-          micromamba activate ultraplot-dev
           mkdir -p results
           python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
           pytest --mpl --mpl-baseline-path=baseline --mpl-generate-summary=html --mpl-results-path=./results/ --mpl-default-style="./ultraplot.yml" --store-failed-only ultraplot/tests
@@ -88,5 +91,5 @@ jobs:
         if: always()
         uses: actions/upload-artifact@v4
         with:
-          name: failed-comparisons-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}
+          name: failed-comparisons-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-${{ github.sha }}
           path: results/*
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 6386bbb75..9167d5f80 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -13,7 +13,7 @@ jobs:
   run-if-changes:
     runs-on: ubuntu-latest
     outputs:
-      run: ${{ steps.filter.outputs.python }}
+      run: ${{ (github.event_name == 'push' && github.ref_name == 'main') && 'true' || steps.filter.outputs.python }}
     steps:
       - uses: actions/checkout@v4
       - uses: dorny/paths-filter@v3
diff --git a/README.rst b/README.rst
index 08c9c4869..7b80d2aee 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,7 @@
     :alt: UltraPlot Logo
     :width: 100%
 
-|build-status| |docs| |pypi| |code-style| |pre-commit| |pr-welcome| |license|
+|build-status| |coverage| |docs| |pypi| |code-style| |pre-commit| |pr-welcome| |license|
 
 A succinct `matplotlib <https://matplotlib.org/>`__ wrapper for making beautiful,
 publication-quality graphics. It builds upon ProPlot_ and transports it into the modern age (supporting mpl 3.9.0+).
@@ -68,3 +68,7 @@ inside the ``ultraplot`` folder.
 .. |pre-commit| image:: https://results.pre-commit.ci/badge/github/Ultraplot/ultraplot/main.svg
    :target: https://results.pre-commit.ci/latest/github/Ultraplot/ultraplot/main
    :alt: pre-commit.ci status
+
+.. |coverage| image:: https://codecov.io/gh/Ultraplot/ultraplot/graph/badge.svg?token=C6ZB7Q9II4 
+   :target: https://codecov.io/gh/Ultraplot/ultraplot
+   :alt: coverage
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 000000000..202435d6b
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,32 @@
+codecov:
+  notify:
+    require_ci_to_pass: no
+
+coverage:
+  status:
+    patch:
+      default:
+        target: 80.0%
+        if_no_uploads: error
+        if_not_found: success
+        if_ci_failed: failure
+
+    project:
+      default: false
+      library:
+        target: auto
+        threshold: 0.5%
+        if_no_uploads: error
+        if_not_found: success
+        if_ci_failed: failure
+        paths:
+          - "!logo/*"
+          - "!docs/*"
+          - "!ultraplot/tests/*"
+
+      tests:
+        target: 95.0%
+        paths:
+          - "ultraplot/tests/*"
+          - "!logo/*"
+          - "!docs/*"
diff --git a/environment.yml b/environment.yml
index 3fe4a8c28..214a9e873 100644
--- a/environment.yml
+++ b/environment.yml
@@ -11,6 +11,7 @@ dependencies:
   - pandas
   - pytest
   - pytest-mpl
+  - pytest-cov
   - jupyter
   - pip
   - pint


Reviews:
user: login: beckermr
body: debug a bit.
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-07T20:17:13Z
user: login: beckermr
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-07T20:25:02Z
user: login: beckermr
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-07T20:36:57Z
user: login: beckermr
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-07T20:43:19Z
user: login: cvanelteren
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-08T09:01:58Z

Review comments:
diff_hunk: @@ -35,22 +38,27 @@ jobs:
           cache-downloads: false
 
       - name: Build Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pip install .
+          pip install --no-build-isolation --no-deps .
 
       - name: Test Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pytest
+          pytest --cov-branch --cov-report=xml
 
+      - name: Upload coverage reports to Codecov
+        uses: codecov/codecov-action@v5
+        with:
+          token: ${{ secrets.CODECOV_TOKEN }}
path: .github/workflows/build-ultraplot.yml
user: login: beckermr
body: ```suggestion
          token: ${{ secrets.CODECOV_TOKEN }}
          slug: Ultraplot/ultraplot
```
created_at: 2025-03-07T20:16:47Z
author_association: COLLABORATOR
diff_hunk: @@ -35,22 +38,27 @@ jobs:
           cache-downloads: false
 
       - name: Build Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pip install .
+          pip install --no-build-isolation --no-deps .
 
       - name: Test Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pytest
+          pytest --cov-branch --cov-report=xml
path: .github/workflows/build-ultraplot.yml
user: login: beckermr
body: ```suggestion
          pytest --cov-branch --cov-report=xml
          ls -lah
```
created_at: 2025-03-07T20:17:04Z
author_association: COLLABORATOR
diff_hunk: @@ -35,22 +38,29 @@ jobs:
           cache-downloads: false
 
       - name: Build Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pip install .
+          pip install --no-build-isolation --no-deps .
 
       - name: Test Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pytest
+          pytest --cov-branch --cov-report=xml
path: .github/workflows/build-ultraplot.yml
user: login: beckermr
body: ```suggestion
          pytest --cov=ultraplot --cov-branch --cov-report term-missing --cov-report=xml ultraplot
```
created_at: 2025-03-07T20:25:01Z
author_association: COLLABORATOR
diff_hunk: @@ -35,22 +38,29 @@ jobs:
           cache-downloads: false
 
       - name: Build Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pip install .
+          pip install --no-build-isolation --no-deps .
 
       - name: Test Ultraplot
-        shell: bash -el {0}
         run: |
-          micromamba activate ultraplot-dev
-          pytest
+          pytest --cov=ultraplot --cov-branch --cov-report term-missing --cov-report=xml ultraplot
+          ls -lah
path: .github/workflows/build-ultraplot.yml
user: login: beckermr
body: ```suggestion
```
created_at: 2025-03-07T20:36:57Z
author_association: COLLABORATOR
diff_hunk: @@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 """
-A succinct matplotlib wrapper for making beautiful, publication-quality graphics.
+A succinct matplotlib wrapper for making beautiful, publication-quality graphics. Woo!
path: ultraplot/__init__.py
user: login: beckermr
body: ```suggestion
A succinct matplotlib wrapper for making beautiful, publication-quality graphics.
```
created_at: 2025-03-07T20:43:19Z
author_association: COLLABORATOR

PR comments:
user: login: codecov[bot]
created_at: 2025-03-07T20:33:34Z
body: ## Welcome to [Codecov](https://codecov.io?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ultraplot) :tada:

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

:information_source: You can also turn on [project coverage checks](https://docs.codecov.com/docs/common-recipe-list#set-project-coverage-checks-on-a-pull-request) and [project coverage reporting on Pull Request comment](https://docs.codecov.com/docs/common-recipe-list#show-project-coverage-changes-on-the-pull-request-comment)

Thanks for integrating Codecov - We've got you covered :open_umbrella:
author_association: NONE
user: login: beckermr
created_at: 2025-03-07T20:49:05Z
body: Once we merge to main and the coverage gets uploaded there, we will get coverage diffs on each PR.
author_association: COLLABORATOR
user: login: cvanelteren
created_at: 2025-03-08T09:02:21Z
body: Great thanks!
author_association: COLLABORATOR