From 4d607fc25b6611b29a03b6c94d57408f0b465319 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 15:50:06 +0200 Subject: [PATCH 01/14] Use uv in Actions --- .github/workflows/doc.yml | 15 +++++---------- .github/workflows/publish.yml | 12 ++++-------- .github/workflows/test.yml | 17 ++++++----------- CONTRIBUTING.rst | 28 +++++++--------------------- pyproject.toml | 17 +++++++++++++++++ 5 files changed, 39 insertions(+), 50 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index e5bd38fd..ad65a422 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -29,25 +29,20 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Ubuntu - install libsndfile run: | sudo apt-get update sudo apt-get install --no-install-recommends --yes libsndfile1 - - name: Install package - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - # DOCS - name: Ubuntu - install graphviz run: sudo apt-get install --yes graphviz - - name: Install docs requirements - run: pip install -r docs/requirements.txt - - name: Test building documentation - run: python -m sphinx docs/ docs/_build/ -b html -W + run: uv run python -m sphinx docs/ docs/_build/ -b html -W - name: Check links in documentation - run: python -m sphinx docs/ docs/_build/ -b linkcheck -W + run: uv run python -m sphinx docs/ docs/_build/ -b linkcheck -W diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8cbded71..ef142550 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,14 +25,12 @@ jobs: with: python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build virtualenv + - name: Install uv + uses: astral-sh/setup-uv@v5 # PyPI package - name: Build Python package - run: python -m build + run: uv build - name: Publish Python package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -48,12 +46,10 @@ jobs: run: | sudo apt-get install --no-install-recommends --yes libsndfile1 sox sudo apt-get install --yes graphviz - pip install -r requirements.txt - pip install -r docs/requirements.txt - name: Build documentation run: | - python -m sphinx docs/ docs/_build/ -b html + uv run python -m sphinx docs/ docs/_build/ -b html - name: Deploy documentation to Github pages uses: peaceiris/actions-gh-pages@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6fd6e6c6..c88a55e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,25 +48,23 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Ubuntu - install libsndfile run: | sudo apt-get update sudo apt-get install --no-install-recommends --yes libsndfile1 if: matrix.os == 'ubuntu-latest' - - name: Install package - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Install numpy<2.0.0 for pandas==2.0.3 run: | - pip install "numpy<2.0.0" + uv add "numpy<2.0.0" if: matrix.pandas == 'pandas==2.0.3' - name: Install requested pandas version run: | - pip install "${{ matrix.pandas }}" + uv add "${{ matrix.pandas }}" if: matrix.pandas # TESTS @@ -84,11 +82,8 @@ jobs: run: choco install ffmpeg mediainfo-cli if: matrix.os == 'windows-latest' - - name: Install tests requirements - run: pip install -r tests/requirements.txt - - name: Test with pytest - run: python -m pytest + run: uv run pytest - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f71e2b4e..b206de0a 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -22,11 +22,7 @@ you should get the newest development version from Github_:: git clone https://github.com/audeering/audb/ cd audb - # Create virtual environment for this project - # e.g. - # virtualenv --python="python3" $HOME/.envs/audb - # source $HOME/.envs/audb/bin/activate - pip install -r requirements.txt + uv sync This way, @@ -81,21 +77,16 @@ 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:: +you can re-create the HTML pages using Sphinx_:: - pip install -r docs/requirements.txt - -To create the HTML pages, use:: - - python -m sphinx docs/ build/sphinx/html -b html + uv run python -m sphinx docs/ build/html -b html The generated files will be available -in the directory :file:`build/sphinx/html/`. +in the directory :file:`build/html/`. It is also possible to automatically check if all links are still valid:: - python -m sphinx docs/ build/sphinx/html -b linkcheck + uv run python -m sphinx docs/ build/html -b linkcheck .. _Sphinx: http://sphinx-doc.org @@ -103,14 +94,9 @@ It is also possible to automatically check if all links are still valid:: Running the Tests ----------------- -You'll need pytest_ for that. -It can be installed with:: - - pip install -r tests/requirements.txt - -To execute the tests, simply run:: +You can run tests with pytest_:: - python -m pytest + uv run pytest .. _pytest: https://pytest.org diff --git a/pyproject.toml b/pyproject.toml index eff83013..1b415edc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,23 @@ repository = 'https://github.com/audeering/audb/' documentation = 'https://audeering.github.io/audb/' +# ===== Dependency groups ================================================= +[dependency-groups] +dev = [ + 'audiofile >=1.1.0', + 'docutils', + 'pytest', + 'pytest-cov', + 'sphinx >=3.5.4', + 'sphinx-apipages >=0.1.2', + 'sphinx-audeering-theme >=1.2.1', + 'sphinx-autodoc-typehints', + 'sphinx-copybutton', + 'sybil', + 'toml', +] + + # ===== BUILD-SYSTEM ====================================================== # # Requirements for building the Python package From 7133a2fa604dfe5236f7c5d8430b8b76770e0548 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 15:55:41 +0200 Subject: [PATCH 02/14] Remove requirement files --- docs/requirements.txt | 7 ------- requirements.txt | 1 - tests/requirements.txt | 5 ----- 3 files changed, 13 deletions(-) delete mode 100644 docs/requirements.txt delete mode 100644 requirements.txt delete mode 100644 tests/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index 2d6d19df..00000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -docutils -sphinx >=3.5.4 -sphinx-apipages >=0.1.2 -sphinx-audeering-theme >=1.2.1 -sphinx-autodoc-typehints -sphinx-copybutton -toml diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d6e1198b..00000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ --e . diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index dbb12eec..00000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -audiofile >=1.1.0 -pytest -pytest-cov -pytest-console-scripts -sybil From 9650f39f197705d9451c8ae735c5611add16a8bc Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 16:04:12 +0200 Subject: [PATCH 03/14] Update benchmarks to use uv --- benchmarks/README.md | 16 ++++------------ .../benchmark-dependencies-methods-polars.py | 10 ++++++++++ benchmarks/benchmark-dependencies-methods.py | 10 ++++++++++ .../benchmark-dependencies-save-and-load.py | 11 +++++++++++ benchmarks/compare_dependency_methods_polars.py | 7 +++++++ benchmarks/dependencies_polars.py | 11 +++++++++++ benchmarks/requirements.txt | 5 ----- 7 files changed, 53 insertions(+), 17 deletions(-) delete mode 100644 benchmarks/requirements.txt diff --git a/benchmarks/README.md b/benchmarks/README.md index 8db4415e..56f6aa44 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -13,14 +13,6 @@ on the following machine: * Linux: Ubuntu 22.04 * Python: 3.10 -Before running any benchmark, -make sure to install missing requirements with: - -```bash -$ cd benchmarks/ -$ pip install -r requirements.txt -``` - ## audb.Dependencies methods @@ -34,7 +26,7 @@ the dependency table internally. To run the benchmark execute: ```bash -$ python benchmark-dependencies-methods.py +$ uv run --python 3.10 benchmark-dependencies-methods.py ``` Execution times in seconds @@ -97,14 +89,14 @@ This benchmark was executed on: To run the benchmark execute: ```bash -$ python benchmark-dependencies-methods-polars.py +$ uv run --python 3.11 benchmark-dependencies-methods-polars.py ``` The data were compared to the results from `benchmark-dependencies-methods.py` using ```bash -python compare_dependency_methods_polars.py +$ uv run --python 3.11 compare_dependency_methods_polars.py ``` Both steps require that `benchmark-dependencies-methods.py` has been run previously in order to create the test data @@ -161,7 +153,7 @@ and `pyarrow.Table`). To run the benchmark execute: ```bash -$ python benchmark-dependencies-save-and-load.py +$ uv run --python 3.10 benchmark-dependencies-save-and-load.py ``` **Writing** diff --git a/benchmarks/benchmark-dependencies-methods-polars.py b/benchmarks/benchmark-dependencies-methods-polars.py index 0504ff89..7b656756 100644 --- a/benchmarks/benchmark-dependencies-methods-polars.py +++ b/benchmarks/benchmark-dependencies-methods-polars.py @@ -1,3 +1,13 @@ +# /// script +# dependencies = [ +# "audb", +# "tabulate", +# ] +# +# [tool.uv.sources] +# audb = { path = "../", editable = true } +# /// + import random import time diff --git a/benchmarks/benchmark-dependencies-methods.py b/benchmarks/benchmark-dependencies-methods.py index 8ecc5df2..55e2cc2a 100644 --- a/benchmarks/benchmark-dependencies-methods.py +++ b/benchmarks/benchmark-dependencies-methods.py @@ -1,3 +1,13 @@ +# /// script +# dependencies = [ +# "audb", +# "tabulate", +# ] +# +# [tool.uv.sources] +# audb = { path = "../", editable = true } +# /// + import hashlib import os import pickle diff --git a/benchmarks/benchmark-dependencies-save-and-load.py b/benchmarks/benchmark-dependencies-save-and-load.py index 92e6f8a2..86761a97 100644 --- a/benchmarks/benchmark-dependencies-save-and-load.py +++ b/benchmarks/benchmark-dependencies-save-and-load.py @@ -1,3 +1,14 @@ +# /// script +# dependencies = [ +# "audb", +# "memray ==1.11.0", +# "tabulate", +# ] +# +# [tool.uv.sources] +# audb = { path = "../", editable = true } +# /// + import hashlib import os import pickle diff --git a/benchmarks/compare_dependency_methods_polars.py b/benchmarks/compare_dependency_methods_polars.py index 1bb89e56..bc17fbca 100644 --- a/benchmarks/compare_dependency_methods_polars.py +++ b/benchmarks/compare_dependency_methods_polars.py @@ -1,3 +1,10 @@ +# /// script +# dependencies = [ +# "pandas", +# "tabulate", +# ] +# /// + import pandas as pd import tabulate diff --git a/benchmarks/dependencies_polars.py b/benchmarks/dependencies_polars.py index 960e5dc1..c274ef84 100644 --- a/benchmarks/dependencies_polars.py +++ b/benchmarks/dependencies_polars.py @@ -1,3 +1,14 @@ +# /// script +# dependencies = [ +# "audb", +# "polars", +# "tabulate", +# ] +# +# [tool.uv.sources] +# audb = { path = "../", editable = true } +# /// + from __future__ import annotations from collections.abc import Callable diff --git a/benchmarks/requirements.txt b/benchmarks/requirements.txt deleted file mode 100644 index f4aa67c5..00000000 --- a/benchmarks/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -memray ==1.11.0 -pandas -polars -pyarrow -tabulate From b26738d95a85998881406c4418ef58c1ee062438 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 16:14:19 +0200 Subject: [PATCH 04/14] Ignore uv.lock --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 056f227c..27f80825 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ coverage.xml docs/api/ benchmarks/cache/ benchmarks/results/ +uv.lock From 4eaa2686b7b52fa7c0aa11652037f40eb3b30f4a Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 16:22:43 +0200 Subject: [PATCH 05/14] Show installed packages in tests --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c88a55e3..b83ee382 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,7 +83,9 @@ jobs: if: matrix.os == 'windows-latest' - name: Test with pytest - run: uv run pytest + run: | + uv pip list + uv run pytest - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 From 58ccf11c9683d0a3f2a92530b7a783c00d744ace Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 16:29:44 +0200 Subject: [PATCH 06/14] Try to better list packages --- .github/workflows/test.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b83ee382..bb1dfeed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,6 +67,11 @@ jobs: uv add "${{ matrix.pandas }}" if: matrix.pandas + - name: List installed Python packages + run: | + uv sync + uv pip list + # TESTS - name: Ubuntu - install ffmpeg/mediainfo run: | @@ -83,9 +88,7 @@ jobs: if: matrix.os == 'windows-latest' - name: Test with pytest - run: | - uv pip list - uv run pytest + run: uv run pytest - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 From e8afd5c594078b6050eeafa2aa1f1df345184db0 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 16:37:58 +0200 Subject: [PATCH 07/14] Remove obsolete pandas==2.0.3 handling --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb1dfeed..f75bb36f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,11 +57,6 @@ jobs: sudo apt-get install --no-install-recommends --yes libsndfile1 if: matrix.os == 'ubuntu-latest' - - name: Install numpy<2.0.0 for pandas==2.0.3 - run: | - uv add "numpy<2.0.0" - if: matrix.pandas == 'pandas==2.0.3' - - name: Install requested pandas version run: | uv add "${{ matrix.pandas }}" From f4a76bb2524e1b1795d7cc26544401af72d27c7b Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 1 Apr 2025 16:38:51 +0200 Subject: [PATCH 08/14] Separate sync and pip list --- .github/workflows/test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f75bb36f..d8eaa4c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -62,10 +62,11 @@ jobs: uv add "${{ matrix.pandas }}" if: matrix.pandas + - name: Sync Python environment + run: uv sync + - name: List installed Python packages - run: | - uv sync - uv pip list + run: uv pip list # TESTS - name: Ubuntu - install ffmpeg/mediainfo From 55fc94fbd282de3d0e3fd2f4ab6c6c2e5997708c Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 28 Apr 2025 15:31:42 +0200 Subject: [PATCH 09/14] Use uv for pre-commit --- .github/workflows/linter.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 1c47b46d..6c9d3c0e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -20,10 +20,7 @@ jobs: python-version: '3.10' - name: Install pre-commit hooks - run: | - pip install pre-commit - pre-commit install --install-hooks + run: uv run pre-commit install --install-hooks - name: Code style check via pre-commit - run: | - pre-commit run --all-files + run: uv run pre-commit run --all-files From c2f609de3d2b88a3f36e2dba644488552e79d258 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 28 Apr 2025 15:35:15 +0200 Subject: [PATCH 10/14] Ensure uv is available --- .github/workflows/linter.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6c9d3c0e..69f9f721 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -19,6 +19,9 @@ jobs: with: python-version: '3.10' + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Install pre-commit hooks run: uv run pre-commit install --install-hooks From a8767f10e9c92252caf18081f49ddc067b610504 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 28 Apr 2025 15:52:45 +0200 Subject: [PATCH 11/14] Try uvx instead --- .github/workflows/linter.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 69f9f721..f58747a8 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -23,7 +23,7 @@ jobs: uses: astral-sh/setup-uv@v5 - name: Install pre-commit hooks - run: uv run pre-commit install --install-hooks + run: uvx pre-commit install --install-hooks - name: Code style check via pre-commit - run: uv run pre-commit run --all-files + run: uvx pre-commit run --all-files From 0fc7928ed99ab113bdeb31102f272abe9f2a45d0 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 13 May 2025 08:53:41 +0200 Subject: [PATCH 12/14] Use uvx for ruff and codespell --- CONTRIBUTING.rst | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b206de0a..3952ca84 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -46,9 +46,8 @@ are defined in :file:`pyproject.toml`. The checks are executed in the CI using `pre-commit`_. You can enable those checks locally by executing:: - pip install pre-commit # consider system wide installation - pre-commit install - pre-commit run --all-files + uvx pre-commit install + uvx pre-commit run --all-files Afterwards ruff_ and codespell_ are executed every time you create a commit. @@ -56,15 +55,14 @@ every time you create a commit. You can also install ruff_ and codespell_ and call it directly:: - 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 + uvx ruff check --fix . # lint all Python files, and fix any fixable errors + uvx ruff format . # format code of all Python files + uvx codespell It can be restricted to specific folders:: - ruff check audfoo/ tests/ - codespell audfoo/ tests/ + uvx ruff check audfoo/ tests/ + uvx codespell audfoo/ tests/ .. _codespell: https://github.com/codespell-project/codespell/ From a0c744fa618ebd35708d81ed0d816c6c6d63623b Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Wed, 28 May 2025 11:01:14 +0200 Subject: [PATCH 13/14] Mention that graphiz is needed --- CONTRIBUTING.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 3952ca84..9f9275e4 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -20,9 +20,9 @@ Development Installation Instead of pip-installing the latest release from PyPI_, you should get the newest development version from Github_:: - git clone https://github.com/audeering/audb/ - cd audb - uv sync + git clone https://github.com/audeering/audb/ + cd audb + uv sync This way, @@ -77,14 +77,19 @@ Building the Documentation If you make changes to the documentation, you can re-create the HTML pages using Sphinx_:: - uv run python -m sphinx docs/ build/html -b html + uv run python -m sphinx docs/ build/html -b html The generated files will be available in the directory :file:`build/html/`. +Note, +that you need ``graphviz`` for building the documentation:: + + sudo apt install graphviz + It is also possible to automatically check if all links are still valid:: - uv run python -m sphinx docs/ build/html -b linkcheck + uv run python -m sphinx docs/ build/html -b linkcheck .. _Sphinx: http://sphinx-doc.org @@ -94,7 +99,7 @@ Running the Tests You can run tests with pytest_:: - uv run pytest + uv run pytest .. _pytest: https://pytest.org From 9cf94cba353ea56600a2c22375acefbe1f5c90e6 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Wed, 28 May 2025 15:53:04 +0200 Subject: [PATCH 14/14] Use just to test and build docs --- justfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 00000000..968868f3 --- /dev/null +++ b/justfile @@ -0,0 +1,12 @@ +# build documentation +docs: + uv run python -m sphinx docs/ build/html -b html + +# run tests +test *ARGS: + uv run pytest {{ARGS}} + +# run pre-commit +pre-commit: + uvx pre-commit install + uvx pre-commit run --all-files