8
8
is_linux = os .name == "posix"
9
9
is_windows = not is_linux
10
10
11
+ VENV_DIR_PREFIX = ".pyaedt_env"
12
+
11
13
12
14
def run_pyinstaller_from_c_python (oDesktop ):
13
- # This is called when run from IronPython
15
+ # Iron Python script to create the virtual environment and install PyAEDT
16
+ # Get AEDT information
14
17
version = oDesktop .GetVersion ()[2 :6 ].replace ("." , "" )
15
- python_version = "3.10"
16
- if version <= "231" :
17
- python_version = "3.7"
18
+ # From AEDT 2023.2 the installed CPython version is 3.10
19
+ python_version = "3.10" if version > "231" else "3.7"
20
+ python_version_new = python_version .replace ("." , "_" )
21
+ # AEDT installation root
18
22
edt_root = os .path .normpath (oDesktop .GetExeDir ())
23
+ # CPython interpreter executable
19
24
if is_windows :
20
- python_exe = os .path .normpath (os .path .join (edt_root , "commonfiles" , "CPython" , python_version . replace ( "." , "_" ) ,
25
+ python_exe = os .path .normpath (os .path .join (edt_root , "commonfiles" , "CPython" , python_version_new ,
21
26
"winx64" , "Release" , "python" , "python.exe" ))
22
27
else :
23
- python_exe = os .path .normpath (os .path .join (edt_root , "commonfiles" , "CPython" , python_version . replace ( "." , "_" ) ,
28
+ python_exe = os .path .normpath (os .path .join (edt_root , "commonfiles" , "CPython" , python_version_new ,
24
29
"linx64" , "Release" , "python" , "runpython" ))
30
+
31
+ # Launch this script again from the CPython interpreter. This calls the ``install_pyaedt()`` method,
32
+ # which creates a virtual environment and installs PyAEDT and its dependencies
25
33
command = ['"{}"' .format (python_exe ), '"{}"' .format (os .path .normpath (__file__ )), "--version=" + version ]
26
34
if is_student_version (oDesktop ):
27
35
command .append ("--student" )
@@ -42,17 +50,21 @@ def run_pyinstaller_from_c_python(oDesktop):
42
50
return_code = run_command (" " .join (command ))
43
51
err_msg = "There was an error while installing PyAEDT. Refer to the Terminal window where AEDT was launched " \
44
52
"from."
45
- if is_windows :
46
- venv_dir = os .path .join (os .environ ["APPDATA" ], "pyaedt_env_ide" , "v" + version )
47
- python_exe = os .path .join (venv_dir , "Scripts" , "python.exe" )
48
- else :
49
- venv_dir = os .path .join (os .environ ["HOME" ], "pyaedt_env_ide" , "v" + version )
50
- python_exe = os .path .join (venv_dir , "bin" , "python" )
53
+
51
54
if str (return_code ) != "0" :
52
55
oDesktop .AddMessage ("" , "" , 2 , err_msg )
53
56
return
54
57
else :
55
58
oDesktop .AddMessage ("" , "" , 0 , "PyAEDT virtual environment created." )
59
+
60
+ # Add PyAEDT tabs in AEDT
61
+ # Virtual environment path and Python executable
62
+ if is_windows :
63
+ venv_dir = os .path .join (os .environ ["APPDATA" ], VENV_DIR_PREFIX , python_version_new )
64
+ python_exe = os .path .join (venv_dir , "Scripts" , "python.exe" )
65
+ else :
66
+ venv_dir = os .path .join (os .environ ["HOME" ], VENV_DIR_PREFIX , python_version_new )
67
+ python_exe = os .path .join (venv_dir , "bin" , "python" )
56
68
pyaedt_path = os .path .join (venv_dir , "Lib" , "site-packages" , "pyaedt" )
57
69
if is_linux :
58
70
for dirpath , dirnames , _ in os .walk (venv_dir ):
@@ -62,35 +74,51 @@ def run_pyinstaller_from_c_python(oDesktop):
62
74
)
63
75
if os .path .isdir (pyaedt_path ):
64
76
break
77
+
78
+ # Create PyAEDT symbolic link in PersonalLib
65
79
personal_lib_dir = oDesktop .GetPersonalLibDirectory ()
66
80
pers1 = os .path .join (personal_lib_dir , "pyaedt" )
81
+
67
82
if os .path .exists (pers1 ):
68
- oDesktop .AddMessage ("" , "" , 2 , "PersonalLib already mapped." )
69
- else :
70
83
if is_windows :
71
- command = 'mklink /D "{}" "{}" ' .format (pers1 , pyaedt_path )
84
+ command = 'rmdir "{}"' .format (pers1 )
72
85
else :
73
- command = 'ln -s "{}" "{}" ' .format (pyaedt_path , pers1 )
86
+ command = 'rm "{}"' .format (pers1 )
74
87
ret_code = os .system (command )
75
88
if ret_code != 0 :
76
- oDesktop .AddMessage ("" , "" , 2 , "Error configuring symbolic link to pyaedt in PersonalLib." )
89
+ oDesktop .AddMessage ("" , "" , 2 ,
90
+ "Error occurred while removing the symbolic link to PyAEDT in 'PersonalLib'." )
91
+
92
+ if is_windows :
93
+ command = 'mklink /D "{}" "{}"' .format (pers1 , pyaedt_path )
94
+ else :
95
+ command = 'ln -s "{}" "{}"' .format (pyaedt_path , pers1 )
96
+ ret_code = os .system (command )
97
+ if ret_code != 0 :
98
+ oDesktop .AddMessage ("" , "" , 2 , "Error occurred while configuring the symbolic link to PyAEDT in 'PersonalLib'." )
99
+
100
+ # Create Toolkits in PersonalLib
77
101
import tempfile
78
102
python_script = os .path .join (tempfile .gettempdir (), "configure_pyaedt.py" )
103
+ if os .path .isfile (python_script ):
104
+ os .remove (python_script )
79
105
with open (python_script , "w" ) as f :
80
106
# enable in debu mode
81
107
# f.write("import sys\n")
82
108
# f.write('sys.path.insert(0, r"c:\\ansysdev\\git\\repos\\pyaedt")\n')
83
109
f .write ("from pyaedt.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt\n " )
84
110
f .write (
85
- 'add_pyaedt_to_aedt(aedt_version="{}", personallib =r"{}")\n ' .format (
111
+ 'add_pyaedt_to_aedt(aedt_version="{}", personal_lib =r"{}")\n ' .format (
86
112
oDesktop .GetVersion ()[:6 ], oDesktop .GetPersonalLibDirectory ()))
87
113
88
114
command = r'"{}" "{}"' .format (python_exe , python_script )
89
- oDesktop .AddMessage ("" , "" , 0 , "Configuring PyAEDT Tabs ." )
115
+ oDesktop .AddMessage ("" , "" , 0 , "Configuring PyAEDT panels in automation tab ." )
90
116
ret_code = os .system (command )
91
117
if ret_code != 0 :
92
- oDesktop .AddMessage ("" , "" , 2 , "Error configuring the configuration Tab ." )
118
+ oDesktop .AddMessage ("" , "" , 2 , "Error occurred configuring the PyAEDT panels ." )
93
119
return
120
+ # Refresh UI
121
+ oDesktop .CloseAllWindows ()
94
122
if version >= "232" :
95
123
oDesktop .RefreshToolkitUI ()
96
124
msg = "PyAEDT configuration complete."
@@ -102,6 +130,7 @@ def run_pyinstaller_from_c_python(oDesktop):
102
130
from System .Windows .Forms import MessageBox , MessageBoxButtons , MessageBoxIcon
103
131
oDesktop .AddMessage ("" , "" , 0 , msg )
104
132
MessageBox .Show (msg , 'Info' , MessageBoxButtons .OK , MessageBoxIcon .Information )
133
+ oDesktop .AddMessage ("" , "" , 0 , "Create a project if the PyAEDT panel is not visible." )
105
134
106
135
107
136
def parse_arguments_for_pyaedt_installer (args = None ):
@@ -123,12 +152,17 @@ def parse_arguments_for_pyaedt_installer(args=None):
123
152
def install_pyaedt ():
124
153
# This is called when run from CPython
125
154
args = parse_arguments_for_pyaedt_installer ()
155
+
156
+ python_version = "3_10"
157
+ if args .version <= "231" :
158
+ python_version = "3_7"
159
+
126
160
if is_windows :
127
- venv_dir = os .path .join (os .environ ["APPDATA" ], "pyaedt_env_ide" , "v" + args . version )
161
+ venv_dir = os .path .join (os .environ ["APPDATA" ], VENV_DIR_PREFIX , python_version )
128
162
python_exe = os .path .join (venv_dir , "Scripts" , "python.exe" )
129
163
pip_exe = os .path .join (venv_dir , "Scripts" , "pip.exe" )
130
164
else :
131
- venv_dir = os .path .join (os .environ ["HOME" ], "pyaedt_env_ide" , "v" + args . version )
165
+ venv_dir = os .path .join (os .environ ["HOME" ], VENV_DIR_PREFIX , python_version )
132
166
python_exe = os .path .join (venv_dir , "bin" , "python" )
133
167
pip_exe = os .path .join (venv_dir , "bin" , "pip" )
134
168
os .environ ["ANSYSEM_ROOT{}" .format (args .version )] = args .edt_root
@@ -158,14 +192,14 @@ def install_pyaedt():
158
192
run_command ('"{}" -m venv "{}"' .format (sys .executable , venv_dir ))
159
193
160
194
if args .wheel and os .path .exists (args .wheel ):
161
- wheelpyaedt = args .wheel
195
+ wheel_pyaedt = args .wheel
162
196
import zipfile
163
- unzipped_path = os .path .join (os .path .dirname (wheelpyaedt ),
164
- os .path .splitext (os .path .basename (wheelpyaedt ))[0 ])
197
+ unzipped_path = os .path .join (os .path .dirname (wheel_pyaedt ),
198
+ os .path .splitext (os .path .basename (wheel_pyaedt ))[0 ])
165
199
if os .path .exists (unzipped_path ):
166
200
shutil .rmtree (unzipped_path , ignore_errors = True )
167
- with zipfile .ZipFile (wheelpyaedt , 'r' ) as zip_ref :
168
- # Extract all contents to a directory (you can specify a different extraction path if needed)
201
+ with zipfile .ZipFile (wheel_pyaedt , 'r' ) as zip_ref :
202
+ # Extract all contents to a directory. (You can specify a different extraction path if needed. )
169
203
zip_ref .extractall (unzipped_path )
170
204
171
205
run_command (
@@ -178,7 +212,7 @@ def install_pyaedt():
178
212
run_command ('"{}" -m pip install --upgrade pip' .format (python_exe ))
179
213
run_command ('"{}" --default-timeout=1000 install wheel' .format (pip_exe ))
180
214
# run_command(
181
- # '"{}" --default-timeout=1000 install git+https://github.com/ansys/pyaedt.git@fix/ main'.format(pip_exe))
215
+ # '"{}" --default-timeout=1000 install git+https://github.com/ansys/pyaedt.git@main'.format(pip_exe))
182
216
run_command ('"{}" --default-timeout=1000 install pyaedt[all]' .format (pip_exe ))
183
217
run_command ('"{}" --default-timeout=1000 install jupyterlab' .format (pip_exe ))
184
218
run_command ('"{}" --default-timeout=1000 install ipython -U' .format (pip_exe ))
@@ -191,14 +225,14 @@ def install_pyaedt():
191
225
run_command ('"{}" uninstall --yes pyaedt' .format (pip_exe ))
192
226
193
227
if args .wheel and os .path .exists (args .wheel ):
194
- wheelpyaedt = args .wheel
228
+ wheel_pyaedt = args .wheel
195
229
import zipfile
196
- unzipped_path = os .path .join (os .path .dirname (wheelpyaedt ),
197
- os .path .splitext (os .path .basename (wheelpyaedt ))[0 ])
230
+ unzipped_path = os .path .join (os .path .dirname (wheel_pyaedt ),
231
+ os .path .splitext (os .path .basename (wheel_pyaedt ))[0 ])
198
232
if os .path .exists (unzipped_path ):
199
233
shutil .rmtree (unzipped_path , ignore_errors = True )
200
- with zipfile .ZipFile (wheelpyaedt , 'r' ) as zip_ref :
201
- # Extract all contents to a directory (you can specify a different extraction path if needed)
234
+ with zipfile .ZipFile (wheel_pyaedt , 'r' ) as zip_ref :
235
+ # Extract all contents to a directory. (You can specify a different extraction path if needed. )
202
236
zip_ref .extractall (unzipped_path )
203
237
204
238
run_command ('"{}" install --no-cache-dir --no-index --find-links={} pyaedt' .format (pip_exe , unzipped_path ))
@@ -224,9 +258,8 @@ def run_command(command):
224
258
225
259
if __name__ == "__main__" :
226
260
227
- # When launched from Toolkit (i.e. IronPython) call this same file using CPython
228
261
if is_iron_python :
229
- # Check if wheelhouse defined, wheelhouse is created for Windows only
262
+ # Check if wheelhouse defined. Wheelhouse is created for Windows only.
230
263
wheelpyaedt = []
231
264
# Retrieve the script arguments
232
265
script_args = ScriptArgument .split ()
0 commit comments