Skip to content

Commit

Permalink
Switch project to use pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Oct 11, 2023
1 parent 3b30940 commit 77e2d52
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 113 deletions.
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
exclude =
.eggs,
build,
extend-ignore =
# math, https://github.com/PyCQA/pycodestyle/issues/513
W503,
per-file-ignores =
# ignore unused imports
__init__.py: F401
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Flake8
name: Linter

on:
push:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install build twine 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 build
python -m twine upload dist/*
# Docuemntation
# Documentation
- name: Install doc dependencies
run: |
pip install -r requirements.txt
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "Got changelog: $CHANGELOG"
echo "::set-output name=body::$CHANGELOG"
echo "body=$CHANGELOG" >> $GITHUB_OUTPUT
- name: Create release on Github
id: create_release
Expand Down
16 changes: 13 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
# $ pre-commit install
# $ pre-commit run --all-files
#
#
default_language_version:
python: python3.8

repos:
- repo: https://github.com/pycqa/flake8
rev: '5.0.4'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.276
hooks:
- id: ruff
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: flake8
- id: codespell
additional_dependencies:
- tomli
70 changes: 41 additions & 29 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ Contributing

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_.
If you find errors,
omissions,
inconsistencies,
or other things
that need improvement,
please create an issue_.

.. _issue: https://github.com/audeering/audplot/issues/new/
.. _pull request: https://github.com/audeering/audplot/compare/
Expand All @@ -13,30 +17,35 @@ that need improvement, please create an issue_.
Development Installation
------------------------

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

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

.. _Github: https://github.com/audeering/audplot

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

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


Coding Convention
-----------------

We follow the PEP8_ convention for Python code
and check for correct syntax with flake8_.
Exceptions are defined under the ``[flake8]`` section
in :file:`setup.cfg`.
and check for correct syntax with ruff_.
In addition,
we check for common spelling errors with codespell_.
Both tools and possible exceptions
are defined in :file:`pyproject.toml`.

The checks are executed in the CI using `pre-commit`_.
You can enable those checks locally by executing::
Expand All @@ -45,22 +54,26 @@ You can enable those checks locally by executing::
pre-commit install
pre-commit run --all-files

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

You can also install flake8_
You can also install ruff_ and codespell_
and call it directly::

pip install flake8 # consider system wide installation
flake8
pip install ruff codespell # consider system wide installation
ruff check .
codespell

It can be restricted to specific folders::

flake8 audfoo/ tests/
ruff check audfoo/ tests/
codespell audfoo/ tests/


.. _codespell: https://github.com/codespell-project/codespell/
.. _PEP8: http://www.python.org/dev/peps/pep-0008/
.. _flake8: https://flake8.pycqa.org/en/latest/index.html
.. _pre-commit: https://pre-commit.com
.. _ruff: https://beta.ruff.rs


Building the Documentation
Expand All @@ -70,21 +83,20 @@ 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 requirements.txt
pip install -r docs/requirements.txt
pip install -r docs/requirements.txt

To create the HTML pages, use::

python -m sphinx docs/ build/sphinx/html -b html
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
Expand All @@ -93,13 +105,13 @@ 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 Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ and machine learning problems (e.g. confusion matrix).
.. |tests| image:: https://github.com/audeering/audplot/workflows/Test/badge.svg
:target: https://github.com/audeering/audplot/actions?query=workflow%3ATest
:alt: Test status
.. |coverage| image:: https://codecov.io/gh/audeering/audplot/branch/master/graph/badge.svg?token=t5c5Ky64Ch
.. |coverage| image:: https://codecov.io/gh/audeering/audplot/branch/main/graph/badge.svg?token=t5c5Ky64Ch
:target: https://codecov.io/gh/audeering/audplot/
:alt: code coverage
.. |docs| image:: https://img.shields.io/pypi/v/audplot?label=docs
:target: https://audeering.github.io/audplot/
:alt: audplot's documentation
.. |license| image:: https://img.shields.io/badge/license-MIT-green.svg
:target: https://github.com/audeering/audplot/blob/master/LICENSE
:target: https://github.com/audeering/audplot/blob/main/LICENSE
:alt: audplot's MIT license
.. |python-versions| image:: https://img.shields.io/pypi/pyversions/audplot.svg
:target: https://pypi.org/project/audplot/
Expand Down
22 changes: 10 additions & 12 deletions audplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from audplot.core.api import (
cepstrum,
confusion_matrix,
detection_error_tradeoff,
distribution,
human_format,
scatter,
series,
signal,
spectrum,
waveform,
)
from audplot.core.api import cepstrum
from audplot.core.api import confusion_matrix
from audplot.core.api import detection_error_tradeoff
from audplot.core.api import distribution
from audplot.core.api import human_format
from audplot.core.api import scatter
from audplot.core.api import series
from audplot.core.api import signal
from audplot.core.api import spectrum
from audplot.core.api import waveform


# Disencourage from audfoo import *
Expand Down
2 changes: 1 addition & 1 deletion audplot/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pandas as pd
import seaborn as sns


# The scipy implementation is faster,
# but scipy is not an official dependency of audplot
try:
Expand Down Expand Up @@ -59,7 +60,6 @@ def cepstrum(
>>> plt.tight_layout()
"""

ax = ax or plt.gca()
cc_matrix = cc_matrix[channel] if cc_matrix.ndim == 3 else cc_matrix

Expand Down
Loading

0 comments on commit 77e2d52

Please sign in to comment.