Skip to content

Commit 227d017

Browse files
CHORE: Remove support of version 23R2 (#1255)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent b2291b3 commit 227d017

File tree

8 files changed

+45
-94
lines changed

8 files changed

+45
-94
lines changed

doc/changelog.d/1255.maintenance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove support of version 23r2

src/ansys/mechanical/core/embedding/app.py

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import atexit
2727
import os
2828
from pathlib import Path
29-
import shutil
3029
import typing
3130

3231
from ansys.mechanical.core import LOG
@@ -84,12 +83,8 @@ def _start_application(configuration: AddinConfiguration, version, db_file) -> "
8483
os.environ["ANSYS_MECHANICAL_STANDALONE_NO_ACT_EXTENSIONS"] = "1"
8584

8685
addin_configuration_name = configuration.addin_configuration
87-
# Starting with version 241 we can pass a configuration name to the constructor
88-
# of Application
89-
if int(version) >= 241:
90-
return Ansys.Mechanical.Embedding.Application(db_file, addin_configuration_name)
91-
else:
92-
return Ansys.Mechanical.Embedding.Application(db_file)
86+
87+
return Ansys.Mechanical.Embedding.Application(db_file, addin_configuration_name)
9388

9489

9590
def is_initialized():
@@ -325,11 +320,6 @@ def save_as(self, path: str, overwrite: bool = False, remove_lock: bool = False)
325320
------
326321
Exception
327322
If the file already exists at the specified path and `overwrite` is False.
328-
329-
Notes
330-
-----
331-
For version 232, if `overwrite` is True, the existing file and its associated directory
332-
(if any) will be removed before saving the new file.
333323
"""
334324
if not os.path.exists(path):
335325
self.DataModel.Project.SaveAs(path)
@@ -340,39 +330,28 @@ def save_as(self, path: str, overwrite: bool = False, remove_lock: bool = False)
340330
f"File already exists in {path}, Use ``overwrite`` flag to "
341331
"replace the existing file."
342332
)
343-
if self.version < 241: # pragma: no cover
344-
file_name = os.path.basename(path)
345-
file_dir = os.path.dirname(path)
346-
associated_dir = os.path.join(file_dir, os.path.splitext(file_name)[0] + "_Mech_Files")
347-
348-
# Remove existing files and associated folder
349-
os.remove(path)
350-
if os.path.exists(associated_dir):
351-
shutil.rmtree(associated_dir)
352-
# Save the new file
353-
self.DataModel.Project.SaveAs(path)
354-
else:
355-
if remove_lock:
356-
file_path = Path(path)
357-
associated_dir = file_path.parent / f"{file_path.stem}_Mech_Files"
358-
lock_file = associated_dir / ".mech_lock"
359-
# Remove the lock file if it exists before saving the project file
360-
if lock_file.exists():
361-
self.log_warning(f"Removing the lock file, {lock_file}... ")
362-
lock_file.unlink()
363-
try:
364-
self.DataModel.Project.SaveAs(path, overwrite)
365-
except Exception as e:
366-
error_msg = str(e)
367-
if "The project is locked by" in error_msg:
368-
self.log_error(
369-
f"Failed to save project as {path}: {error_msg}\n"
370-
"Hint: The project file is locked. "
371-
"Try using the 'remove_lock=True' option when saving the project."
372-
)
373-
else:
374-
self.log_error(f"Failed to save project as {path}: {error_msg}")
375-
raise e
333+
334+
if remove_lock:
335+
file_path = Path(path)
336+
associated_dir = file_path.parent / f"{file_path.stem}_Mech_Files"
337+
lock_file = associated_dir / ".mech_lock"
338+
# Remove the lock file if it exists before saving the project file
339+
if lock_file.exists():
340+
self.log_warning(f"Removing the lock file, {lock_file}... ")
341+
lock_file.unlink()
342+
try:
343+
self.DataModel.Project.SaveAs(path, overwrite)
344+
except Exception as e:
345+
error_msg = str(e)
346+
if "The project is locked by" in error_msg:
347+
self.log_error(
348+
f"Failed to save project as {path}: {error_msg}\n"
349+
"Hint: The project file is locked. "
350+
"Try using the 'remove_lock=True' option when saving the project."
351+
)
352+
else:
353+
self.log_error(f"Failed to save project as {path}: {error_msg}")
354+
raise e
376355

377356
def launch_gui(self, delete_tmp_on_close: bool = True, dry_run: bool = False):
378357
"""Launch the GUI."""
@@ -391,10 +370,7 @@ def close(self):
391370
def exit(self):
392371
"""Exit the application."""
393372
self._unsubscribe()
394-
if self.version < 241:
395-
self.ExtAPI.Application.Close()
396-
else:
397-
self.ExtAPI.Application.Exit()
373+
self.ExtAPI.Application.Exit()
398374

399375
def execute_script(self, script: str) -> typing.Any:
400376
"""Execute the given script with the internal IronPython engine."""

src/ansys/mechanical/core/embedding/mechanical_warnings.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,9 @@ def _on_obsolete_message(sender: typing.Any, args: typing.Any):
6363

6464
def connect_warnings(app: "ansys.mechanical.core.embedding.app.App"):
6565
"""Connect Mechanical warnings to the `warnings` Python module."""
66-
if int(app.version) < 241:
67-
return
68-
6966
app._app.OnObsoleteMessage += _on_obsolete_message
7067

7168

7269
def disconnect_warnings(app):
7370
"""Disconnect Mechanical warnings from the `warnings` Python module."""
74-
if int(app.version) < 241:
75-
return
76-
7771
app._app.OnObsoleteMessage -= _on_obsolete_message

src/ansys/mechanical/core/run.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import os
2828
import sys
2929
import typing
30-
import warnings
3130

3231
import ansys.tools.path as atp
3332
import click
@@ -130,10 +129,6 @@ def _cli_impl(
130129
if (not graphical) or (not show_welcome_screen):
131130
args.append("-AppModeMech")
132131

133-
if version < 232:
134-
args.append("-nosplash")
135-
args.append("-notabctrl")
136-
137132
if not graphical:
138133
args.append("-b")
139134

@@ -159,14 +154,8 @@ def _cli_impl(
159154

160155
if (not graphical) and input_script:
161156
exit = True
162-
if version < 241:
163-
warnings.warn(
164-
"Please ensure ExtAPI.Application.Close() is at the end of your script. "
165-
"Without this command, Batch mode will not terminate.",
166-
stacklevel=2,
167-
)
168157

169-
if exit and input_script and version >= 241:
158+
if exit and input_script:
170159
args.append("-x")
171160

172161
profile: UniqueUserProfile = None

tests/embedding/test_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from ansys.mechanical.core.embedding.app import is_initialized
3535
from ansys.mechanical.core.embedding.cleanup_gui import cleanup_gui
36+
from ansys.mechanical.core.embedding.initializer import SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS
3637
from ansys.mechanical.core.embedding.ui import _launch_ui
3738
import ansys.mechanical.core.embedding.utils as utils
3839

@@ -47,7 +48,6 @@ def test_app_repr(embedded_app):
4748

4849

4950
@pytest.mark.embedding
50-
@pytest.mark.minimum_version(241)
5151
def test_deprecation_warning(embedded_app):
5252
harmonic_acoustic = embedded_app.Model.AddHarmonicAcousticAnalysis()
5353
with pytest.warns(UserWarning):
@@ -118,7 +118,7 @@ def test_app_version(embedded_app):
118118
"""Test version of the Application class."""
119119
version = embedded_app.version
120120
assert type(version) is int
121-
assert version >= 241
121+
assert version >= min(SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS)
122122

123123

124124
@pytest.mark.embedding

tests/embedding/test_logger.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def test_logging_write_info_after_initialize_with_error_level(
117117
@pytest.mark.parametrize("addin_configuration", ["Mechanical", "WorkBench"])
118118
@pytest.mark.embedding_scripts
119119
@pytest.mark.embedding_logging
120-
@pytest.mark.minimum_version(241)
121120
def test_addin_configuration(rootdir, run_subprocess, pytestconfig, addin_configuration):
122121
"""Test that mechanical can start with both the Mechanical and WorkBench configuration."""
123122
stderr = _run_embedding_log_test(

tests/test_cli.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from click.testing import CliRunner
3030
import pytest
3131

32+
from ansys.mechanical.core.embedding.initializer import SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS
3233
from ansys.mechanical.core.ide_config import cli as ideconfig_cli
3334
from ansys.mechanical.core.ide_config import get_stubs_location, get_stubs_versions
3435
from ansys.mechanical.core.run import _cli_impl
@@ -104,13 +105,6 @@ def test_cli_appmode(disable_cli, pytestconfig):
104105
assert "-AppModeMech" not in args
105106

106107

107-
@pytest.mark.cli
108-
def test_cli_231(disable_cli):
109-
args, _ = _cli_impl(exe="AnsysWBU.exe", version=231, port=11)
110-
assert "-nosplash" in args
111-
assert "-notabctrl" in args
112-
113-
114108
@pytest.mark.cli
115109
def test_cli_port(disable_cli, pytestconfig):
116110
version = int(pytestconfig.getoption("ansys_version"))
@@ -216,18 +210,10 @@ def test_cli_features(disable_cli, pytestconfig):
216210
@pytest.mark.cli
217211
def test_cli_exit(disable_cli, pytestconfig):
218212
version = int(pytestconfig.getoption("ansys_version"))
219-
# Regardless of version, `exit` does nothing on its own
220-
args, _ = _cli_impl(exe="AnsysWBU.exe", version=232, exit=True, port=11)
221-
assert "-x" not in args
222213

223214
args, _ = _cli_impl(exe="AnsysWBU.exe", version=version, exit=True, port=11)
224215
assert "-x" not in args
225216

226-
# On versions earlier than 2024R1, `exit` throws a warning but does nothing
227-
with pytest.warns(UserWarning):
228-
args, _ = _cli_impl(exe="AnsysWBU.exe", version=232, exit=True, input_script="foo.py")
229-
assert "-x" not in args
230-
231217
# In UI mode, exit must be manually specified
232218
args, _ = _cli_impl(exe="AnsysWBU.exe", version=version, input_script="foo.py", graphical=True)
233219
assert "-x" not in args
@@ -247,25 +233,31 @@ def test_cli_exit(disable_cli, pytestconfig):
247233

248234
@pytest.mark.cli
249235
def test_cli_batch_required_args(disable_cli):
250-
# ansys-mechanical -r 241 => exception
236+
# ansys-mechanical -r <version> => exception
251237
with pytest.raises(Exception):
252-
_cli_impl(exe="AnsysWBU.exe", version=241)
238+
_cli_impl(exe="AnsysWBU.exe", version=max(SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS))
253239

254-
# ansys-mechanical -r 241 -g => no exception
240+
# ansys-mechanical -r <version> -g => no exception
255241
try:
256-
_cli_impl(exe="AnsysWBU.exe", version=241, graphical=True)
242+
_cli_impl(
243+
exe="AnsysWBU.exe", version=max(SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS), graphical=True
244+
)
257245
except Exception as e:
258246
assert False, f"cli raised an exception: {e}"
259247

260-
# ansys-mechanical -r 241 -i input.py => no exception
248+
# ansys-mechanical -r <version> -i input.py => no exception
261249
try:
262-
_cli_impl(exe="AnsysWBU.exe", version=241, input_script="input.py")
250+
_cli_impl(
251+
exe="AnsysWBU.exe",
252+
version=max(SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS),
253+
input_script="input.py",
254+
)
263255
except Exception as e:
264256
assert False, f"cli raised an exception: {e}"
265257

266-
# ansys-mechanical -r 241 -port 11 => no exception
258+
# ansys-mechanical -r <version> -port 11 => no exception
267259
try:
268-
_cli_impl(exe="AnsysWBU.exe", version=241, port=11)
260+
_cli_impl(exe="AnsysWBU.exe", version=max(SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS), port=11)
269261
except Exception as e:
270262
assert False, f"cli raised an exception: {e}"
271263

tests/test_mechanical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_find_mechanical_path():
410410
else:
411411
assert ".workbench" in path
412412

413-
assert re.match(r"\d{3}", str(version)) and version >= 232
413+
assert re.match(r"\d{3}", str(version)) and version >= 241
414414

415415

416416
@pytest.mark.remote_session_launch

0 commit comments

Comments
 (0)