From 831cb66a28b9b78802b5a3cfc9c1cedaef6dae53 Mon Sep 17 00:00:00 2001 From: David Evans Date: Tue, 15 Oct 2024 13:28:09 +0100 Subject: [PATCH] Test installation using `uv` --- .github/workflows/tests.yml | 4 ++++ tests/test_packaging.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 83e34d0..480a3f3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,6 +17,10 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Install `uv` + uses: astral-sh/setup-uv@f3bcaebff5eace81a1c062af9f9011aae482ca9d # v3.1.7 + with: + version: "0.4.20" - name: Install dependencies run: | python -m pip install -r requirements.dev.txt diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 2680d2d..34f9eac 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -66,6 +66,35 @@ def test_packaging(package_type, tmp_path, older_version_file): assert "Successfully installed opensafely" in result.stdout +def test_installing_with_uv(tmp_path, older_version_file): + uv_bin = shutil.which("uv") + if uv_bin is None: + pytest.skip("Skipping as `uv` not installed") + + package_path = build_package("bdist_wheel") + bin_path = tmp_path / "bin" + uv_env = dict( + os.environ, + UV_TOOL_BIN_DIR=bin_path, + UV_TOOL_DIR=tmp_path / "tools", + ) + python_version = f"python{sys.version_info[0]}.{sys.version_info[1]}" + subprocess_run( + [uv_bin, "tool", "install", "--python", python_version, package_path], + env=uv_env, + check=True, + ) + # Basic smoketest + subprocess_run([bin_path / "opensafely", "run", "--help"], check=True) + subprocess_run([bin_path / "opensafely", "--version"], check=True) + # The `upgrade` command should prompt the user to use `uv upgrade` instead + result = subprocess_run( + [bin_path / "opensafely", "upgrade"], capture_output=True, text=True + ) + assert result.returncode != 0 + assert "uv tool upgrade opensafely" in result.stdout + + def build_package(package_type): extension = {"sdist": "tar.gz", "bdist_wheel": "whl"}[package_type] project_root = Path(__file__).parent.parent