Skip to content

Commit d4ac48f

Browse files
committed
Merge remote-tracking branch 'origin/artist-factory' into artist-factory
2 parents 072f200 + bda3497 commit d4ac48f

File tree

9 files changed

+147
-24
lines changed

9 files changed

+147
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
* Added `draw_node_labels` and `draw_edgelabels` to `compas_blender.artists.NetworkArtist`.
2424
* Added `compas_blender.artists.RobotModelArtist.clear`.
2525
* Added `compas_blender.geometry.booleans` as plugin for boolean pluggables.
26+
* Added version-based installation for Blender.
2627

2728
### Changed
2829

@@ -34,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3435
* `compas_blender.artists.RobotModelArtist.collection` can be assigned as a Blender collection or a name.
3536
* Generalized the parameter `color` of `compas_blender.draw_texts` and various label drawing methods.
3637
* Changed `compas.IPY` to `compas.RHINO` in `orientation_rhino`.
38+
* Changed `planarity` to `requires_extra` for pip installations.
3739

3840
### Removed
3941

docs/gettingstarted/blender.rst

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ the version of the bundled Python is 3.7, and for 2.93 LTS it is 3.9.
2222
Installation
2323
============
2424

25-
These instructions are for the latest Blender 2.83 LTS which ships with Python 3.7
26-
If you don't have an environment yet with Python 3.7 and COMPAS you can create one with ``conda``.
25+
These instructions are for the latest Blender 2.93 LTS which ships with Python 3.9
26+
If you don't have an environment yet with Python 3.9 and COMPAS you can create one with ``conda``.
2727

2828
.. code-block:: bash
2929
3030
conda config --add channels conda-forge
31-
conda create -n blender python=3.7 COMPAS --yes
31+
conda create -n blender python=3.9 COMPAS --yes
3232
3333
Configuring Blender to use the newly installed environment is slightly different per OS.
3434

@@ -58,9 +58,9 @@ Configuring Blender to use the newly installed environment is slightly different
5858
.. code-block:: bash
5959
6060
conda activate blender
61-
python -m compas_blender.install "%PROGRAMFILES%\\Blender Foundation\\Blender 2.83\\2.83"
61+
python -m compas_blender.install "%PROGRAMFILES%\\Blender Foundation\\Blender 2.93\\2.93"
6262
63-
Note that the path ``%PROGRAMFILES%\\Blender Foundation\\Blender 2.83\\2.83`` might be different on your system.
63+
Note that the path ``%PROGRAMFILES%\\Blender Foundation\\Blender 2.93\\2.93`` might be different on your system.
6464
Check your Blender installation and change the path accordingly.
6565

6666
.. raw:: html
@@ -71,9 +71,9 @@ Check your Blender installation and change the path accordingly.
7171
.. code-block:: bash
7272
7373
conda activate blender
74-
python -m compas_blender.install /Applications/blender.app/Contents/Resources/2.83
74+
python -m compas_blender.install /Applications/blender.app/Contents/Resources/2.93
7575
76-
Note that the path ``/Applications/blender.app/Contents/Resources/2.83`` might be different on your system.
76+
Note that the path ``/Applications/blender.app/Contents/Resources/2.93`` might be different on your system.
7777
Check your Blender installation and change the path accordingly.
7878

7979
.. raw:: html
@@ -84,9 +84,9 @@ Check your Blender installation and change the path accordingly.
8484
.. code-block:: bash
8585
8686
conda activate blender
87-
python -m compas_blender.install ~/Blender/2.83
87+
python -m compas_blender.install ~/Blender/2.93
8888
89-
Note that the path ``~/Blender/2.83`` might be different on your system.
89+
Note that the path ``~/Blender/2.93`` might be different on your system.
9090
Check your Blender installation and change the path accordingly.
9191

9292
.. raw:: html
@@ -99,6 +99,14 @@ Check your Blender installation and change the path accordingly.
9999
</div>
100100
</div>
101101

102+
On Windows and OSX, if Blender is installed in the default location, you can simply provide the version number.
103+
104+
.. code-block:: bash
105+
106+
conda activate blender
107+
python -m compas_blender.install -v 2.93
108+
109+
102110
Add-ons
103111
=======
104112

