1{
2 lib,
3 stdenv,
4 testers,
5 buildPythonPackage,
6 pythonOlder,
7 python,
8 pytestCheckHook,
9 # fetchers
10 fetchFromGitHub,
11 fetchpatch,
12 gitUpdater,
13 # build tools
14 cmake,
15 swig,
16 # native dependencies
17 eigen,
18 boost,
19 cgal_5,
20 gmp,
21 hdf5,
22 icu,
23 libaec,
24 libxml2,
25 mpfr,
26 nlohmann_json,
27 opencascade-occt_7_6,
28 opencollada,
29 pcre,
30 zlib,
31
32 # python deps
33 ## tools
34 setuptools,
35 build,
36 pytest,
37 ## dependencies
38 isodate,
39 lark,
40 numpy,
41 python-dateutil,
42 shapely,
43 typing-extensions,
44 ## additional deps for tests
45 ifcopenshell,
46 lxml,
47 mathutils,
48 networkx,
49 tabulate,
50 xmlschema,
51 xsdata,
52}:
53let
54 opencascade-occt = opencascade-occt_7_6;
55in
56buildPythonPackage rec {
57 pname = "ifcopenshell";
58 version = "0.8.0";
59 pyproject = false;
60
61 src = fetchFromGitHub {
62 owner = "IfcOpenShell";
63 repo = "IfcOpenShell";
64 tag = "ifcopenshell-python-${version}";
65 fetchSubmodules = true;
66 hash = "sha256-tnj14lBEkUZNDM9J1sRhNA7OkWTWa5JPTSF8hui3q7k=";
67 };
68
69 patches = [
70 (fetchpatch {
71 name = "ifcopenshell-boost-1.86-mt19937.patch";
72 url = "https://github.com/IfcOpenShell/IfcOpenShell/commit/1fe168d331123920eeb9a96e542fcc1453de57fe.patch";
73 hash = "sha256-oZDEL8cPcEu83lW+qSvCbmDGYpaNNRrptW9MLu2pN70=";
74 })
75
76 (fetchpatch {
77 name = "ifcopenshell-boost-1.86-json.patch";
78 url = "https://github.com/IfcOpenShell/IfcOpenShell/commit/88b861737c7c206d0e7307f90d37467e9585515c.patch";
79 hash = "sha256-zMoQcBWRdtavL0xdsr53SqyG6CZoeon8/mmJhrw85lc=";
80 })
81 ];
82
83 nativeBuildInputs = [
84 # c++
85 cmake
86 swig
87 # python
88 build
89 setuptools
90 ];
91
92 buildInputs = [
93 # ifcopenshell needs stdc++
94 (lib.getLib stdenv.cc.cc)
95 boost
96 cgal_5
97 eigen
98 gmp
99 hdf5
100 icu
101 libaec
102 libxml2
103 mpfr
104 nlohmann_json
105 opencascade-occt
106 opencollada
107 pcre
108 ];
109
110 propagatedBuildInputs = [
111 isodate
112 lark
113 numpy
114 python-dateutil
115 shapely
116 typing-extensions
117 ];
118
119 # list taken from .github/workflows/ci.yml:49
120 nativeCheckInputs = [
121 lxml
122 mathutils
123 networkx
124 pytest
125 tabulate
126 xmlschema
127 xsdata
128
129 pytestCheckHook
130 ];
131
132 pythonImportsCheck = [ "ifcopenshell" ];
133
134 PYTHONUSERBASE = ".";
135
136 # We still build with python to generate ifcopenshell_wrapper.py and ifcopenshell_wrapper.so
137 cmakeFlags = [
138 "-DUSERSPACE_PYTHON_PREFIX=ON"
139 "-DBUILD_SHARED_LIBS=ON"
140 "-DBUILD_IFCPYTHON=ON"
141 "-DCITYJSON_SUPPORT=OFF"
142 "-DEIGEN_DIR=${eigen}/include/eigen3"
143 "-DJSON_INCLUDE_DIR=${nlohmann_json}/include/"
144 "-DOCC_INCLUDE_DIR=${opencascade-occt}/include/opencascade"
145 "-DOCC_LIBRARY_DIR=${lib.getLib opencascade-occt}/lib"
146 "-DOPENCOLLADA_INCLUDE_DIR=${opencollada}/include/opencollada"
147 "-DOPENCOLLADA_LIBRARY_DIR=${lib.getLib opencollada}/lib/opencollada"
148 "-DSWIG_EXECUTABLE=${swig}/bin/swig"
149 "-DLIBXML2_INCLUDE_DIR=${libxml2.dev}/include/libxml2"
150 "-DLIBXML2_LIBRARIES=${lib.getLib libxml2}/lib/libxml2${stdenv.hostPlatform.extensions.sharedLibrary}"
151 "-DGMP_LIBRARY_DIR=${lib.getLib gmp}/lib/"
152 "-DMPFR_LIBRARY_DIR=${lib.getLib mpfr}/lib/"
153 # HDF5 support is currently not optional, see https://github.com/IfcOpenShell/IfcOpenShell/issues/1815
154 "-DHDF5_SUPPORT=ON"
155 "-DHDF5_INCLUDE_DIR=${hdf5.dev}/include/"
156 "-DHDF5_LIBRARIES=${lib.getLib hdf5}/lib/libhdf5_cpp.so;${lib.getLib hdf5}/lib/libhdf5.so;${lib.getLib zlib}/lib/libz.so;${lib.getLib libaec}/lib/libaec.so;"
157 ];
158
159 postPatch = ''
160 pushd src/ifcopenshell-python
161 # The build process is here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/Makefile#L131
162 # NOTE: it has changed a *lot* between 0.7.0 and 0.8.0, it *may* change again (look for mathutils and basically all the things this Makefile does manually)
163 substituteInPlace pyproject.toml --replace-fail "0.0.0" "${version}"
164 # NOTE: the following is directly inspired by https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/Makefile#L123
165 cp ../../README.md README.md
166 popd
167 '';
168
169 preConfigure = ''
170 cd cmake
171 '';
172
173 preCheck = ''
174 pushd ../../src/ifcopenshell-python
175 # let's test like done in .github/workflows/ci.yml
176 # installing the python wrapper and the .so, both are needed to be able to test
177 cp -v $out/${python.sitePackages}/ifcopenshell/ifcopenshell_wrapper.py ./ifcopenshell
178 cp $out/${python.sitePackages}/ifcopenshell/_ifcopenshell_wrapper.cpython-${
179 lib.versions.major python.version + lib.versions.minor python.version
180 }-${stdenv.targetPlatform.system}-gnu.so ./ifcopenshell
181 pushd ../../test
182 PYTHONPATH=../src/ifcopenshell-python/ python tests.py
183 popd
184 '';
185
186 pytestFlags = [
187 "-pno:pytest-blender"
188 ];
189
190 disabledTestPaths = [
191 "test/test_open.py"
192 ];
193
194 postCheck = ''
195 popd
196 '';
197
198 passthru = {
199 updateScript = gitUpdater { rev-prefix = "ifcopenshell-python-"; };
200 tests = {
201 version = testers.testVersion {
202 command = "IfcConvert --version";
203 package = ifcopenshell;
204 };
205 };
206 };
207
208 meta = with lib; {
209 broken = stdenv.hostPlatform.isDarwin;
210 description = "Open source IFC library and geometry engine";
211 homepage = "https://ifcopenshell.org/";
212 license = licenses.lgpl3;
213 maintainers = with maintainers; [ autra ];
214 };
215}