Skip to content

Commit 6c4bcc6

Browse files
committed
Update readme for uv
Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent 7c717f6 commit 6c4bcc6

File tree

1 file changed

+118
-13
lines changed

1 file changed

+118
-13
lines changed

README.md

Lines changed: 118 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,130 @@
33
Note: this is a perpertual work in progress. If you encounter any obstacles or bugs, let us know!
44

55
## Main requirements
6-
* python >= 3.8
7-
* packages as listed in requirements/base.txt
8-
* extra test-specific requirements are documented in the test file
9-
"Requirements" header
6+
7+
This project encourages the use of [uv](https://github.com/astral-sh/uv) to deal with the python dependencies.
8+
9+
Some tools are required on the host running the tests:
10+
* python >= 3.11 (from your distro, or from `uv` as described below)
1011
* `netcat` is required on the machine running the tests.
1112

12-
### Quick install (python requirements)
13+
Extra test-specific requirements are documented in the test file "Requirements" header.
1314

14-
Install the python requirements using pip:
15+
### Quick install
1516

16-
```
17-
$ pip install -r requirements/base.txt
18-
```
17+
Install `uv` with one of these commands
1918

20-
Additionally, for dev dependencies (things like the linter / style checker):
19+
~~~sh
20+
pip install uv # for Fedora-based and older distros
21+
pipx install uv # for newer distros
22+
curl -LsSf https://astral.sh/uv/install.sh | sh # if you don't mind an installer modifying your environment
23+
~~~
2124

22-
```
23-
$ pip install -r requirements/dev.txt
24-
```
25+
You have two options to run the tests:
26+
27+
* with the `uv run` command
28+
29+
You can use the dependencies managed by `uv` by prefixing the commands documented in the next chapters with `uv run`.
30+
For example
31+
32+
~~~sh
33+
uv run pytest
34+
~~~
35+
36+
or
37+
38+
~~~sh
39+
uv run ./jobs.py
40+
~~~
41+
42+
When running the command with `uv run`, `uv` checks that your dependencies are
43+
up to date and updates them if required, before running your command. You're
44+
always sure to have the expected dependencies, even when switching branch!
45+
46+
* by activating the virtual environment
47+
48+
You need to run `uv sync` to install the dependencies managed by uv, and then
49+
activate the virtual environment with
50+
51+
~~~sh
52+
source .venv/bin/activate
53+
~~~
54+
55+
You can then run the commands directly in your shell: `pytest`, `./jobs.py`, …
56+
57+
Note you have to explicitly run `uv sync` when the dependencies are modified in
58+
the project, as `uv` won't ensure that the dependencies are up to date when run
59+
this way.
60+
61+
Running `deactivate` restores your shell configuration.
62+
63+
### Advanced usages
64+
65+
> [!CAUTION]
66+
> These methods don't strictly guarantee the version of the dependencies.
67+
68+
#### Use a specific python interpreter with `uv`
69+
70+
`uv` is able to use any python version accessible on your system. Many `uv`
71+
commands accept a `-p`/`--python` option which takes either the path of the
72+
python interpreter to use, or a python version. `uv` also uses the value of
73+
the `UV_PYTHON` environment variable to set the python interpreter (or version
74+
to use).
75+
76+
So if you want to run this project with your system's interpreter, you can
77+
78+
~~~sh
79+
export UV_PYTHON=$(which python3)
80+
~~~
81+
82+
and then use `uv` as shown in the previous section.
83+
84+
> [!TIP]
85+
> [direnv](https://direnv.net/) may be used to automatically deal with the
86+
> environment variables when you enter the project directory with your shell.
87+
88+
#### Dealing with dependencies without `uv`
89+
90+
This project can be used without `uv`.
91+
92+
If you desire, you can install a virtual environment with
93+
94+
~~~sh
95+
python3 -m venv .venv
96+
source .venv/bin/activate
97+
~~~
98+
99+
or skip the virtual environment entirely and just go with a user or system
100+
installation of the dependencies.
101+
102+
The base dependencies can be installed with
103+
104+
~~~sh
105+
./pip_install_pyproject.py
106+
~~~
107+
108+
Optionally, you can install the development dependencies with
109+
110+
~~~sh
111+
./pip_install_pyproject.py dev
112+
~~~
113+
114+
### Adding python dependencies
115+
116+
When adding a dependency, run
117+
118+
~~~sh
119+
uv add --raw my_dep
120+
~~~
121+
122+
This command installs the dependency locally and update the `uv.lock` file.
123+
124+
> [!NOTE]
125+
> In order to keep this project usable with dependency packaged by the system,
126+
> we always use `uv add` with the `--raw` command line option.
127+
128+
The lock file allows `uv` to install the dependencies at the exact same versions
129+
on all the environments.
25130

26131
## Other requirements
27132
* XCP-ng hosts that you can ssh to using a SSH key, non-interactively

0 commit comments

Comments
 (0)