-
Notifications
You must be signed in to change notification settings - Fork 771
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
using nox and uv only to test multiple python versions #6579
Comments
Additional info. Using a simpler noxfile:
it will run fine, for the specifically requested python version.
Using it specifying another version is working:
|
Need to find a minute to play around with this before giving a confident answer. In the meantime would love to hear from others. |
@henryiii might have ideas on the ideal way to do this using Nox with uv as he was the author of the integration of nox with uv |
I have the same need to run against multiple versions of Python, but ones that are built "in-house". Currently we're using tox to drive this as opposed to another tool wrapping tox: [tox]
envlist = prepare,test3{10,11,12},ci
ignore_basepython_conflict = true
[testenv]
base_python = python3.10
...
[testenv:test310]
depends = prepare
commands =
pytest test --cov src
mypy --config-file tox.ini src
...
[testenv:test311]
depends = prepare
commands =
pytest test --cov src
[testenv:test312]
depends = prepare
commands =
pytest test --cov src
... |
I ran into the same issue. In the meantime, I'm just adding the paths to uv pythons to the def add_uv_to_environ() -> None:
import os
import subprocess
from pathlib import Path
path_to_uv_pythons = (
subprocess.check_output(
["uv", "python", "dir"], env={"NO_COLOR": "1", **os.environ}
)
.decode()
.strip()
)
paths_new = ":".join(map(str, Path(path_to_uv_pythons).glob("*/bin")))
paths_old = os.environ["PATH"]
os.environ["PATH"] = f"{paths_new}:{paths_old}"
add_uv_to_environ()
@nox.session
def test(session):
... Or as a bash script #!/usr/bin/env bash
p=$PATH
for k in "$(uv python dir)"/*/bin; do
p="${k}:${p}"
done
PATH=$p "$@" and run shim-uv nox/tox .... |
@wpk-nist-gov, thank you for providing the script! I’m wondering if there’s a way to automate the process of pulling the necessary Python versions beforehand. Do you have any automated solution for this, and if so, how do you implement it? Currently, I'm using From my understanding, to utilize the script you provided, I would first need to identify the specific Python versions I want, then have uv install them, and only afterward add them to the PATH. Is there a more simpler way around? Or, rather, a more standardized way that I could pass down onto users? |
nox is supposed to install Python automatically as needed as long as you are using the uv backend. That was added in wntrblm/nox#842, which was released almost exactly a month ago. |
Hey, this is great news actually! Just to make it clear, were you talking about setting venv backend to uv? @henryiii
This worked for me. |
Yes, or nox.options.default_venv_backend = "uv|virtualenv" (I put this in all my noxfiles) |
For anybody struggling with this, make sure that you are using uv >= 0.4.16. We were on 0.4.4 and this line was being skipped: |
Hi,
I'm struggling to use a pure uv only environment that can use nox for multiple python versions...
Dockerfile
noxfile.py
the
uv python install 3.x
doesn't create any shims (like you would have with pyenv), so they are not known to the shell with python3.11 ...I can call nox from uv per python versions, which works, but kind of beats the point of nox.
For each of the command the other environment would be skipped. Example:
(therefore not specifying the different python versions in the noxfile.)
Has anyone else played with this already? (and got it to work?)
My goal is to use versions installed by uv only and preferably have it run automatically against all desired python versions.
uv version: 0.3.3
The text was updated successfully, but these errors were encountered: