From 640e0fcf028ef2525f0c90bb1965a120680522b2 Mon Sep 17 00:00:00 2001 From: Augustin Trancart Date: Wed, 17 Jul 2024 10:39:36 +0200 Subject: [PATCH] ifcopenshell: fix build and use relevant release By relevant release, I mean the ifcopenshell-python release, and not the blenderbim release --- .../python-modules/ifcopenshell/default.nix | 127 ++++++++++++++++-- pkgs/top-level/all-packages.nix | 2 - pkgs/top-level/python-packages.nix | 4 +- 3 files changed, 117 insertions(+), 16 deletions(-) diff --git a/pkgs/development/python-modules/ifcopenshell/default.nix b/pkgs/development/python-modules/ifcopenshell/default.nix index 6e17149079cf664..3bcf1594798d5a1 100644 --- a/pkgs/development/python-modules/ifcopenshell/default.nix +++ b/pkgs/development/python-modules/ifcopenshell/default.nix @@ -1,53 +1,97 @@ { lib, stdenv, + testers, buildPythonPackage, + # fetchers fetchFromGitHub, - gcc10, + # testers + runCommand, + # native dep + python3, + # build tools cmake, + gcc10, + swig, + # dependencies + eigen, boost179, + cgal, + gmp, + hdf5, icu, - swig, - pcre, + libaec, + libxml2, + mpfr, + nlohmann_json, opencascade-occt_7_6, opencollada, - libxml2, + pcre, + zlib, + # for tests + # python deps + python3Packages, + setuptools, + build, + wheel, }: let opencascade-occt = opencascade-occt_7_6; in buildPythonPackage rec { pname = "ifcopenshell"; - version = "240611"; + version = "0.7.10"; format = "other"; src = fetchFromGitHub { owner = "IfcOpenShell"; repo = "IfcOpenShell"; - rev = "refs/tags/blenderbim-${version}"; + rev = "refs/tags/ifcopenshell-python-${version}"; fetchSubmodules = true; - hash = "sha256-fCgxSambC01qb14EoZTrVxNNw8H3nX8oMi6gk0O/HmQ="; + hash = ""; }; nativeBuildInputs = [ - gcc10 + # c++ cmake + gcc10 + swig + # python + build + python3 + setuptools + wheel ]; + pythonImportsCheck = [ "ifcopenshell" ]; + buildInputs = [ + # ifcopenshell needs stdc++ + stdenv.cc.cc.lib boost179 + cgal + eigen + gmp + hdf5 icu - pcre + libaec libxml2 + mpfr + nlohmann_json + opencascade-occt + pcre ]; - preConfigure = '' - cd cmake - ''; - PYTHONUSERBASE = "."; + + # We still build with python to generate ifcopenshell_wrapper.py and ifcopenshell_wrapper.so cmakeFlags = [ "-DUSERSPACE_PYTHON_PREFIX=ON" + "-DBUILD_SHARED_LIBS=ON" + "-DBUILD_IFCPYTHON=ON" + "-DCITYJSON_SUPPORT=OFF" + "-DEIGEN_DIR=${eigen}/include/eigen3" + "-DJSON_INCLUDE_DIR=${nlohmann_json}/include/" "-DOCC_INCLUDE_DIR=${opencascade-occt}/include/opencascade" "-DOCC_LIBRARY_DIR=${opencascade-occt}/lib" "-DOPENCOLLADA_INCLUDE_DIR=${opencollada}/include/opencollada" @@ -55,8 +99,58 @@ buildPythonPackage rec { "-DSWIG_EXECUTABLE=${swig}/bin/swig" "-DLIBXML2_INCLUDE_DIR=${libxml2.dev}/include/libxml2" "-DLIBXML2_LIBRARIES=${libxml2.out}/lib/libxml2${stdenv.hostPlatform.extensions.sharedLibrary}" + "-DGMP_LIBRARY_DIR=${gmp.out}/lib/" + "-DMPFR_LIBRARY_DIR=${mpfr.out}/lib/" + # HDF5 support is currently not optional, see https://github.com/IfcOpenShell/IfcOpenShell/issues/1815 + "-DHDF5_SUPPORT=ON" + "-DHDF5_INCLUDE_DIR=${hdf5.dev}/include/" + "-DHDF5_LIBRARIES=${hdf5.out}/lib/libhdf5_cpp.so;${hdf5.out}/lib/libhdf5.so;${zlib.out}/lib/libz.so;${libaec.out}/lib/libaec.so;" # /usr/lib64/libsz.so;" ]; + preConfigure = '' + pushd src/ifcopenshell-python + # The build process is here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/Makefile#L131 + # but we'd have to patch the copied pyproject.toml anyway, as the version is incorrect (even after their `make dist` btw), and the `where = ["dist"]` does not apply to us. + # so let's just create it from scratch + cat << EOF > pyproject.toml + [build-system] + requires = ["setuptools>=61.0"] + build-backend = "setuptools.build_meta" + [project] + name = "ifcopenshell" + version = "${version}" + authors = [ + { name="Dion Moult", email="dion@thinkmoult.com" }, + ] + description = "Python bindings, utility functions, and high-level API for IfcOpenShell" + readme = "README.md" + requires-python = ">=3.6,<3.12" + classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", + ] + [project.optional-dependencies] + geometry = ["mathutils", "shapely"] + date = ["isodate"] + [project.urls] + "Homepage" = "http://ifcopenshell.org" + "Bug Tracker" = "https://github.com/ifcopenshell/ifcopenshell/issues" + [tool.setuptools.packages.find] + include = ["ifcopenshell*"] + [tool.setuptools.package-data] + ifcopenshell = ["*.pyd", "*.so", "*.json"] + "ifcopenshell.util" = ["*.json", "schema/*.ifc"] + EOF + # NOTE: the following is directly inspired by https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/Makefile#L131 + # these 2 files are wrapper over a C api. They are put in the python3.12 in the ifcopenshell cmake build process folder + # because the default python3 is 3.11 at the time of writing this, but AFAIK there is nothing specific to 3.11 here. + # distutils cannot access anything outside the cwd, so hackishly swap out the README.md + cp README.md ../README.bak + cp ../../README.md README.md + popd + cd cmake + ''; + meta = with lib; { broken = stdenv.isDarwin; description = "Open source IFC library and geometry engine"; @@ -64,4 +158,11 @@ buildPythonPackage rec { license = licenses.lgpl3; maintainers = with maintainers; [ fehnomenal ]; }; + + passthru.tests = { + version = testers.testVersion { + # package = ifcopenshell; + command = "IfcConvert --version"; + }; + }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 24c05bba8f60531..95fab118b2720c7 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8957,8 +8957,6 @@ with pkgs; idle3tools = callPackage ../tools/system/idle3tools { }; - ifcopenshell = with python3Packages; toPythonApplication ifcopenshell; - iftop = callPackage ../tools/networking/iftop { }; ifwifi = callPackage ../tools/networking/ifwifi { diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index d6400d36b33200d..cd40101628f989d 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -5804,7 +5804,9 @@ self: super: with self; { ifconfig-parser = callPackage ../development/python-modules/ifconfig-parser { }; - ifcopenshell = callPackage ../development/python-modules/ifcopenshell { }; + ifcopenshell = callPackage ../development/python-modules/ifcopenshell { + inherit (pkgs) libxml2; + }; ignite = callPackage ../development/python-modules/ignite { };