tweag / FawltyDeps

Python dependency checker
Other
201 stars 14 forks source link

Use uv instead of pip to manage virtualenvs #432

Closed jherland closed 4 months ago

jherland commented 6 months ago

uv is much faster than pip for installing package (it is also faster then python -m venv for creating virtualenvs). This PR switches from venv/pip to uv in three separate parts of our project:

  1. Instruct Nox to use uv instead of pip to manage the virtualenv associated with each Nox session (first commit).
  2. Use uv instead of venv/pip (when available) to manage virtualenvs for our sample_project and real_projects tests (next three commits).
  3. Use uv instead of venv/pip (when available) to create and populate the temporary virtualenv managed by the --install-deps option (next two commits).

The first two points above only concern our tests and has no effect on the FawltyDeps program itself. The last one changes the behavior of the --install-deps option to use uv when available (otherwise fall back to venv/pip).

The last commit in this PR adds a small convenience for our users: If they want to ensure that uv is available for FawltyDeps to use, they can now install fawltydeps[uv]. This uv extra will bring in uv as a dependency in much the same way that we currently depend on nox[uv] in our own developement environment.

Commits:

mknorps commented 4 months ago

Thank you @jherland 🫶

I started checking the PR by looking at all usages of "pip". There are some places where we can consider updating the text or a name:

  1. https://github.com/tweag/FawltyDeps/blob/57ebc4c4ebee7ffb811cc478b2ec6cb743514049/README.md#L442: "This will use pip install" -> "This will use uv pip install and fall back to pip install if uv is not available"
  2. https://github.com/tweag/FawltyDeps/blob/57ebc4c4ebee7ffb811cc478b2ec6cb743514049/docs/DesignDoc.md#L192 Should we also include uvinstructions? Or should we only apply it in the developer context?
  3. https://github.com/tweag/FawltyDeps/blob/57ebc4c4ebee7ffb811cc478b2ec6cb743514049/tests/conftest.py#L33-L34
  4. https://github.com/tweag/FawltyDeps/blob/57ebc4c4ebee7ffb811cc478b2ec6cb743514049/tests/project_helpers.py#L178-L179
  5. https://github.com/tweag/FawltyDeps/blob/57ebc4c4ebee7ffb811cc478b2ec6cb743514049/tests/test_install_deps.py#L29-L30 does this still hold for uv?
jherland commented 4 months ago

I started checking the PR by looking at all usages of "pip". There are some places where we can consider updating the text or a name:

Agreed. Look at f2d359c for my rewordings.

monkeypatch.setenv("PIP_NO_INDEX", "True") does this still hold for uv?

Actually it does not! 🙀

Furthermore, although uv supports some UV_* environment variables that mirror the PIP_* equivalents, these settings/variables cannot yet be set via the environment. I found a workaround instead that relies on setting up a (temporary) config file for uv. Take a look at 2795898 for the details.