Skip to content

Commit

Permalink
test: ensure apt *and* python c extensions work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed May 11, 2024
1 parent a24535c commit adfe8d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/python-numpy/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
import numpy as np
import pandas as pd
import subprocess

print(np)
print(pd)
Expand All @@ -8,3 +10,10 @@
print(arr)

print("Hello from Python numpy and pandas")

# with the wrong LD_LIBRARY_PATH, this will fail with a GLIBC version mismatch
result = subprocess.run(["apt", "--version"], capture_output=True, text=True)
print(result.stdout)

# fail if subprocess fails!
sys.exit(result.returncode)
11 changes: 9 additions & 2 deletions src/providers/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,15 @@ impl PythonProvider {
let mut setup = Phase::setup(Some(pkgs));

// Many Python packages need some C headers to be available
// stdenv.cc.cc.lib -> https://discourse.nixos.org/t/nixos-with-poetry-installed-pandas-libstdc-so-6-cannot-open-shared-object-file/8442/3
setup.add_pkgs_libs(vec!["zlib".to_string(), "stdenv.cc.cc.lib".to_string()]);
//
// - https://discourse.nixos.org/t/nixos-with-poetry-installed-pandas-libstdc-so-6-cannot-open-shared-object-file/8442/3
// - https://github.com/mcdonc/.nixconfig/blob/e7885ad18b7980f221e59a21c91b8eb02795b541/videos/pydev/script.rst
//
// Some packages (like stdenv.cc.cc.lib) may conflict with other system commands and cause libc version conflicts
// since LD_LIBRARY_PATH is mutated by `add_pkgs_libs`
//

setup.add_pkgs_libs(vec!["zlib".to_string()]);
setup.add_nix_pkgs(&[Pkg::new("gcc")]);

Ok(Some(setup))
Expand Down
3 changes: 3 additions & 0 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ async fn run_image(name: &str, cfg: Option<Config>) -> String {
}
};

assert!(_status_code == Some(0), "Failed to run image successfully");

let reader = BufReader::new(child.stdout.unwrap());
reader
.lines()
Expand Down Expand Up @@ -771,6 +773,7 @@ async fn test_python_numpy() {
let name = simple_build("./examples/python-numpy").await;
let output = run_image(&name, None).await;
assert!(output.contains("Hello from Python numpy and pandas"));
assert!(output.contains("apt is a commandline package manager"));
}

#[tokio::test]
Expand Down

0 comments on commit adfe8d2

Please sign in to comment.