uv icon indicating copy to clipboard operation
uv copied to clipboard

Sync with system Python?

Open b-phi opened this issue 1 year ago • 6 comments

I'm trying to use uv to synchronize environments across a cluster. This involves creating a lock file and then using it to install dependencies everywhere. As far as I can tell, uv sync only supports installing dependencies in a uv managed venv. Is there anyway to run sync against a target environment, the system Python in this case?

b-phi avatar Aug 09 '24 16:08 b-phi

I was able to workaround this by activating the environment dynamically, but this does feel like a bit of a hack since it doesn't guarantee that the environments are actually synced. This is with a dask cluster, I'm not aware of an easy way to "switch" to the new venv if the workers are started with the system python.

import runpy

runpy.run_path('.venv/bin/activate_this.py')

b-phi avatar Aug 09 '24 17:08 b-phi

Na this isn't supported yet.

charliermarsh avatar Aug 09 '24 17:08 charliermarsh

I think you can use uv venv --system-site-packages but uv sync is not yet aware of requirements that are already satisfied by the system/inherited environment so it still attempts to resolve and install them.

chrisrodrigue avatar Aug 11 '24 01:08 chrisrodrigue

In the mean time, I'm addind the venv's bin (or Scripts on Windows) folder to PATH as per https://github.com/jakebailey/pyright-action/tree/v2/?tab=readme-ov-file#using-pyright-from-path :

jobs:
  mypy:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: canopeum_backend
    steps:
      - uses: actions/checkout@v4
      - name: Install uv using the standalone installer
        run: curl -LsSf https://astral.sh/uv/install.sh | sh
      - run: uv sync --locked --extra dev
      - run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
      - run: mypy . --python-version=3.12

  pyright:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: canopeum_backend
    steps:
      - uses: actions/checkout@v4
      - name: Install uv using the standalone installer
        run: curl -LsSf https://astral.sh/uv/install.sh | sh
      - run: uv sync --locked --extra dev
      - run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
      - uses: jakebailey/pyright-action@v2
        with:
          version: PATH
          python-version: "3.12"
          working-directory: canopeum_backend

And making sure that my docker commands are using uv run instead of python

SamuelT-Beslogic avatar Aug 14 '24 20:08 SamuelT-Beslogic

I upvote for the optional synchronization with the host system rather than with venv-only. Not only for CI/CD, but for me personally it is also occasionally preferable to install project packages into the system directly.

seppzer0 avatar Aug 25 '24 15:08 seppzer0

One option is to symlink:

ln -sf $(/path/to/target/python -c 'import sys; print(sys.prefix)') .venv 
uv sync

hauntsaninja avatar Aug 25 '24 20:08 hauntsaninja

I suppose it is a functional workaround, but having this implemented natively into uv would be a big improvement

seppzer0 avatar Sep 05 '24 11:09 seppzer0

This is now supported via UV_PROJECT_ENVIRONMENT (#6834) — I still don't recommend it but you don't need to do a symlink.

zanieb avatar Sep 05 '24 13:09 zanieb