Skip to content

Commit da22502

Browse files
authored
Improve uv instructions, add dev dependencies (#187)
* Improve uv instructions, add dev dependencies * Add --no-workspace to --editable * Mention the example scripts * Mention alternatives to uv * RTD: use uv * separate "test" and "doc" dependency groups
1 parent 41ad65f commit da22502

File tree

8 files changed

+1868
-143
lines changed

8 files changed

+1868
-143
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,9 @@ jobs:
3636
- name: Install dependencies
3737
run: |
3838
uv sync --locked
39-
uv pip install -r tests/requirements.txt
40-
uv pip install -r doc/requirements.txt
41-
# This is needed in example scripts:
42-
uv pip install pillow
4339
- name: Test
4440
run: uv run --locked -m pytest
4541
- name: Test examples
46-
run: uv run --locked --script doc/examples/run_all.py
42+
run: uv run --locked --with pillow --script doc/examples/run_all.py
4743
- name: Test documentation
4844
run: uv run --locked -m sphinx doc/ _build/ -b doctest

CONTRIBUTING.rst

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,13 @@ Contributions are always welcome!
99
Development Installation
1010
^^^^^^^^^^^^^^^^^^^^^^^^
1111

12-
Instead of pip-installing the latest release from PyPI_, you should get the
12+
Instead of installing the latest release from PyPI_, you should get the
1313
newest development version from Github_::
1414

1515
git clone https://github.com/sfstoolbox/sfs-python.git
1616
cd sfs-python
1717
uv sync
1818

19-
This creates a virtual environment where the latest development version
20-
of the SFS Toolbox is installed.
21-
Note that you can activate this environment from any directory
22-
(e.g. one where you have some Python scripts using the ``sfs`` module),
23-
it doesn't have to be the directory where you cloned the Git repository.
24-
25-
Wherever you activate that environment from,
26-
it will always stay up-to-date, even if you pull new
27-
changes from the Github repository or switch branches.
28-
2919
.. _PyPI: https://pypi.org/project/sfs/
3020
.. _Github: https://github.com/sfstoolbox/sfs-python/
3121

@@ -34,47 +24,40 @@ Building the Documentation
3424
^^^^^^^^^^^^^^^^^^^^^^^^^^
3525

3626
If you make changes to the documentation, you can re-create the HTML pages
37-
using Sphinx_.
38-
From the main ``sfs-python`` directory,
39-
you can install it and a few other necessary packages with::
40-
41-
uv pip install -r doc/requirements.txt
42-
43-
To create the HTML pages, use::
27+
using Sphinx_. From the main ``sfs-python`` directory, run::
4428

45-
uv run -m sphinx doc _build
29+
uv run sphinx-build doc _build
4630

4731
The generated files will be available in the directory ``_build/``.
4832

49-
To create the PDF file, use::
33+
.. _Sphinx: http://sphinx-doc.org/
5034

51-
uv run -m sphinx doc _build -b latex
5235

53-
Afterwards go to the folder ``_build/`` and run LaTeX to create the
54-
PDF file. If you don’t know how to create a PDF file from the LaTeX output, you
55-
should have a look at Latexmk_ (see also this `Latexmk tutorial`_).
36+
Running the Tests
37+
^^^^^^^^^^^^^^^^^
5638

57-
It is also possible to automatically check if all links are still valid::
39+
You'll need pytest_, which will be installed automatically.
40+
To execute the tests, simply run::
5841

59-
uv run -m sphinx doc _build -b linkcheck
42+
uv run pytest
6043

61-
.. _Sphinx: http://sphinx-doc.org/
62-
.. _Latexmk: https://www.cantab.net/users/johncollins/latexmk/
63-
.. _Latexmk tutorial: https://mg.readthedocs.io/latexmk.html
44+
.. _pytest: https://pytest.org/
6445

65-
Running the Tests
66-
^^^^^^^^^^^^^^^^^
6746

68-
You'll need pytest_ for that.
69-
It can be installed with::
47+
Editable Installation
48+
^^^^^^^^^^^^^^^^^^^^^
7049

71-
uv pip install -r tests/requirements.txt
50+
If you want to work in a different directory on your own files,
51+
but using the latest development version (or a custom branch) of
52+
the ``sfs`` module, you can switch to a directory of your choice
53+
and enter this::
7254

73-
To execute the tests, simply run::
55+
uv init --bare
56+
uv add --editable --no-workspace path/to/your/sfs/repo
7457

75-
uv run -m pytest
58+
You can install further packages with ``uv add`` and then run
59+
whatever you need with ``uv run``.
7660

77-
.. _pytest: https://pytest.org/
7861

7962
Creating a New Release
8063
^^^^^^^^^^^^^^^^^^^^^^

doc/installation.rst

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ You can install ``uv`` with your favorite package manager,
1313
or by one of the other methods described at
1414
https://docs.astral.sh/uv/getting-started/installation/.
1515

16+
If you don't like ``uv``, no problem!
17+
You can also use Python's official packaging tool pip_ or any other third-party tool,
18+
as long as it can install `the SFS package`_.
19+
1620
.. _Python: https://www.python.org/
1721
.. _uv: https://docs.astral.sh/uv/
22+
.. _pip: https://packaging.python.org/en/latest/tutorials/installing-packages/
23+
.. _the SFS package: https://pypi.org/project/sfs/
1824
.. _NumPy: http://www.numpy.org/
1925
.. _SciPy: https://www.scipy.org/scipylib/
2026
.. _Matplotlib: https://matplotlib.org/
@@ -24,32 +30,74 @@ Installation
2430

2531
First, create a new directory wherever you want, change into it, then run::
2632

27-
uv venv
28-
29-
This will print instructions for how to `activate the environment`__.
30-
You should do that now!
33+
uv init --bare
3134

32-
__ https://docs.astral.sh/uv/pip/environments/#using-a-virtual-environment
35+
This will create a file named ``pyproject.toml`` for you.
36+
Use the ``--help`` flag to see other options.
3337

34-
The Sound Field Synthesis Toolbox can be installed with::
38+
The Sound Field Synthesis Toolbox can now be installed with::
3539

36-
uv pip install sfs
40+
uv add sfs
3741

3842
This will automatically install the NumPy_ and SciPy_ libraries as well,
3943
which are needed by the SFS Toolbox.
44+
It will also create a file named ``uv.lock``, which tracks the exact versions
45+
of all installed packages.
4046

4147
If you want to use the provided functions for plotting sound fields, you'll need
4248
Matplotlib_::
4349

44-
uv pip install matplotlib
50+
uv add matplotlib
4551

4652
However, since all results are provided as plain NumPy_ arrays, you should also
4753
be able to use any other plotting library of your choice to visualize the sound
4854
fields.
4955

50-
The steps above need to be executed only once.
51-
Whenever you come back to this directory at a later time,
52-
you just need to activate the environment again.
56+
You might also want to install some other Python-related tools,
57+
e.g. JupyterLab_::
58+
59+
uv add jupyterlab
60+
61+
.. _JupyterLab: https://jupyter.org/
62+
63+
You get the gist: whatever you need, just ``uv add ...`` it!
64+
65+
Once everything is installed, you can start working with the tool of your choice
66+
by simply prefixing it with ``uv run``, for example::
67+
68+
uv run jupyter lab
69+
70+
Similarly, you can launch any other tool, like a text editor, an IDE etc.
71+
72+
You can also simply create a Python file, let's say ``my_script.py``:
73+
74+
.. code:: python
75+
76+
import matplotlib.pyplot as plt
77+
import numpy as np
78+
import sfs
79+
80+
npw = sfs.util.direction_vector(np.radians(-45))
81+
f = 300 # Hz
82+
omega = 2 * np.pi * f
83+
84+
grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)
85+
array = sfs.array.circular(N=32, R=1.5)
86+
87+
d, selection, secondary_source = sfs.fd.wfs.plane_25d(
88+
omega, array.x, array.n, npw)
89+
90+
p = sfs.fd.synthesize(d, selection, array, secondary_source, grid=grid)
91+
sfs.plot2d.amplitude(p, grid)
92+
sfs.plot2d.loudspeakers(array.x, array.n, selection * array.a, size=0.15)
93+
94+
plt.show()
95+
96+
You can then run this script (assuming you installed ``matplotlib`` before) with::
97+
98+
uv run my_script.py
99+
100+
In a similar way, you can run the :doc:`example-python-scripts`.
53101

