Skip to content

Commit

Permalink
change version output to json so it's consistent in linux vs windows
Browse files Browse the repository at this point in the history
  • Loading branch information
saucoide committed Sep 16, 2024
1 parent 4ddee7c commit 7a3c951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import abc
import contextlib
import functools
import json
import os
import platform
import re
Expand Down Expand Up @@ -69,13 +70,13 @@ def find_uv() -> tuple[bool, str]:

def uv_version() -> version.Version:
ret = subprocess.run(
[UV, "--version"],
[UV, "version", "--output-format", "json"],
check=False,
text=True,
capture_output=True,
)
if ret.returncode == 0 and ret.stdout:
return version.Version(ret.stdout.strip().lstrip("uv "))
return version.Version(json.loads(ret.stdout).get("version"))
else:
logger.info("Failed to establish uv's version.")
return version.Version("0.0")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,15 @@ def find_uv_bin():
@pytest.mark.parametrize(
["return_code", "stdout", "expected_result"],
[
(0, "uv 0.2.3", "0.2.3"),
(0, '{"version": "0.2.3", "commit_info": null}', "0.2.3"),
(1, None, "0.0"),
(1, "uv 9.9.9", "0.0"),
(1, '{"version": "9.9.9", "commit_info": null}', "0.0"),
],
)
def test_uv_version_error(monkeypatch, return_code, stdout, expected_result):
def mock_run(*args, **kwargs):
return subprocess.CompletedProcess(
args=["uv", "--version"],
args=["uv", "version", "--output-format", "json"],
stdout=stdout,
returncode=return_code,
)
Expand Down

0 comments on commit 7a3c951

Please sign in to comment.