Skip to content

Commit d7599ab

Browse files
committed
📝 Update uv sections
* Reproducing and updating uv environments
1 parent bad4bee commit d7599ab

File tree

3 files changed

+86
-71
lines changed

3 files changed

+86
-71
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Added
3232
Changed
3333
~~~~~~~
3434

35+
* 📝 Update uv sections
36+
37+
* Reproducing and updating uv environments
38+
3539
* 📝 Update conda term
3640
* 📝 Update GitLab package registry
3741
* 📝 Expand the pytest plugins section

docs/appendix/glossary.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,16 +529,19 @@ Glossary
529529
uv greatly simplifies the development and deployment of Python projects:
530530

531531
* :ref:`Installation <uv>`
532-
* :doc:`Python environments
533-
<Python4DataScience:productive/envs/uv/index>`
534-
* :ref:`uv-package-structure`
532+
* :ref:`Reproduce <reproduce-virtual-env>` and :ref:`update
533+
<update-uv-lock>` virtual environments
534+
* :ref:`Create packages <uv-package-structure>` and publish them on
535+
:doc:`PyPI <../packs/publish>` or :doc:`GitLab <../packs/gitlab>`
535536
* :doc:`Developing applications <../packs/apps>`
536537
* Testing libraries with different :ref:`Python versions
537538
<various-python-versions>` and :ref:`tox_uv`
539+
* :ref:`Reproducing <reproduce-virtual-env>` and :ref:`updating
540+
<update-uv-lock>` the Python environment, if necessary also with a
541+
:doc:`Python4DataScience:productive/envs/uv/dependency-bot`
538542
* :doc:`Python4DataScience:productive/envs/uv/cicd`
539543
* :doc:`Python4DataScience:productive/envs/uv/docker`
540-
* Publishing packages on :doc:`PyPI <../packs/publish>` and
541-
:doc:`GitLab <../packs/gitlab>`
544+
* Check vulnerabilities with :ref:`uv-secure <check-vulnerabilities>`
542545

543546
.. seealso::
544547
* `Docs <https://docs.astral.sh/uv/>`__

docs/packs/apps.rst

Lines changed: 74 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ interfaces)`. We can also create them with ``uv init --package``:
2222
└── myapp
2323
└── __init__.py
2424
25+
.. note::
26+
I strongly believe that a Python application should be properly packaged to
27+
enjoy the many benefits, such as
28+
29+
* source management with :doc:`importlib <python3:library/importlib>`
30+
* executable scripts with ``project.scripts`` instead of attached
31+
:file:`scripts` folders
32+
* the benefits of :file:`src` layout with a common, documented and well
33+
understood structure.
34+
2535
:file:`myapp/pyproject.toml`
2636
The :file:`pyproject.toml` file contains a ``scripts`` entry point
2737
``myapp:main``:
@@ -56,90 +66,88 @@ interfaces)`. We can also create them with ``uv init --package``:
5666
>>> myapp.main()
5767
Hello from myapp!
5868
59-
.. note::
60-
I strongly believe that a Python application should be properly packaged to
61-
enjoy the many benefits, such as
62-
63-
* source management with :doc:`importlib <python3:library/importlib>`
64-
* executable scripts with ``project.scripts`` instead of attached
65-
:file:`scripts` folders
66-
* the benefits of :file:`src` layout with a common, documented and well
67-
understood structure.
68-
6969
.. _uv_lock:
7070

7171
:file:`uv.lock` file
72-
--------------------
73-
74-
With ``uv add --dev .`` the :file:`uv.lock` file was also created alongside the
75-
:file:`pyproject.toml` file. :file:`uv.lock` is a cross-platform lock file that
76-
records the packages that are to be installed across all possible Python
77-
features such as operating system, architecture and Python version.
78-
79-
Unlike :file:`pyproject.toml`, which specifies the general requirements of your
80-
project, :file:`uv.lock` contains the exact resolved versions that are installed
81-
in the project environment. This file should be checked into the :doc:`Git
82-
<Python4DataScience:productive/git/index>` version control system to enable
83-
consistent and reproducible installations on different computers.
84-
85-
.. literalinclude:: myapp/uv.lock
86-
:caption: myapp/uv.lock
87-
88-
:file:`uv.lock` is a human-readable
89-
:doc:`Python4DataScience:data-processing/serialisation-formats/toml/index` file,
90-
but is managed by ``uv`` and should not be edited manually.
91-
92-
.. note::
93-
If ``uv`` is to be integrated into other tools or workflows, you can export
94-
the content to the `requirements file format
95-
<https://pip.pypa.io/en/stable/reference/requirements-file-format/>`_ using
96-
:samp:`uv export --format requirements-txt > {CONSTRAINTS.TXT}`. Conversely,
97-
the :samp:`{CONSTRAINTS.TXT}` file created can then be used with ``uv pip
98-
install`` or other tools.
72+
With ``uv add --dev .`` the :file:`uv.lock` file was also created alongside
73+
the :file:`pyproject.toml` file. :file:`uv.lock` is a cross-platform lock
74+
file that records the packages that are to be installed across all possible
75+
Python features such as operating system, architecture and Python version.
76+
77+
Unlike :file:`pyproject.toml`, which specifies the general requirements of
78+
your project, :file:`uv.lock` contains the exact resolved versions that are
79+
installed in the project environment. This file should be checked into the
80+
:doc:`Git <Python4DataScience:productive/git/index>` version control system
81+
to enable consistent and reproducible installations on different computers.
82+
83+
.. literalinclude:: myapp/uv.lock
84+
:caption: myapp/uv.lock
85+
86+
:file:`uv.lock` is a human-readable
87+
:doc:`Python4DataScience:data-processing/serialisation-formats/toml/index`
88+
file, but is managed by ``uv`` and should not be edited manually.
89+
90+
.. note::
91+
If ``uv`` is to be integrated into other tools or workflows, you can
92+
export the content to the `requirements file format
93+
<https://pip.pypa.io/en/stable/reference/requirements-file-format/>`_
94+
using :samp:`uv export --format requirements-txt > {CONSTRAINTS.TXT}`.
95+
Conversely, the :samp:`{CONSTRAINTS.TXT}` file created can then be used
96+
with ``uv pip install`` or other tools.
97+
98+
.. _reproduce-virtual-env:
99+
100+
Reproducing the Python environment
101+
----------------------------------
102+
103+
In production environments, you should always use exactly the versions that have
104+
been tested. You can use ``uv sync --locked`` in your environment to ensure that
105+
the :file:`uv.lock` file matches the project metadata. Otherwise an error
106+
message will be displayed.
107+
108+
You can then use ``uv sync --frozen`` in the production environment to ensure
109+
that the versions of :file:`uv.lock` are used as the source of truth, but if
110+
the :file:`uv.lock` file is missing in the production environment, ``uv sync
111+
--frozen`` will terminate with an error. Finally, changes to dependencies in the
112+
:file:`pyproject.toml` file are ignored if they are not yet written to the
113+
:file:`uv.lock` file.
114+
115+
If you want to use ``uv run`` in a productive environment, the ``--no-sync``
116+
option prevents the environment from being updated.
99117

100118
.. _update-uv-lock:
101119

102-
Aktualisieren von :file:`uv.lock`
103-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104-
105-
:file:`uv.lock` is updated regularly when ``uv sync`` and ``uv run`` are called.
106-
107-
``--frozen``
108-
leaves the :file:`uv.lock file` unchanged.
109-
``--no-sync``
110-
avoids updating the environment during ``uv run`` calls.
111-
``--locked``
112-
ensures that the lock file matches the project metadata. If the lockfile is
113-
not up-to-date, an error message is issued instead of updating the lockfile.
120+
Updating the Python environment
121+
-------------------------------
114122

115123
By default, ``uv`` favours the locked versions of the packages when executing
116124
``uv sync`` and ``uv lock``. Package versions are only changed if the dependency
117125
conditions of the project exclude the previous, locked version.
118126

119-
``uv lock --upgrade``
120-
updates all packages.
121-
:samp:`uv lock --upgrade-package {PACKAGE}=={VERSION}`
122-
upgrades a single package to a specific version.
127+
With ``uv lock --upgrade`` you can upgrade all packages and with :samp:`uv lock
128+
--upgrade-package {PACKAGE}=={VERSION}` you can upgrade individual packages to a
129+
specific version.
123130

124-
You can also use the
125-
:doc:`Python4DataScience:productive/git/advanced/hooks/pre-commit` to regularly
126-
update your uv.lock file:
131+
.. tip::
132+
You can also use the
133+
:doc:`Python4DataScience:productive/git/advanced/hooks/pre-commit` to
134+
regularly update your :file:`uv.lock` file:
127135

128-
.. code-block:: yaml
129-
:caption: .pre-commit-config.yaml
136+
.. code-block:: yaml
137+
:caption: .pre-commit-config.yaml
130138
131-
- repo: https://github.com/astral-sh/uv-pre-commit
132-
rev: 0.4.24
133-
hooks:
134-
- id: uv-lock
139+
- repo: https://github.com/astral-sh/uv-pre-commit
140+
rev: 0.5.21
141+
hooks:
142+
- id: uv-lock
135143
136144
Restrict platform and Python versions
137-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145+
-------------------------------------
138146

139147
If your project only supports a limited number of platforms or Python versions,
140-
you can do this in the :file:`pyprojects.toml` file in compliance with
141-
:pep:`508`, for example to restrict the :file:`uv.lock` file to macOS and Linux
142-
only:
148+
you can do this in the :file:`pyprojects.toml` file :pep:`508` compliant, for
149+
example to restrict your project to macOS and Linux only you can add the
150+
following section in your :file:`pyproject.toml` file:
143151

144152
.. code-block:: toml
145153

0 commit comments

Comments
 (0)