astral-sh / setup-uv

Set up your GitHub Actions workflow with a specific version of https://docs.astral.sh/uv/
MIT License
200 stars 14 forks source link

Confused about how to use without a virtualenv #124

Open ngoldbaum opened 1 month ago

ngoldbaum commented 1 month ago

I feel like I'm going against the grain here and maybe that's the issue.

I'd like to replace setup-python with setup-uv. Our existing CI uses python from setup-python directly, without setting up a virtualenv.

Is it possible to use uv in a similar way? Basically, I'd like to install directly into the global environment associated with a uv python install command. When I try to actually do that, I see errors like:

Run uv pip install --python=3.13t -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython

error: No virtual environment found for Python 3.13t; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment

Is the right thing to do here to put uv's python at the front of the PATH and then pass --system? Or just use a virtualenv? If it's the latter, then this is not quite a drop-in replacement for setup-python, since that's not necessary with setup-python.

ngoldbaum commented 1 month ago

And if I put the path to the uv-managed python at the front of my PATH environment variable, and then try to install something into its environment with uv pip install --system, I get errors like:

  error: The interpreter at /home/runner/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu is externally managed, and indicates the following:

    This Python installation is managed by uv and should not be modified.

  Consider creating a virtual environment with `uv venv`.
ngoldbaum commented 1 month ago

The way I've worked around this is by activating the virtualenv once, then inserting the updated PATH into GITHUB_ENV:

    - uses: astral-sh/setup-uv@f3bcaebff5eace81a1c062af9f9011aae482ca9d
    - run: |
        uv python install 3.13t
        uv venv --python 3.13t
        uv pip install pip
        . .venv/bin/activate
        echo PATH=$PATH >> $GITHUB_ENV

It looks like the setup-pixi action has an activate-envrionment option that does the same thing with a bit nicer of UX. Might it make sense for setup-uv to do add a similar feature?

eifinger commented 3 weeks ago

Could you please add a bit of context on the bigger picture and what you are trying to achieve?

My understanding is, that you want to use uv to install packages into your system (faster than with pip) to then use those packages without a venv. Is that correct? EDIT: Saw the linked issue in numpy. I also tried a bit around and got to the same conclusions as you so far. Will keep you posted

ngoldbaum commented 3 weeks ago

Ah, great, glad you were ultimately able to figure out what I meant.

mscheltienne commented 2 weeks ago

I agree it's a bit confusing, at the moment I'm going with:

      - name: Setup Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install uv
        uses: astral-sh/setup-uv@v3
      - name: Install package
        run: uv pip install --quiet --system .[test]

But it doesn't seems like the recommended approach.