Merge pull request #214990 from risicle/ris-onnx-full-source-tests

python3Packages.onnx: use github source & enable many more tests
This commit is contained in:
Robert Scott 2023-02-14 00:13:24 +00:00 committed by GitHub
commit 5d4e464c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 16 deletions

View File

@ -1,4 +1,10 @@
{ lib, stdenv, cmake, ninja, fetchFromGitHub }: { lib
, stdenv
, fetchFromGitHub
, cmake
, ninja
, static ? stdenv.hostPlatform.isStatic,
}:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "gtest"; pname = "gtest";
@ -20,7 +26,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake ninja ]; nativeBuildInputs = [ cmake ninja ];
cmakeFlags = [ cmakeFlags = [
"-DBUILD_SHARED_LIBS=ON" "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}"
] ++ lib.optionals (stdenv.cc.isClang && (lib.versionOlder stdenv.cc.version "16.0")) [ ] ++ lib.optionals (stdenv.cc.isClang && (lib.versionOlder stdenv.cc.version "16.0")) [
# Enable C++17 support # Enable C++17 support
# https://github.com/google/googletest/issues/3081 # https://github.com/google/googletest/issues/3081

View File

@ -1,35 +1,42 @@
{ lib { lib
, buildPythonPackage , buildPythonPackage
, python3
, bash , bash
, cmake , cmake
, fetchPypi , fetchFromGitHub
, gtest
, isPy27 , isPy27
, nbval , nbval
, numpy , numpy
, protobuf , protobuf
, pybind11
, pytestCheckHook , pytestCheckHook
, six , six
, tabulate , tabulate
, typing-extensions , typing-extensions
, pythonRelaxDepsHook , pythonRelaxDepsHook
, pytest-runner
}: }:
buildPythonPackage rec { let
gtestStatic = gtest.override { static = true; };
in buildPythonPackage rec {
pname = "onnx"; pname = "onnx";
version = "1.13.0"; version = "1.13.0";
format = "setuptools"; format = "setuptools";
disabled = isPy27; disabled = isPy27;
src = fetchPypi { src = fetchFromGitHub {
inherit pname version; owner = pname;
sha256 = "sha256-QQs5lQNnhX+XtlCTaB/iSVouI9Y3d6is6vlsVqFtFm4="; repo = pname;
rev = "refs/tags/v${version}";
sha256 = "sha256-D8POBAkZVr0O5i4qsSuYRkDfL8WsDTqzgNACmmkFwGs=";
}; };
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
pythonRelaxDepsHook pythonRelaxDepsHook
pybind11
]; ];
pythonRelaxDeps = [ "protobuf" ]; pythonRelaxDeps = [ "protobuf" ];
@ -44,30 +51,36 @@ buildPythonPackage rec {
nativeCheckInputs = [ nativeCheckInputs = [
nbval nbval
pytestCheckHook pytestCheckHook
pytest-runner
tabulate tabulate
]; ];
postPatch = '' postPatch = ''
chmod +x tools/protoc-gen-mypy.sh.in chmod +x tools/protoc-gen-mypy.sh.in
patchShebangs tools/protoc-gen-mypy.sh.in patchShebangs tools/protoc-gen-mypy.sh.in
substituteInPlace setup.py \
--replace 'setup_requires.append("pytest-runner")' ""
# prevent from fetching & building own gtest
substituteInPlace CMakeLists.txt \
--replace 'include(googletest)' ""
substituteInPlace cmake/unittest.cmake \
--replace 'googletest)' ')'
''; '';
# Set CMAKE_INSTALL_LIBDIR to lib explicitly, because otherwise it gets set
# to lib64 and cmake incorrectly looks for the protobuf library in lib64
preConfigure = '' preConfigure = ''
# Set CMAKE_INSTALL_LIBDIR to lib explicitly, because otherwise it gets set
# to lib64 and cmake incorrectly looks for the protobuf library in lib64
export CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib -DONNX_USE_PROTOBUF_SHARED_LIBS=ON" export CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib -DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
'' + lib.optionalString doCheck ''
export CMAKE_ARGS+=" -Dgoogletest_STATIC_LIBRARIES=${gtestStatic}/lib/libgtest.a -Dgoogletest_INCLUDE_DIRS=${lib.getDev gtestStatic}/include"
export ONNX_BUILD_TESTS=1
''; '';
preBuild = '' preBuild = ''
export MAX_JOBS=$NIX_BUILD_CORES export MAX_JOBS=$NIX_BUILD_CORES
''; '';
disabledTestPaths = [
# Unexpected output fields from running code: {'stderr'}
"onnx/examples/np_array_tensorproto.ipynb"
];
# The executables are just utility scripts that aren't too important # The executables are just utility scripts that aren't too important
postInstall = '' postInstall = ''
rm -r $out/bin rm -r $out/bin
@ -76,6 +89,35 @@ buildPythonPackage rec {
# The setup.py does all the configuration # The setup.py does all the configuration
dontUseCmakeConfigure = true; dontUseCmakeConfigure = true;
doCheck = true;
preCheck = ''
export HOME=$(mktemp -d)
# detecting source dir as a python package confuses pytest
mv onnx/__init__.py onnx/__init__.py.hidden
'';
pytestFlagsArray = [ "onnx/test" "onnx/examples" ];
disabledTests = [
# attempts to fetch data from web
"test_bvlc_alexnet_cpu"
"test_densenet121_cpu"
"test_inception_v1_cpu"
"test_inception_v2_cpu"
"test_resnet50_cpu"
"test_shufflenet_cpu"
"test_squeezenet_cpu"
"test_vgg19_cpu"
"test_zfnet512_cpu"
];
disabledTestPaths = [
# Unexpected output fields from running code: {'stderr'}
"onnx/examples/np_array_tensorproto.ipynb"
];
postCheck = ''
# run "cpp" tests
.setuptools-cmake-build/onnx_gtests
'';
pythonImportsCheck = [ pythonImportsCheck = [
"onnx" "onnx"
]; ];