Skip to content

Commit

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

* Use pyproject.toml

* Fix codespell errors

* Fix ruff errors

* Update setup.py to work with pyproject.toml

* Update publish Action

* Fix metadata parsing in docs

* Fix typos
  • Loading branch information
hagenw authored Aug 15, 2023
1 parent ed0b129 commit 4e07823
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 102 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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install build virtualenv
- name: Build wheels
run: python -m build --wheel --outdir wheelhouse
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
52 changes: 32 additions & 20 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/audresample/issues/new/
.. _pull request: https://github.com/audeering/audresample/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/audresample/
cd audresample
# Create virutal environment for this project
# Create virtual environment for this project
# e.g.
# virtualenv --python="python3" $HOME/.envs/audresample
# source $HOME/.envs/audresample/bin/activate
pip install -r requirements.txt

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

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/audresample/
.. _Github: https://github.com/audeering/audresample/


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 audresample/ tests/
codespell audresample/ 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

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 @@ -99,7 +111,7 @@ To execute the tests, simply run::

python -m pytest

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


Creating a New Release
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ Have a look at the installation_ and usage_ instructions.
.. |tests| image:: https://github.com/audeering/audresample/workflows/Test/badge.svg
:target: https://github.com/audeering/audresample/actions?query=workflow%3ATest
:alt: Test status
.. |coverage| image:: https://codecov.io/gh/audeering/audresample/branch/master/graph/badge.svg?token=NPQDJ5T7HI
.. |coverage| image:: https://codecov.io/gh/audeering/audresample/branch/main/graph/badge.svg?token=NPQDJ5T7HI
:target: https://codecov.io/gh/audeering/audresample/
:alt: code coverage
.. |docs| image:: https://img.shields.io/pypi/v/audresample?label=docs
:target: https://audeering.github.io/audresample/
:alt: audresample's documentation
.. |license| image:: https://img.shields.io/badge/license-MIT-green.svg
:target: https://github.com/audeering/audfactory/blob/master/LICENSE
:alt: audfactory's MIT license
:target: https://github.com/audeering/audresample/blob/main/LICENSE
:alt: audresample's MIT license
.. |python-versions| image:: https://img.shields.io/pypi/pyversions/audresample.svg
:target: https://pypi.org/project/audresample/
:alt: audresamples's supported Python versions
8 changes: 3 additions & 5 deletions audresample/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from audresample.core import define
from audresample.core.api import (
am_fm_synth,
remix,
resample,
)
from audresample.core.api import am_fm_synth
from audresample.core.api import remix
from audresample.core.api import resample
from audresample.core.config import config


Expand Down
2 changes: 1 addition & 1 deletion audresample/core/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def platform_name():

# resample

class ConverterConfig(ctypes.Structure):
class ConverterConfig(ctypes.Structure): # noqa: D101
_fields_ = [
("srIn", ctypes.c_double),
("srOut", ctypes.c_double),
Expand Down
10 changes: 5 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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']
project = config['project']['name']
author = ', '.join(author['name'] for author in config['project']['authors'])
copyright = f'2020-{date.today().year} audEERING GmbH'
project = config['metadata']['name']
version = audeer.git_repo_version()
title = 'Documentation'

Expand Down
2 changes: 0 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. documentation master file
.. include:: ../README.rst

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

0 comments on commit 4e07823

Please sign in to comment.