-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uv venv
and github actions scripts / workflows
#1386
Comments
Hi! You need to activate virtual environments so set Related #1326 |
Sorry maybe I'm being dumb here, but I've tried this and it still doesn't pick up the package. steps:
- name: Checkout code
uses: actions/checkout@v4.1.1
- name: Set up Python
uses: actions/setup-python@v5.0.0
with:
python-version: '3.10'
- name: Install current package as editable
run: |
pip install uv
uv venv
VIRTUAL_ENV=./.venv
uv pip install darglint
- name: Check docstrings
run: bash scripts/docstring.sh
env:
VIRTUAL_ENV: ./.venv I even threw in a |
With GitHub Actions I think it makes more sense to install the dependencies globally in the virtual machine. uv does not support that yet. See #1374 In your “Check docstrings” step shown above you’re missing also updating the PATH environment variable to include |
Had a similar issue, got this working for me with the following snippet :
Its a bit of a hack, but basically you create the environment variable and set it to the root python and append it to the special github_env variable. This basically tells uv to just use the system python instead oa virtual env, should be good to go, |
@dylanbstorey that's a neat trick, and helpful it works across operating systems too. But would be good for |
Ok and key here is that the |
Was running into race conditions here or at least issues with steps / jobs running in parallel attempting to access the same environment, it seems. I switched back to using |
Ideally for me there would be clear instructions on good practice for using |
Thank you @dylanbstorey . In my use of your trick, I quote
Ideally for me any documented example will pass |
Can confirm @dylanbstorey's hack - run: echo "VIRTUAL_ENV=${Python_ROOT_DIR}" >> $GITHUB_ENV is working fine in my case: |
The previous solutions suggested in this thread aren't cross-platform:
All that means that the previous suggested solutions won't work in a workflow job that runs on multiple operating systems in CI. After much debugging with @MichaReiser, here's a workflow job that I'm now successfully using to run tests for my hobby project jobs:
pytest-tests:
name: Run tests with pytest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.10", "3.11", "3.12"]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Create and activate a virtual environment (Windows)
if: ${{ runner.os == 'Windows' }}
# uv doesn't (yet) allow us to install packages globally;
# we have to create and activate a virtual environment
run: |
irm https://astral.sh/uv/install.ps1 | iex
uv venv .venv
"VIRTUAL_ENV=.venv" | Out-File -FilePath $env:GITHUB_ENV -Append
"$PWD/.venv/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Append
- name: Create and activate a virtual environment (Unix)
if: ${{ runner.os != 'Windows' }}
# uv doesn't (yet) allow us to install packages globally;
# we have to create and activate a virtual environment
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv .venv
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
echo "$PWD/.venv/bin" >> $GITHUB_PATH
- name: Install dependencies
run: uv pip install -e ".[pytest]"
- run: uv pip freeze
- name: Run tests under coverage
run: |
coverage run -m pytest
coverage report |
@AlexWaygood, @MichaReiser Thank you for investigating this. If you want to use |
@adamtheturtle we tried that but it caused other things to break ;) take a look at the test failures on AlexWaygood/typeshed-stats#191. |
Had / having similar issues on our CI. Choosing to wait for a more stable way for this global install to happen which I believe will be worked on next week. |
The following worked here. jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install uv
uv venv
uv pip install -e .[dev]
- name: Activate virtualenv
run: |
. .venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
- name: Test with pytest
run: pytest |
See astral-sh/uv#1386 Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
See astral-sh/uv#1386 Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
I'll just note that |
Nope! But it's a good point!
I think that would likely depend quite a lot on how complex it is to resolve the requirements set. But for simple requirements sets, I'd wager you're likely right. |
The way I understand it, the cache does not really speeds up resolution itself, no? Well, unless you do not run |
oh I don't actually really know anything about how the caching works. Should probably not have implied that I did 😆 |
Closing this issue as the |
The cache does improve resolution times because sometimes we need to build source distributions to determine their requirements during resolution which is generally slow — the cache contains these builds. |
Hi! For those of you who are subscribed to this and are using |
Can anyone share an example of how to set up uv in GitHub actions with --system/--python? |
Having trouble converting our pre-existing CI workflows / scripts to use
uv
, as you can see here. Problem relates to the virtual environments which don't seem to be retained between workflow steps.This is maybe the easiest illustration of that:
One step installs it, and then the next step runs a script which in turn attempts to use the package, but it fails because the CI can't be found.
I don't see any docs yet, so wondering how best to handle this?
The text was updated successfully, but these errors were encountered: