From adfe8d22491b24215b6d3c9f1d36850abc84e77a Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Sat, 11 May 2024 06:42:37 -0600 Subject: [PATCH] test: ensure apt *and* python c extensions work properly --- examples/python-numpy/main.py | 9 +++++++++ src/providers/python.rs | 11 +++++++++-- tests/docker_run_tests.rs | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/python-numpy/main.py b/examples/python-numpy/main.py index 91cf46052..1f12efb0c 100644 --- a/examples/python-numpy/main.py +++ b/examples/python-numpy/main.py @@ -1,5 +1,7 @@ +import sys import numpy as np import pandas as pd +import subprocess print(np) print(pd) @@ -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) diff --git a/src/providers/python.rs b/src/providers/python.rs index fd831e099..36b7f5874 100644 --- a/src/providers/python.rs +++ b/src/providers/python.rs @@ -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)) diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs index e7dc4a301..f975c4196 100644 --- a/tests/docker_run_tests.rs +++ b/tests/docker_run_tests.rs @@ -97,6 +97,8 @@ async fn run_image(name: &str, cfg: Option) -> String { } }; + assert!(_status_code == Some(0), "Failed to run image successfully"); + let reader = BufReader::new(child.stdout.unwrap()); reader .lines() @@ -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]