Skip to content

Commit

Permalink
pyproject.toml, ruff, Python 3.10, update CI (#11)
Browse files Browse the repository at this point in the history
* pyproject.toml, ruff, Python 3.10, update CI

* Fix definition of Python version in tests

* Fix ruff errors

* Remove internal test

* Add audmetric to depednencies

* Fix linkcheck on PyPI
  • Loading branch information
hagenw authored Aug 19, 2024
1 parent ff7eb5a commit e88e04f
Show file tree
Hide file tree
Showing 21 changed files with 593 additions and 605 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Linter

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install pre-commit hooks
run: |
pip install pre-commit
pre-commit install --install-hooks
- name: Code style check via pre-commit
run: |
pre-commit run --all-files
50 changes: 28 additions & 22 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish
name: Publish Python Package

on:
push:
Expand All @@ -8,31 +8,36 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install build virtualenv
# PyPI package
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
python -m twine upload dist/*
- name: Build Python package
run: python -m build

# Docuemntation
- name: Publish Python package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

# Documentation
- name: Install doc dependencies
run: |
pip install -r requirements.txt
Expand All @@ -43,7 +48,7 @@ jobs:
python -m sphinx docs/ docs/_build/ -b html
- name: Deploy documentation to Github pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build
Expand All @@ -54,20 +59,21 @@ jobs:
run: |
# Get bullet points from last CHANGELOG entry
CHANGELOG=$(git diff -U0 HEAD^ HEAD | grep '^[+][\* ]' | sed 's/\+//')
# Support for multiline, see
# https://github.com/actions/create-release/pull/11#issuecomment-640071918
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "Got changelog: $CHANGELOG"
echo "::set-output name=body::$CHANGELOG"
# Support for multiline, see
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
{
echo 'body<<EOF'
echo "$CHANGELOG"
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Create release on Github
id: create_release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
name: Release ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.body }}
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macOS-latest, windows-latest ]
python-version: [ 3.8 ]
python-version: [ "3.10" ]
tasks: [ tests ]
include:
- os: ubuntu-latest
python-version: 3.9
python-version: "3.8"
tasks: tests
- os: ubuntu-latest
python-version: 3.8
python-version: "3.9"
tasks: tests
- os: ubuntu-latest
python-version: "3.10"
tasks: docs

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -45,7 +48,7 @@ jobs:
if: matrix.tasks == 'tests'

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Configuration of checks run by pre-commit
#
# The tests are executed in the CI pipeline,
# see CONTRIBUTING.rst for further instructions.
# You can also run the checks directly at the terminal, e.g.
#
# $ pre-commit install
# $ pre-commit run --all-files
#
#
default_language_version:
python: python3.10

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies:
- tomli
123 changes: 79 additions & 44 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,83 +1,118 @@
Contributing
============

If you would like to add new functionality fell free to create a `pull
request`_ . If you find errors, omissions, inconsistencies or other things
that need improvement, please create an issue_.
Contributions are always welcome!
Everyone is invited to contribute to this project.
Feel free to create a `pull request`_ .
If you find errors,
omissions,
inconsistencies,
or other things
that need improvement,
please create an issue_.

.. _issue: https://github.com/audeering/audpsychometric/issues/new/
.. _pull request: https://github.com/audeering/audpsychometric/compare/

.. _issue:
https://github.com/audeering/audpsychometric/issues/new/
.. _pull request:
https://github.com/audeering/audpsychometric/compare/

Development Installation
------------------------

Instead of pip-installing the latest release from PyPI, you should get the
newest development version from Github_::
Instead of pip-installing the latest release from PyPI_,
you should get the newest development version from Github_::

git clone https://github.com/audeering/audpsychometric/
cd audpsychometric
# Create virtual environment for this project
# e.g.
# virtualenv --python="python3" $HOME/.envs/audpsychometric
# source $HOME/.envs/audpsychometric/bin/activate
pip install -r requirements.txt


git clone https://github.com/audeering/audpsychometric/
cd audpsychometric
# Use virtual environment
pip install -r requirements.txt
This way,
your installation always stays up-to-date,
even if you pull new changes from the Github repository.

.. _PyPI: https://pypi.org/project/audpsychometric/
.. _Github: https://github.com/audeering/audpsychometric/

This way, your installation always stays up-to-date,
even if you pull new changes
from the repository.

Building the Documentation
--------------------------
Coding Convention
-----------------

If you make changes to the documentation, you can re-create the HTML pages
using Sphinx_.
You can install it and a few other necessary packages with::
We follow the PEP8_ convention for Python code
and use ruff_ as a linter and code formatter.
In addition,
we check for common spelling errors with codespell_.
Both tools and possible exceptions
are defined in :file:`pyproject.toml`.

pip install -r requirements.txt
pip install -r docs/requirements.txt
The checks are executed in the CI using `pre-commit`_.
You can enable those checks locally by executing::

To create the HTML pages, use::
pip install pre-commit # consider system wide installation
pre-commit install
pre-commit run --all-files

Afterwards ruff_ and codespell_ are executed
every time you create a commit.

python -m sphinx docs/ build/sphinx/html -b html
You can also install ruff_ and codespell_
and call it directly::

The generated files will be available in the directory ``build/sphinx/html/``.
pip install ruff codespell # consider system wide installation
ruff check --fix . # lint all Python files, and fix any fixable errors
ruff format . # format code of all Python files
codespell

.. Note::
It can be restricted to specific folders::

During the default building of the documentation
Jupyter notebooks are not executed to save time.
ruff check audfoo/ tests/
codespell audfoo/ tests/

To execute the notebooks as well, copy and paste
the following into your terminal and press the enter key::

python -m sphinx -W docs/ \
-D nbsphinx_execute='always' \
-d build/sphinx/doctrees \
build/sphinx/html \
-b html
.. _codespell: https://github.com/codespell-project/codespell/
.. _PEP8: http://www.python.org/dev/peps/pep-0008/
.. _pre-commit: https://pre-commit.com
.. _ruff: https://beta.ruff.rs


Building the Documentation
--------------------------

If you make changes to the documentation,
you can re-create the HTML pages using Sphinx_.
You can install it and a few other necessary packages with::

pip install -r docs/requirements.txt

To create the HTML pages, use::

python -m sphinx docs/ build/sphinx/html -b html

The generated files will be available
in the directory :file:`build/sphinx/html/`.

It is also possible to automatically check if all links are still valid::

python -m sphinx docs/ build/sphinx/linkcheck -b linkcheck
python -m sphinx docs/ build/sphinx/html -b linkcheck

.. _Sphinx: http://sphinx-doc.org

.. _Sphinx: http://sphinx-doc.org/

Running the Tests
-----------------

You'll need pytest_ for that.
It can be installed with::

pip install -r tests/requirements.txt
pip install -r tests/requirements.txt

To execute the tests, simply run::

python -m pytest
python -m pytest

.. _pytest:
https://pytest.org/
.. _pytest: https://pytest.org


Creating a New Release
Expand All @@ -87,5 +122,5 @@ New releases are made using the following steps:

#. Update ``CHANGELOG.rst``
#. Commit those changes as "Release X.Y.Z"
#. Create an (annotated) tag with ``git tag -a vX.Y.Z``
#. Create an (annotated) tag with ``git tag -a X.Y.Z``
#. Push the commit and the tag to Github
29 changes: 12 additions & 17 deletions audpsychometric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@
"""
import audpsychometric.core
import audpsychometric.core.reliability
from audpsychometric.core import datasets
from audpsychometric.core.gold_standard import (
evaluator_weighted_estimator,
rater_confidence_pearson,
gold_standard_mean,
gold_standard_median,
gold_standard_mode,
)
from audpsychometric.core.reliability import (
congeneric_reliability,
cronbachs_alpha,
intra_class_correlation
)

from audpsychometric.core.datasets import (
list_datasets,
read_dataset)
from audpsychometric.core.datasets import list_datasets
from audpsychometric.core.datasets import read_dataset
from audpsychometric.core.gold_standard import evaluator_weighted_estimator
from audpsychometric.core.gold_standard import gold_standard_mean
from audpsychometric.core.gold_standard import gold_standard_median
from audpsychometric.core.gold_standard import gold_standard_mode
from audpsychometric.core.gold_standard import rater_confidence_pearson
import audpsychometric.core.reliability
from audpsychometric.core.reliability import congeneric_reliability
from audpsychometric.core.reliability import cronbachs_alpha
from audpsychometric.core.reliability import intra_class_correlation


# Disencourage from audpsychometric import *
__all__ = []
Expand Down
3 changes: 0 additions & 3 deletions audpsychometric/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
"""
The core module
"""
Loading

0 comments on commit e88e04f

Please sign in to comment.