Debian Codegraph @

src/bonsai/Makefile

raw
1 # Bonsai - OpenBIM Blender Add-on
2 # Copyright (C) 2020-2023 Dion Moult <[email protected]>
3 #
4 # This file is part of Bonsai.
5 #
6 # Bonsai is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Bonsai is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
18
19 PYTHON:=python3.11
20 PIP:=pip3.11
21 PATCH:=patch
22 SED:=sed -i
23 VENV_ACTIVATE:=bin/activate
24
25 ifeq ($(OS),Windows_NT)
26 HOSTOS:=win
27 PYTHON:=python
28 VENV_ACTIVATE:=Scripts/activate
29 else
30 UNAME_S:=$(shell uname -s)
31 ifeq ($(UNAME_S),Linux)
32 HOSTOS:=linux
33 endif
34 ifeq ($(UNAME_S),Darwin)
35 HOSTOS:=macos
36 PYTHON:=python3
37 PATCH:=patch -d
38 SED:=sed -i '' -e
39 endif
40 endif
41
42 IS_STABLE:=FALSE
43 VERSION:=$(shell cat ../../VERSION)
44 VERSION_MAJOR:=$(shell cat '../../VERSION' | cut -d '.' -f 1)
45 VERSION_MINOR:=$(shell cat '../../VERSION' | cut -d '.' -f 2)
46 VERSION_PATCH:=$(shell cat '../../VERSION' | cut -d '.' -f 3)
47 VERSION_DATE:=$(shell date '+%y%m%d')
48 LAST_COMMIT_HASH:=$(shell git rev-parse HEAD)
49 LAST_COMMIT_DATE:=$(shell git show -s --format=%cI)
50 PYVERSION:=py310
51 PYPI_IMP:=cp
52
53 ifeq ($(PYVERSION), py311)
54 PYLIBDIR:=python3.11
55 PYNUMBER:=311
56 PYPI_VERSION:=3.11
57 endif
58 ifeq ($(PYVERSION), py312)
59 PYLIBDIR:=python3.12
60 PYNUMBER:=312
61 PYPI_VERSION:=3.12
62 endif
63
64 ifeq ($(PLATFORM), linux)
65 PYPI_PLATFORM:=--platform manylinux_2_17_x86_64
66 BLENDER_PLATFORM:=linux-x64
67 endif
68
69 ifeq ($(PLATFORM), macos)
70 ifeq ($(PYVERSION), py311)
71 PYPI_PLATFORM:=--platform macosx_10_10_x86_64
72 else
73 PYPI_PLATFORM:=--platform macosx_10_13_x86_64
74 endif
75 BLENDER_PLATFORM:=macos-x64
76 endif
77
78 ifeq ($(PLATFORM), macosm1)
79 PYPI_PLATFORM:=--platform macosx_11_0_arm64
80 BLENDER_PLATFORM:=macos-arm64
81 endif
82
83 ifeq ($(PLATFORM), win)
84 PYPI_PLATFORM:=--platform win_amd64
85 BLENDER_PLATFORM:=windows-x64
86 endif
87
88 # Current build commit hash.
89 OLD:=c49ca69
90 .PHONY: bump
91 bump:
92 ifndef NEW
93 $(error ERROR: 'NEW' variable is not set (should be set with new commmit hash). Example use for 'bump' command: 'make bump NEW=0123456'.)
94 endif
95 cd . && $(SED) -b "s/$(OLD)/$(NEW)/" Makefile
96 cd ../ifcopenshell-python/ && $(SED) -b "s/$(OLD)/$(NEW)/" Makefile
97
98 .PHONY: dist
99 dist:
100 ifndef PLATFORM
101 $(error PLATFORM is not set)
102 endif
103 rm -rf build
104 mkdir -p build
105 mkdir -p dist
106 cp -r bonsai build/
107
108 # To scope any build-time dependencies
109 cd build && $(PYTHON) -m venv env && . env/$(VENV_ACTIVATE) && $(PIP) install build
110 cd build && . env/$(VENV_ACTIVATE) && $(PIP) install wheel
111
112 mkdir -p build/wheels
113 # Provides IfcOpenShell Python functionality
114 cd ../ifcopenshell-python && make dist PLATFORM=$(PLATFORM)64 PYVERSION=$(PYVERSION) && mv dist/*.whl ../bonsai/build/wheels/
115 cd ../bcf && make dist && mv dist/*.whl ../bonsai/build/wheels/
116 cd ../ifcclash && make dist && mv dist/*.whl ../bonsai/build/wheels/
117 cd ../ifctester && make dist && mv dist/*.whl ../bonsai/build/wheels/
118 cd ../ifcfm && make dist && mv dist/*.whl ../bonsai/build/wheels/
119 cd ../bsdd && make dist && mv dist/*.whl ../bonsai/build/wheels/
120 cd ../ifcdiff && make dist && mv dist/*.whl ../bonsai/build/wheels/
121 cd ../ifccsv && make dist && mv dist/*.whl ../bonsai/build/wheels/
122 cd ../ifcpatch && make dist && mv dist/*.whl ../bonsai/build/wheels/
123 cd ../ifc4d && make dist && mv dist/*.whl ../bonsai/build/wheels/
124 cd ../ifc5d && make dist && mv dist/*.whl ../bonsai/build/wheels/
125 cd ../ifccityjson && make dist && mv dist/*.whl ../bonsai/build/wheels/
126 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download GitPython --dest=./wheels
127 # Provides audio playback for costing
128 # This is a REALLY IMPORTANT feature
129 cd build && . env/$(VENV_ACTIVATE) && $(PIP) wheel git+https://github.com/Andrej730/aud.git --wheel-dir=./wheels
130 # IfcOpenShell dependency - support for new typing features
131 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download typing_extensions --dest=./wheels
132 # Required by IfcCSV
133 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pandas $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
134 # Pandas ships with very heavy tests
135 # cd build/site-packages/pandas && rm -rf tests
136 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download openpyxl --dest=./wheels
137 # odfpy doesn't come with its own wheel, so whee'l (get it?) create it ourselves!
138 cd build && . env/$(VENV_ACTIVATE) && $(PIP) wheel odfpy --wheel-dir=./wheels
139 # Required by IFCCityJSON
140 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download cjio --dest=./wheels
141 # Required in general for sorting all sorts of stuff in a nice way
142 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download natsort --dest=./wheels
143 # Provides express rule validation for ifcopenshell.validate
144 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pytest --dest=./wheels
145 # Provides Brickschema functionality
146 # Is not platform specific but has platform specific dependencies.
147 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download "brickschema[persistence]==0.7.6a2" $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
148 # Required for SVG to DXF conversion
149 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download ezdxf $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
150 # Required by bcf
151 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download xsdata --dest=./wheels
152 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download xmlschema --dest=./wheels
153 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download elementpath --dest=./wheels
154 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download six --dest=./wheels
155 # Required by drawing module
156 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download lxml $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
157 # Required by qto and drawing module
158 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download shapely $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
159 # Required by the BIM type manager thumbnail generator
160 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pillow $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
161 # Provides mustache templating in construction docs and web UI data
162 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pystache --dest=./wheels
163 # Provides SVG export in construction documentation
164 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download svgwrite --dest=./wheels
165 # Provides fuzzy date parsing for construction sequencing
166 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download python-dateutil --dest=./wheels
167 # Provides duration parsing for construction sequencing
168 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download isodate --dest=./wheels
169 # Provides networkx graph analysis for project dependency calculations
170 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download networkx --dest=./wheels
171 # Required by IFCDiff
172 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download deepdiff --dest=./wheels
173 # Required by IFCCSV and ifcopenshell.util.selector
174 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download lark --dest=./wheels
175 # Required by IFC4D
176 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download PyP6Xer --dest=./wheels
177 # Required by web module
178 # Is not platform specific but has platform specific dependencies.
179 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download python-socketio[asyncio_client] $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
180 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download aiohttp $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
181 # Required to access platform specific paths
182 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download platformdirs --dest=./wheels
183 # Required by light module
184 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pytz --dest=./wheels
185 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download tzfpy $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
186 # pyradiance is using different platform versions than defaults in our makefile.
187 ifeq ($(PLATFORM), linux)
188 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pyradiance --platform manylinux_2_35_x86_64 --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
189 else ifeq ($(PLATFORM), macos)
190 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pyradiance --platform macosx_10_13_x86_64 --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
191 else
192 cd build && . env/$(VENV_ACTIVATE) && $(PIP) download pyradiance $(PYPI_PLATFORM) --python-version $(PYPI_VERSION) --implementation $(PYPI_IMP) --only-binary=:all: --dest=./wheels
193 endif
194
195 # Provides jsgantt-improved supports for web-based construction sequencing gantt charts
196 cd build/bonsai/bim/data/gantt/ && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.js
197 cd build/bonsai/bim/data/gantt/ && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.css
198
199 # Provides IFCJSON functionality
200 # TODO: replace with main repo if https://github.com/IFCJSON-Team/IFC2JSON_python/pull/3 is merged.
201 cd build && wget -O ifc2json.zip https://github.com/Moult/IFC2JSON_python/archive/refs/heads/feature-ios-v0.8.0.zip
202 cd build && unzip ifc2json.zip && rm ifc2json.zip
203 # IFCJSON doesn't have pyproject.toml, so we use python command.
204 cd build && . env/$(VENV_ACTIVATE) && cd IFC2JSON_python-*/file_converters && \
205 $(PYTHON) -c "from setuptools import setup; \
206 setup( \
207 name='ifcjson', \
208 version='0.0.1', \
209 author='Jan Brouwer', \
210 author_email='[email protected]', \
211 packages=['ifcjson'], \
212 )" bdist_wheel
213 cp -r build/IFC2JSON_python-*/file_converters/dist/*.whl build/wheels/
214
215 # Brickschema requires pkg_resources which is provided by Blender.
216 # Provides Brickschema functionality
217 # For now lets bundle the latest nightly schema
218 cd build/bonsai/bim/data/brick/ && wget https://github.com/BrickSchema/Brick/releases/download/nightly/Brick.ttl
219
220 # Required for hipped roof generation
221 cd build && wget https://github.com/prochitecture/bpypolyskel/archive/refs/heads/master.zip
222 cd build && unzip master.zip && rm master.zip
223 cd build && . env/$(VENV_ACTIVATE) && cd bpypolyskel-master && \
224 $(PYTHON) -c "from setuptools import setup; \
225 setup( \
226 name='bpypolyskel', \
227 version='0.0.0', \
228 packages=['bpypolyskel'], \
229 )" bdist_wheel
230 cp -r build/bpypolyskel-master/dist/*.whl build/wheels/
231
232 # folder for executable files
233 mkdir -p build/bonsai/libs/bin
234
235 # required for three-way git merging
236 ifeq ($(PLATFORM), win)
237 cd build/bonsai/libs/bin && wget https://github.com/brunopostle/ifcmerge/releases/download/2025-01-26/ifcmerge.zip
238 cd build/bonsai/libs/bin && unzip ifcmerge.zip && rm ifcmerge.zip
239 else
240 cd build/bonsai/libs/bin && wget https://raw.githubusercontent.com/brunopostle/ifcmerge/main/ifcmerge && chmod +x ifcmerge
241 endif
242
243 # Generate translations module for Bonsai build
244 git clone https://github.com/IfcOpenShell/bonsai-translations.git build/working
245 $(PYTHON) scripts/bonsai_translations.py -i "build/working" -o "build/bonsai"
246 rm -rf build/working
247
248 # Remove dependencies also bundled with Blender
249 rm -rf build/wheels/numpy*
250
251 cp pyproject.toml build/
252 ifeq ($(IS_STABLE), TRUE)
253 $(SED) "s/0.0.0/$(VERSION)/" build/bonsai/blender_manifest.toml
254 $(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' build/pyproject.toml
255 else
256 $(SED) "s/0.0.0/$(VERSION)-alpha$(VERSION_DATE)/" build/bonsai/blender_manifest.toml
257 $(SED) "s/8888888/$(LAST_COMMIT_HASH)/" build/bonsai/__init__.py
258 $(SED) "s/9999999/$(LAST_COMMIT_DATE)/" build/bonsai/__init__.py
259 $(SED) 's/version = "0.0.0"/version = "$(VERSION)-alpha$(VERSION_DATE)"/' build/pyproject.toml
260 endif
261
262 $(SED) "s/os-arch/$(BLENDER_PLATFORM)/" build/bonsai/blender_manifest.toml
263
264 # Provides bonsai Add-on functionality
265 ifeq ($(IS_STABLE), TRUE)
266 $(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' build/pyproject.toml
267 else
268 $(SED) 's/version = "0.0.0"/version = "$(VERSION)a$(VERSION_DATE)"/' build/pyproject.toml
269 endif
270 cd build && . env/$(VENV_ACTIVATE) && $(PYTHON) -m build
271 cp build/dist/*.whl build/wheels/
272
273 # Safeguard for non-wheel dependencies slipping in.
274 wheels=$$(find build/wheels/* ! -name "*.whl"); \
275 if [ -n "$$wheels" ]; then \
276 echo "Found non-wheel dependencies:"; \
277 echo "$$wheels"; \
278 echo "Error: non-wheel dependencies are not supported by Blender!"; \
279 exit 1; \
280 fi
281 mv build/wheels/*.whl build/bonsai/wheels/
282
283 # Temporary workaround for Blender not handling non-3.11 wheels #5743.
284 # Use '-n' as on macos x86-64 doesn't have a binary wheel and it autoincludes 'cp311'.
285 prev_whl_name=$$(find build/bonsai/wheels/tzfpy-*.whl); \
286 whl_name=$$(echo $$prev_whl_name | sed "s/-cp39-/-cp$(PYNUMBER)-/"); \
287 mv --update=none "$$prev_whl_name" "$$whl_name";
288
289 ifneq ($(PLATFORM), linux)
290 # Safeguard: in case one of `pip download` will break,
291 # it will produce a linux wheel for non-linux build (our github action machine is using linux).
292 wheels=$$(find build/bonsai/wheels/*manylinux_*.whl); \
293 if [ -n "$$wheels" ]; then \
294 echo "Found linux wheel files in non-linux build:"; \
295 echo "$$wheels"; \
296 echo "Error: linux wheels are incompatible with build $(PLATFORM)!"; \
297 exit 1; \
298 fi
299 endif
300
301 $(PYTHON) scripts/get_wheels.py build/bonsai/wheels build/bonsai/blender_manifest.toml
302 rm -rf build/bonsai/bim/
303 rm -rf build/bonsai/core/
304 rm -rf build/bonsai/tool/
305 rm -rf build/bonsai/libs/
306
307 ifeq ($(IS_STABLE), TRUE)
308 cd build && zip -r bonsai_$(PYVERSION)-$(VERSION)-$(BLENDER_PLATFORM).zip ./bonsai
309 else
310 cd build && zip -r bonsai_$(PYVERSION)-$(VERSION)-alpha$(VERSION_DATE)-$(BLENDER_PLATFORM).zip ./bonsai
311 endif
312
313 mv build/bonsai*.zip dist/
314
315 rm -rf build
316
317 .PHONY: test
318 test:
319 @echo "Running all tests..."
320 @ERROR=0; \
321 make test-core || ERROR=1; \
322 make test-tool || ERROR=1; \
323 make test-bim || ERROR=1; \
324 if [ $$ERROR -ne 0 ]; then \
325 echo "One or more tests failed"; \
326 exit 1; \
327 fi
328
329 .PHONY: test-core
330 test-core:
331 pytest -p no:pytest-blender test/core
332
333 .PHONY: test-bim
334 test-bim:
335 ifndef MODULE
336 pytest test/bim
337 else
338 pytest test/bim -m "$(MODULE)" ./ --maxfail=1
339 endif
340
341 .PHONY: test-tool
342 test-tool:
343 ifndef MODULE
344 pytest test/tool
345 else
346 pytest test/tool/test_$(MODULE).py
347 endif
348
349 # Reregistering test is not added to the standard test suite because during unregister
350 # Blender removes all Bonsai dependencies breaking dev-environment symlinks.
351 .PHONY: test-reregister
352 test-reregister:
353 blender --python scripts/reregister_bonsai.py
354
355 .PHONY: qa
356 qa:
357 black .
358 pylint ./* --output-format=colorized --disable all --enable E --disable import-error
359
360 .PHONY: coverage
361 coverage:
362 coverage run --source bonsai.core -m pytest -p no:pytest-blender test/core
363 coverage html
364 xdg-open htmlcov/index.html
365
366 .PHONY: license
367 license:
368 copyright-header --license GPL3 --copyright-holder "Dion Moult <[email protected]>" --copyright-year "2022" --copyright-software "Bonsai" --copyright-software-description "OpenBIM Blender Add-on" -a ./ -o ./
369
370 .PHONY: clean
371 clean:
372 rm -rf dist
373 rm -rf htmlcov
374
375 .PHONY: dev
376 dev:
377 blender -p setup_pytest.py