@@ -287,3 +295,30 @@ Artists are currently only available for data structures and robots.
287295

288296
There is also no official system yet for making custom COMPAS tools in Blender.
289297
Therefore, COMPAS Blender development is somewhat limited to individual scripts.
298+
299+
Known Issues
300+
============
301+
302+
On Windows, Blender sometimes has issues with finding NumPy libraries.
303+
If this is the case, the problem can usually be solved by reinstalling NumPy in your environment using ``pip``.
304+
However, to avoid issues with other packages that were already installed and depend on a specific version of NumPy,
305+
you should install the same version as the one installed originally by ``conda``.
306+
307+
.. code-block:: bash
308+
309+
python -c "import numpy; print(numpy.__version__)"
310+
311+
If the above is, for example, ``1.20.3``
312+
313+
.. code-block:: bash
314+
315+
pip install --force-reinstall numpy==1.20.3
316+
317+
Alternatively, you can create a new environment and simply install entire COMPAS using ``pip``.
318+
319+
.. code-block:: bash
320+
321+
conda create -n blender python=3.9 cython planarity --yes
322+
conda activate blender
323+
pip install compas
324+
python -m compas_blender.install

docs/installation.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ Note that installation with ``pip`` is also possible within a ``conda`` environm
7979
conda activate my-project
8080
pip install -e .
8181
82+
By default, ``planarity`` is marked as an optional requirement for installation with ``pip`` on Windows.
83+
To include ``planarity``, add a conditional to the install command.
84+
85+
.. code-block:: bash
86+
87+
pip install compas[planarity]
88+
89+
.. code-block:: bash
90+
91+
pip install -e .[planarity]
92+
8293
8394
Update with conda
8495
=================

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ networkx
1212
numba
1313
numpy >= 1.15.4
1414
pillow
15-
planarity
15+
planarity ; sys_platform != 'win32'
1616
pycollada
1717
schema
1818
jsonschema

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def read(*names, **kwargs):
6666
zip_safe=False,
6767
install_requires=requirements,
6868
python_requires='>=2.7',
69-
extras_require=optional_requirements,
69+
extras_require={
70+
'planarity': ['planarity'],
71+
},
7072
entry_points={
7173
'console_scripts': [
7274
'compas_rpc=compas.rpc.__main__:main'

src/compas/datastructures/network/planarity.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88

99
from itertools import product
1010

11-
import compas
12-
1311
from compas.geometry import angle_vectors_xy
1412
from compas.geometry import is_intersection_segment_segment_xy
1513
from compas.geometry import is_ccw_xy
1614
from compas.geometry import subtract_vectors_xy
1715

18-
if not compas.IPY:
19-
import planarity
20-
2116

2217
__all__ = [
2318
'network_is_crossed',
@@ -198,6 +193,12 @@ def network_is_planar(network):
198193
--------
199194
>>>
200195
"""
196+
try:
197+
import planarity
198+
except ImportError:
199+
print("Planarity is not installed.")
200+
raise
201+
201202
return planarity.is_planar(list(network.edges()))
202203

203204

src/compas_blender/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
compas_blender.utilities
1515
1616
"""
17+
import os
18+
import compas
19+
1720
try:
1821
import bpy # noqa: F401
1922
except ImportError:
@@ -50,6 +53,42 @@ def redraw():
5053
__version__ = '1.8.1'
5154

5255

56+
def _check_blender_version(version):
57+
supported_versions = ['2.83', '2.93']
58+
59+
if not version:
60+
return '2.93'
61+
62+
if version not in supported_versions:
63+
raise Exception('Unsupported Blender version: {}'.format(version))
64+
65+
return version
66+
67+
68+
def _get_default_blender_installation_path(version):
69+
version = _check_blender_version(version)
70+
71+
if compas.OSX:
72+
path = _get_default_blender_installation_path_mac(version)
73+
elif compas.WINDOWS:
74+
path = _get_default_blender_installation_path_windows(version)
75+
else:
76+
raise Exception('Unsupported platform.')
77+
78+
if not os.path.exists(path):
79+
raise Exception("The default installation folder for Blender {} doesn't exist.".format(version))
80+
81+
return path
82+
83+
84+
def _get_default_blender_installation_path_mac(version):
85+
return '/Applications/Blender.app/Contents/Resources/{}'.format(version)
86+
87+
88+
def _get_default_blender_installation_path_windows(version):
89+
return os.path.expandvars('%PROGRAMFILES%/Blender Foundation/Blender {}/{}'.format(version, version))
90+
91+
5392
__all__ = [name for name in dir() if not name.startswith('_')]
5493

5594
__all_plugins__ = [

src/compas_blender/install.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import sys
33
import tempfile
44

5+
import compas
6+
import compas_blender
7+
58
from compas._os import copy
69
from compas._os import create_symlinks
710
from compas._os import remove
@@ -41,27 +44,52 @@ def unregister():
4144
"""
4245

4346

44-
def install(blender_path):
47+
def install(blender_path, version=None):
4548
"""Install COMPAS for Blender.
4649
4750
Parameters
4851
----------
4952
blender_path : str
5053
The path to the folder with the version number of Blender.
5154
For example, on Mac: ``'/Applications/Blender.app/Contents/Resources/2.83'``.
52-
On Windows: ``'%PROGRAMFILES%\\Blender Foundation\\Blender\\2.83'``.
55+
On Windows: ``'%PROGRAMFILES%/Blender Foundation/Blender 2.83/2.83'``.
56+
version : {'2.83', '2.93'}, optional
57+
The version number of Blender.
58+
Default is ``'2.93'``.
5359
5460
Examples
5561
--------
5662
.. code-block:: bash
5763
58-
$ python -m compas_blender.install /Applications/Blender.app/Contents/Resources/2.83
64+
$ python -m compas_blender.install
65+
66+
.. code-block:: bash
67+
68+
$ python -m compas_blender.install -v 2.93
69+
70+
.. code-block:: bash
71+
72+
$ python -m compas_blender.install /Applications/Blender.app/Contents/Resources/2.93
5973
6074
"""
6175
if not os.environ.get('CONDA_PREFIX'):
6276
print('Conda environment not found. The installation into Blender requires an active conda environment with a matching Python version to continue.')
6377
sys.exit(-1)
6478

79+
if not version and not blender_path:
80+
version = '2.93'
81+
82+
if version and blender_path:
83+
print('Both options cannot be provided simultaneously. Provide the full installation path, or the version with flag -v.')
84+
sys.exit(-1)
85+
86+
if version:
87+
if compas.LINUX:
88+
print('Version-based installs are currently not supported for Linux. Please provide the full installation path with the -p option.')
89+
sys.exit(-1)
90+
91+
blender_path = compas_blender._get_default_blender_installation_path(version)
92+
6593
if not os.path.exists(blender_path):
6694
raise FileNotFoundError('Blender version folder not found.')
6795

@@ -122,7 +150,9 @@ def install(blender_path):
122150

123151
parser = argparse.ArgumentParser()
124152

125-
parser.add_argument('versionpath', help="The path to the folder with the version number of Blender.")
153+
parser.add_argument('blenderpath', nargs='?', help="The path to the folder with the version number of Blender.")
154+
parser.add_argument('-v', '--version', choices=['2.83', '2.93'], help="The version of Blender to install COMPAS in.")
155+
126156
args = parser.parse_args()
127157

128-
install(args.versionpath)
158+
install(args.blenderpath, version=args.version)

tests/compas/datastructures/test_network.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22

3-
import compas
43
from compas.datastructures import Network
54

65

@@ -33,15 +32,19 @@ def test_add_node():
3332

3433

3534
def test_non_planar(k5_network):
36-
if compas.IPY:
35+
try:
36+
import planarity # noqa: F401
37+
except ImportError:
3738
return
3839

3940
from compas.datastructures import network_is_planar
4041
assert network_is_planar(k5_network) is not True
4142

4243

4344
def test_planar(k5_network):
44-
if compas.IPY:
45+
try:
46+
import planarity # noqa: F401
47+
except ImportError:
4548
return
4649

4750
from compas.datastructures import network_is_planar

0 commit comments

Comments
 (0)