1
- #!/usr/bin/python
1
+ #!/usr/bin/python3
2
2
3
3
# -------------------------------------------------------------------------------
4
4
# This file is part of Phobos, a Blender Add-On to edit robot models.
9
9
# -------------------------------------------------------------------------------
10
10
import json
11
11
import os
12
- import sys
13
- import shutil
14
12
import setuptools
15
13
import subprocess
16
14
from pathlib import Path
17
- from copy import deepcopy
18
15
19
16
20
17
# utilities
@@ -30,105 +27,27 @@ def get_git_branch():
30
27
return subprocess .check_output (['git' , 'rev-parse' , '--abbrev-ref' , 'HEAD' ]).strip ().decode ("utf-8" )
31
28
32
29
33
- def check_blender_agreement (answer ):
34
- if not answer .lower () in ["y" , "yes" ]:
35
- print ("Blender installation cancelled!" )
36
- print ("If you want to install the phobos blender "
37
- "add-on later or manually follow the following steps:\n "
38
- "1) Zip the phobos directory in this repository\n "
39
- "2) Open blender\n "
40
- "3) Go to preferences->Add-ons\n "
41
- "4) Click 'Install' and select the freshly zipped phobos.zip file\n "
42
- " Blender will now install the phobos add-on with all its dependencies.\n "
43
- "5) Click the checkbox to activate the phobos-add-on" )
44
- sys .exit ()
45
- return True
46
-
47
-
48
- def exec_shell_cmd (command ):
49
- if sys .platform .startswith ("linux" ):
50
- command = [" " .join (str (x ) for x in command )]
51
- proc = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
52
- (out , err ) = proc .communicate ()
53
- return out .decode ().strip ()
54
-
55
-
56
- def install_requirement (py_exec , package_name , upgrade_pip = False , lib = None ):
57
- # Ensure pip is installed
58
- exec_shell_cmd ([py_exec , "-m" , "ensurepip" , "--user" ])
59
- # Update pip (not mandatory)
60
- if upgrade_pip :
61
- print (" Upgrading pip..." )
62
- exec_shell_cmd ([py_exec , "-m" , "pip" , "install" , "--upgrade" , "pip" ])
63
- # Install package
64
- print (" Installing package" , package_name )
65
- if lib is None :
66
- exec_shell_cmd ([py_exec , "-m" , "pip" , "install" , package_name ])
67
- else :
68
- exec_shell_cmd ([py_exec , "-m" , "pip" , "install" , f"--target={ str (lib )} " , package_name ])
69
-
70
-
71
- def check_requirements (py_exec , optional = False , upgrade_pip = False , lib = None ):
72
- print ("Checking requirements:" )
73
- import importlib
74
- requirements = [
75
- "networkx" ,
76
- "numpy" ,
77
- "scipy" ,
78
- "trimesh" ,
79
- "pydot" ,
80
- "setuptools" ,
81
- "collada"
82
- ]
83
- optional_requirements = [
84
- "pyyaml" ,
85
- "pybullet" ,
86
- "open3d" ,
87
- "python-fcl"
88
- ]
89
- reqs = [requirements ]
90
- if optional :
91
- reqs += [optional_requirements ]
92
- if upgrade_pip :
93
- print (" Upgrading pip..." )
94
- exec_shell_cmd ([py_exec , "-m" , "pip" , "install" , "--upgrade" , "pip" ])
95
- for r in reqs :
96
- for import_name , req_name in r .items ():
97
- print (" Checking" , import_name )
98
- install_requirement (py_exec , req_name , upgrade_pip = False , lib = lib )
99
- # try:
100
- # if importlib.util.find_spec(import_name) is None:
101
- # install_requirement(py_exec, req_name, upgrade_pip=False, lib=lib)
102
- # except AttributeError:
103
- # loader = importlib.find_loader(import_name)
104
- # if not issubclass(type(loader), importlib.machinery.SourceFileLoader):
105
- # install_requirement(py_exec, req_name, upgrade_pip=False, lib=lib)
106
- importlib .invalidate_caches ()
107
-
108
-
109
- def fetch_path_from_blender_script (blender_exec , script , keyword = "blender" ):
110
- out = exec_shell_cmd ([blender_exec , "--background" , "--python" , script ])
111
- path = None
112
- for line in out .split ("\n " ):
113
- line = line .strip ()
114
- if line == "" :
115
- continue
116
- if line .endswith ("\r " ):
117
- line = line .replace ("\r " , "" )
118
- if line .startswith ("/" ) and keyword in line .lower ():
119
- path = Path (line )
120
- break
121
- return path
122
-
123
-
124
30
def main (args ):
125
31
# data
126
32
with open ("README.md" , "r" ) as fh :
127
33
long_description = fh .read ()
128
34
codemeta = json .load (open ("codemeta.json" , "r" ))
129
- deps = json .load (open ("blender_requirements.json" , "r" ))
130
- requirements = deps ["requirements" ]
131
- optional_requirements = deps ["optional_requirements" ]
35
+ requirements = {
36
+ "yaml" : "pyyaml" ,
37
+ "networkx" : "networkx" , # optional for blender
38
+ "numpy" : "numpy" ,
39
+ "scipy" : "scipy" ,
40
+ "trimesh" : "trimesh" , # optional for blender
41
+ "pkg_resources" : "setuptools" ,
42
+ "collada" : "pycollada" ,
43
+ "pydot" : "pydot"
44
+ }
45
+ optional_requirements = {
46
+ "yaml" : "pyyaml" ,
47
+ "pybullet" : "pybullet" , # optional for blender
48
+ "open3d" : "open3d" , # optional for blender
49
+ "python-fcl" : "python-fcl" , # optional for blender
50
+ }
132
51
this_dir = Path (__file__ ).parent
133
52
134
53
##################
@@ -160,53 +79,15 @@ def main(args):
160
79
]
161
80
}
162
81
}
163
- # # autoproj handling
164
- # if not "AUTOPROJ_CURRENT_ROOT" in os.environ:
165
- # kwargs["install_requires"] = list(requirements.values()) #+ list(optional_requirements.keys())
82
+ # autoproj handling
83
+ if not "AUTOPROJ_CURRENT_ROOT" in os .environ :
84
+ kwargs ["install_requires" ] = list (requirements .values ())
85
+ kwargs ["extras_require" ] = {'console_scripts' : list (optional_requirements .keys ())}
166
86
167
87
setuptools .setup (
168
88
** kwargs
169
89
)
170
90
171
- if "--blender" in args :
172
- #################
173
- # blender addon #
174
- #################
175
- # autoproj installation can not handle user inputs
176
- if "AUTOPROJ_CURRENT_ROOT" in os .environ :
177
- sys .exit ()
178
-
179
- blender_path = None
180
- print ("Thanks for installing phobos!\n \n Trying now to install blender addon" )
181
- auto_found = False
182
- for cmd in ["which" , "where" , "Get-Command" ]:
183
- out = Path (exec_shell_cmd ([cmd , "blender" ]))
184
- if out .exists () and "blender" in str (out ).lower ():
185
- if input (f"Take this blender version '{ out } '? (y/n)>" ).lower () in ["y" , "yes" ]:
186
- auto_found = True
187
- break
188
- while not auto_found or not out .exists () or not "blender" in str (out ).lower ():
189
- auto_found = True
190
- print ("Could not retrieve blender executable from this path:" , out )
191
- out = Path (input ("Please provide the path to your blender executable: " ).strip ())
192
- blender_path = deepcopy (out )
193
- scripts_path = fetch_path_from_blender_script (blender_path , this_dir / "get_blender_path.py" )
194
- modules_path = scripts_path / "modules"
195
- addons_path = scripts_path / "addons"
196
- print ("Found the following blender installation directories:" )
197
- print (scripts_path )
198
- print (modules_path )
199
- print (addons_path )
200
- if check_blender_agreement (input ("Do you want to proceed? (y/n)>" ).strip ()):
201
- #install phobos
202
- target = addons_path / "phobos"
203
- if target .exists ():
204
- shutil .rmtree (target )
205
- shutil .copytree (this_dir / "phobos" , target )
206
- # install requirements
207
- python_path = fetch_path_from_blender_script (blender_path , this_dir / "get_blender_python.py" )
208
- check_requirements (python_path , upgrade_pip = True , lib = modules_path )
209
-
210
91
211
92
if __name__ == "__main__" :
212
93
import sys
0 commit comments