54102
If you want to install the latest development version of the SFS Toolbox, have a
55103
look at :doc:`contributing`.

doc/requirements.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ Documentation = "https://sfs-python.readthedocs.io/"
2222
Repository = "https://github.com/sfstoolbox/sfs-python"
2323
Issues = "https://github.com/sfstoolbox/sfs-python/issues"
2424

25+
[dependency-groups]
26+
dev = [{ include-group = "test" }, { include-group = "doc" }]
27+
test = [
28+
"pytest",
29+
]
30+
doc = [
31+
"sphinx>=8",
32+
"sphinx-rtd-theme",
33+
"nbsphinx",
34+
"ipykernel",
35+
"sphinxcontrib-bibtex>=2.1.4",
36+
"matplotlib>=3",
37+
]
38+
2539
[tool.setuptools.packages.find]
2640
include = ["sfs*"]
2741

readthedocs.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ build:
44
os: ubuntu-24.04
55
tools:
66
python: "3"
7-
8-
python:
9-
install:
10-
- method: pip
11-
path: .
12-
- requirements: doc/requirements.txt
7+
jobs:
8+
pre_create_environment:
9+
- asdf plugin add uv
10+
- asdf install uv latest
11+
- asdf global uv latest
12+
create_environment:
13+
- uv venv "${READTHEDOCS_VIRTUALENV_PATH}"
14+
install:
15+
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv sync --frozen
1316

1417
sphinx:
1518
configuration: doc/conf.py

tests/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)