Skip to content

Commit

Permalink
Move maturin test coverage into CI (#3714)
Browse files Browse the repository at this point in the history
This test can take over 60s to run, which is too much for a unit test.
We'll run it in a separate CI job to retain coverage.
  • Loading branch information
zanieb authored May 21, 2024
1 parent cf99708 commit dfd6ccf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,31 @@ jobs:
./uv venv
./${{ matrix.command }}
integration-test-maturin:
needs: build-binary-linux
name: "integration test | maturin"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: "Download binary"
uses: actions/download-artifact@v4
with:
name: uv-linux-${{ github.sha }}

- name: "Prepare binary"
run: chmod +x ./uv

- name: "Compile"
run: |
echo '-e ${PROJECT_ROOT}/scripts/packages/maturin_editable' | ./uv pip compile - -o requirements.txt
- name: "Sync"
run: |
./uv venv
./uv pip sync requirements.txt
cache-test-ubuntu:
needs: build-binary-linux
name: "check cache | ubuntu"
Expand Down
4 changes: 1 addition & 3 deletions crates/uv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ reqwest = { workspace = true, features = ["blocking"], default-features = false
ignored = ["flate2"]

[features]
default = ["flate2/zlib-ng", "python", "pypi", "git", "maturin", "python-patch"]
default = ["flate2/zlib-ng", "python", "pypi", "git", "python-patch"]
# Introduces a dependency on a local Python installation.
python = []
# Introduces a dependency on a local Python installation with specific patch versions.
Expand All @@ -99,8 +99,6 @@ python-patch = []
pypi = []
# Introduces a dependency on Git.
git = []
# Introduces a dependency on Maturin.
maturin = []
# Adds self-update functionality.
self-update = ["axoupdater"]

Expand Down
8 changes: 2 additions & 6 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3327,13 +3327,11 @@ fn respect_file_env_var() -> Result<()> {
}

#[test]
#[cfg(feature = "maturin")]
fn compile_editable() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str(indoc! {r"
-e ../../scripts/packages/poetry_editable
-e ${PROJECT_ROOT}/../../scripts/packages/maturin_editable
-e file://../../scripts/packages/black_editable[dev]
boltons # normal dependency for comparison
"
Expand All @@ -3347,8 +3345,6 @@ fn compile_editable() -> Result<()> {
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z [TEMP_DIR]/requirements.in
-e ${PROJECT_ROOT}/../../scripts/packages/maturin_editable
# via -r [TEMP_DIR]/requirements.in
-e ../../scripts/packages/poetry_editable
# via -r [TEMP_DIR]/requirements.in
-e file://../../scripts/packages/black_editable
Expand Down Expand Up @@ -3383,8 +3379,8 @@ fn compile_editable() -> Result<()> {
# via aiohttp
----- stderr -----
Built 3 editables in [TIME]
Resolved 14 packages in [TIME]
Built 2 editables in [TIME]
Resolved 13 packages in [TIME]
"###);

Ok(())
Expand Down
63 changes: 31 additions & 32 deletions crates/uv/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2123,19 +2123,25 @@ fn refresh_package() -> Result<()> {
}

#[test]
#[cfg(feature = "maturin")]
fn sync_editable() -> Result<()> {
let context = TestContext::new("3.12");
let poetry_editable = context.temp_dir.child("poetry_editable");
// Copy into the temporary directory so we can mutate it
copy_dir_all(
context
.workspace_root
.join("scripts/packages/poetry_editable"),
&poetry_editable,
)?;

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str(&indoc::formatdoc! {r"
boltons==23.1.1
-e {workspace_root}/scripts/packages/maturin_editable
numpy==1.26.2
# via poetry-editable
-e file://{workspace_root}/scripts/packages/poetry_editable
-e file://{poetry_editable}
",
workspace_root = context.workspace_root.simplified_display(),
poetry_editable = poetry_editable.display()
})?;

// Install the editable packages.
Expand All @@ -2146,14 +2152,13 @@ fn sync_editable() -> Result<()> {
----- stdout -----
----- stderr -----
Built 2 editables in [TIME]
Built 1 editable in [TIME]
Resolved 2 packages in [TIME]
Downloaded 2 packages in [TIME]
Installed 4 packages in [TIME]
Installed 3 packages in [TIME]
+ boltons==23.1.1
+ maturin-editable==0.1.0 (from file://[WORKSPACE]/scripts/packages/maturin_editable)
+ numpy==1.26.2
+ poetry-editable==0.1.0 (from file://[WORKSPACE]/scripts/packages/poetry_editable)
+ poetry-editable==0.1.0 (from file://[TEMP_DIR]/poetry_editable)
"###
);

Expand All @@ -2170,58 +2175,52 @@ fn sync_editable() -> Result<()> {
Built 1 editable in [TIME]
Uninstalled 1 package in [TIME]
Installed 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE]/scripts/packages/poetry_editable)
+ poetry-editable==0.1.0 (from file://[WORKSPACE]/scripts/packages/poetry_editable)
- poetry-editable==0.1.0 (from file://[TEMP_DIR]/poetry_editable)
+ poetry-editable==0.1.0 (from file://[TEMP_DIR]/poetry_editable)
"###
);

// Make sure we have the right base case.
let python_source_file = context
.workspace_root
.join("scripts/packages/maturin_editable/python/maturin_editable/__init__.py");
let python_version_1 = indoc::indoc! {r"
from .maturin_editable import *
let python_source_file = poetry_editable.path().join("poetry_editable/__init__.py");
let check_installed = indoc::indoc! {r#"
from poetry_editable import a
assert a() == "a", a()
"#};
context.assert_command(check_installed).success();

// Edit the sources and make sure the changes are respected without syncing again
let python_version_1 = indoc::indoc! {r"
version = 1
"};
fs_err::write(&python_source_file, python_version_1)?;

let check_installed = indoc::indoc! {r#"
from maturin_editable import sum_as_string, version
let check_installed = indoc::indoc! {r"
from poetry_editable import version
assert version == 1, version
assert sum_as_string(1, 2) == "3", sum_as_string(1, 2)
"#};
"};
context.assert_command(check_installed).success();

// Edit the sources.
let python_version_2 = indoc::indoc! {r"
from .maturin_editable import *
version = 2
"};
fs_err::write(&python_source_file, python_version_2)?;

let check_installed = indoc::indoc! {r#"
from maturin_editable import sum_as_string, version
from pathlib import Path
let check_installed = indoc::indoc! {r"
from poetry_editable import version
assert version == 2, version
assert sum_as_string(1, 2) == "3", sum_as_string(1, 2)
"#};
"};
context.assert_command(check_installed).success();

// Don't create a git diff.
fs_err::write(&python_source_file, python_version_1)?;

uv_snapshot!(context.filters(), command(&context)
.arg(requirements_txt.path()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Audited 4 packages in [TIME]
Audited 3 packages in [TIME]
"###
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def a():
pass
return "a"

0 comments on commit dfd6ccf

Please sign in to comment.