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

Use pyproject.toml with hatch #156

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

139 changes: 114 additions & 25 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: CI

on:
push:
Expand All @@ -10,34 +10,123 @@ on:
branches: [ master, dev, v0.7]

jobs:
build:
check:
name: ${{ matrix.env.name }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
env:
- {"name": "pkg", "target": "show"}
- {"name": "lint", "target": "run"}
# - {"name": "type", "target": "run"}
- {"name": "docs", "target": "all"}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Let us have colors
run: echo "FORCE_COLOR=true" >> "$GITHUB_ENV"
- name: Install Hatch
uses: pypa/hatch@install
- name: Setup ${{ matrix.env.name }}
run: |
hatch -v env create ${{ matrix.env.name }}
hatch run ${{ matrix.env.name }}:pip freeze
- name: Run ${{ matrix.env.name }}
run: hatch -v run ${{ matrix.env.name }}:${{ matrix.env.target }}

test:
name: test py${{ matrix.python-version }} - seaborn-${{ matrix.seaborn-version }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
# keep synchronized with hatch tests matrix
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
seaborn-version: ["0.11", "0.12", "0.13"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 coverage packaging
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with unittest
run: |
coverage run -m unittest discover tests
coverage report -m
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Pick environment to run
run: |
import codecs
import os
env = "tests.py{}-{}".format("${{ matrix.python-version }}", "${{ matrix.seaborn-version }}")
print(f"Environment {env}")
with codecs.open(os.environ["GITHUB_ENV"], mode="a", encoding="utf-8") as file_handler:
file_handler.write("FORCE_COLOR=1\n")
file_handler.write(f"ENV={env}\n")
shell: python
- name: Install Hatch
uses: pypa/hatch@install
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup test environment
run: |
hatch -v env create ${ENV}
hatch run ${ENV}:pip freeze
shell: bash
- name: Run test suite
run: hatch -v run ${ENV}:run-cov
env:
CI_RUN: "yes"
shell: bash
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}-${{ matrix.seaborn-version }}
path: "report/.coverage.*"

coverage:
name: coverage
runs-on: ubuntu-22.04
needs: test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Let us have colors
run: echo "FORCE_COLOR=true" >> "$GITHUB_ENV"
- name: Install Hatch
uses: pypa/hatch@install
- name: Setup coverage tool
run: |
hatch -v env create coverage
hatch run coverage:pip freeze
- name: Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: report
merge-multiple: true
- name: Combine and report coverage
run: hatch run coverage:run

- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report
path: report/html

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
with:
directory: report
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ statannot.egg-info/requires.txt
statannot.egg-info/SOURCES.txt
statannot.egg-info/top_level.txt

usage/figures/*
report/

# IDE files
.idea/
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
# - id: end-of-file-fixer
# - id: trailing-whitespace
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
hooks:
- id: validate-pyproject
# - repo: https://github.com/astral-sh/ruff-pre-commit
# rev: v0.5.5
# hooks:
# # Run the linter.
# - id: ruff
# args: [ --fix, --unsafe-fixes ]
# # Run the formatter.
# - id: ruff-format
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

1 change: 0 additions & 1 deletion coverage.sh

This file was deleted.

1 change: 1 addition & 0 deletions docs/source/_static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.gitignore
7 changes: 6 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx_rtd_theme']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx_rtd_theme',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
7 changes: 0 additions & 7 deletions docs/source/setup.rst

This file was deleted.

147 changes: 147 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# https://hatch.pypa.io/latest/config/environment/overview/
# ---------------------------------------------------------
[envs.default]
description = "Development environment"
installer = "uv pip install"

# ---------------------------------------------------------
[envs.pkg]
description = "package information"
[envs.pkg.scripts]
show = [
"uv pip list --format=columns",
'python -c "import sys; print(sys.version); print(sys.executable)"',
]


# ---------------------------------------------------------
[envs.lint]
template = "lint"
installer = "uv pip install"
description = "lint and format"
detached = true
dependencies = ["pre-commit"]

[envs.lint.scripts]
run = "pre-commit run --all-files"


# ---------------------------------------------------------
[envs.docs]
template = "docs"
installer = "uv pip install"
description = "build and check documentation"
features = ["docs"]

[envs.docs.scripts]
build = "sphinx-build -W --keep-going -b html docs/source docs/build"
doctest = "sphinx-build -W --keep-going -b doctest docs/source docs/build"
linkcheck = "sphinx-build -W --keep-going -b linkcheck docs/source docs/build"
all = ["build", "doctest", "linkcheck"]


# ---------------------------------------------------------
[envs.types]
template = "types"
installer = "uv pip install"
description = "Run the type checker"
dev-mode = false
dependencies = ["mypy"]

[envs.types.scripts]
run = [
"""
mypy --install-types --non-interactive --ignore-missing-imports \
--config-file={root}/pyproject.toml {args:statannotations tests}
""",
]


# ---------------------------------------------------------
[envs.tests]
template = "tests"
installer = "uv pip install"
description = "Run the tests suite"
features = ["tests"]
extra-dependencies = [
"matplotlib<3.9",
"seaborn=={matrix:seaborn_version}",
]

[[envs.tests.matrix]]
# python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
# seaborn_version = ["0.11", "0.12", "0.13"]
python = ["3.8", "3.9", "3.10", "3.11"]
seaborn_version = ["0.11"]

[envs.tests.overrides]
matrix.seaborn_version.extra-dependencies = [
"matplotlib<3.9",
"seaborn=={matrix:seaborn_version}",
{ value = "pandas<2", if = ["0.11", "0.12"]},
{ value = "numpy<2", if = ["0.11", "0.12"]},
]

[envs.tests.env-vars]
COVERAGE_FILE = "report/.coverage.{matrix:python}-{matrix:seaborn_version}"
COVERAGE_PROCESS_START = "pyproject.toml"
_COVERAGE_SRC = "statannotations"

[envs.tests.scripts]
run-cov = [
"""
pytest --cov=statannotations \
--cov-config=pyproject.toml --cov-context=test \
--cov-report=term-missing:skip-covered \
--cov-report html:report/html{matrix:python} \
--cov-report xml:report/coverage{matrix:python}.xml \
{args:-n auto --slow}
""",
]
run = "pytest {args:-n auto}"


# ---------------------------------------------------------
[envs.coverage]
template = "coverage"
installer = "uv pip install"
description = "combine coverage files"
detached = true
dependencies = [
"coverage[toml]>=7.3",
]
env-vars = { COVERAGE_FILE = "report/.coverage" }

[envs.coverage.scripts]
run = [
"- coverage combine --rcfile=pyproject.toml report",
"coverage report {args:--skip-covered --show-missing}",
"coverage xml -o report/coverage.xml",
"coverage html -d report/html",
]


# ---------------------------------------------------------
[envs.examples]
template = "examples"
installer = "uv pip install"
description = "Run the examples"
python = "3.11"
extra-dependencies = [
"matplotlib<3.9",
"seaborn=={matrix:seaborn_version}",
]

[[envs.examples.matrix]]
seaborn_version = ["0.11", "0.12", "0.13"]

[envs.examples.overrides]
matrix.seaborn_version.extra-dependencies = [
"matplotlib<3.9",
"seaborn=={matrix:seaborn_version}",
{ value = "pandas<2", if = ["0.11", "0.12"]},
{ value = "numpy<2", if = ["0.11", "0.12"]},
]

[envs.examples.scripts]
run = "- python usage/test_script.py {args}"
3 changes: 0 additions & 3 deletions make_doc.sh

This file was deleted.

Loading
Loading