Skip to content

Commit

Permalink
Switch project to use pyproject.toml (#60)
Browse files Browse the repository at this point in the history
* Switch project to use pyproject.toml

* Fix docs
  • Loading branch information
hagenw authored Oct 11, 2023
1 parent 3b30940 commit e0135c3
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 119 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
13 changes: 7 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import configparser
from datetime import date
import os
import shutil

import toml

import audeer


config = configparser.ConfigParser()
config.read(os.path.join('..', 'setup.cfg'))
config = toml.load(audeer.path('..', 'pyproject.toml'))


# Project -----------------------------------------------------------------
author = config['metadata']['author']
author = ', '.join(author['name'] for author in config['project']['authors'])
copyright = f'2020-{date.today().year} audEERING GmbH'
project = config['metadata']['name']
project = config['project']['name']
version = audeer.git_repo_version()
title = f'{project} Documentation'
title = 'Documentation'


# General -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sphinx-audeering-theme >=1.1.3
sphinx-autodoc-typehints
sphinx-copybutton
sphinxcontrib-katex
toml
Loading

0 comments on commit e0135c3

Please sign in to comment.