Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/1972.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove dotnetcore2
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies = [
"cffi>=1.16.0,<2.1; platform_system=='Linux'",
"pywin32>=308;platform_system=='Windows'",
"ansys-pythonnet>=3.1.0rc6",
"dotnetcore2==3.1.23;platform_system=='Linux'",
# Core dependencies
"numpy>=1.20.0,<3",
"pydantic>=2.6.4,<2.13",
Expand Down
43 changes: 16 additions & 27 deletions src/pyedb/dotnet/clr_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non
dotnet_root = None
runtime_config = None
runtime_spec = None
# Use system .NET core runtime or fall back to dotnetcore2
# Use system .NET core runtime
if os.environ.get("DOTNET_ROOT") is None:
try:
from clr_loader import get_coreclr
Expand All @@ -70,37 +70,26 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non
load(runtime)
os.environ["DOTNET_ROOT"] = runtime.dotnet_root.as_posix()
is_clr = True
# TODO: Fall backing to dotnetcore2 should be removed in a near future.
except Exception:
warnings.warn(
"Unable to set .NET root and locate the runtime configuration file. Falling back to using dotnetcore2."
raise RuntimeError(
".NET is not found. For more information, see"
"https://aedt.docs.pyansys.com/version/stable/release_1_0.html#dotnet-changes-in-linux"
)
warnings.warn(LINUX_WARNING)

import dotnetcore2

dotnet_root = Path(dotnetcore2.__file__).parent / "bin"
runtime_config = pyedb_path / "misc" / "pyedb.runtimeconfig.json"
# Use specified .NET root folder
else:
dotnet_root = Path(os.environ["DOTNET_ROOT"])
# Patch the case where DOTNET_ROOT leads to dotnetcore2 for more information
# see https://github.com/ansys/pyedb/issues/922
# TODO: Remove once dotnetcore2 is deprecated
if dotnet_root.parent.name == "dotnetcore2":
runtime_config = pyedb_path / "misc" / "pyedb.runtimeconfig.json"
else:
from clr_loader import find_runtimes

candidates = [rt for rt in find_runtimes() if rt.name == "Microsoft.NETCore.App"]
candidates.sort(key=lambda spec: spec.version, reverse=True)
if not candidates:
raise RuntimeError(
"Configuration file could not be found from DOTNET_ROOT. "
"Please ensure that .NET SDK is correctly installed or "
"that DOTNET_ROOT is correctly set."
)
runtime_spec = candidates[0]

from clr_loader import find_runtimes

candidates = [rt for rt in find_runtimes() if rt.name == "Microsoft.NETCore.App"]
candidates.sort(key=lambda spec: spec.version, reverse=True)
if not candidates:
raise RuntimeError(
"Configuration file could not be found from DOTNET_ROOT. "
"Please ensure that .NET SDK is correctly installed or "
"that DOTNET_ROOT is correctly set."
)
runtime_spec = candidates[0]
# Use specific .NET core runtime
if dotnet_root is not None and (runtime_config is not None or runtime_spec is not None):
try:
Expand Down
59 changes: 0 additions & 59 deletions tests/unit/test_clr_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

DOTNET_ROOT = "dummy/root/path"
DOTNET_ROOT_PATH = Path(DOTNET_ROOT)
DOTNETCORE2_FILE = "dummy/dotnetcore2/file"
DOTNETCORE2_BIN = "dummy/dotnetcore2/bin"
PYEDB_FILE = "dummy/pyedb/file"


Expand Down Expand Up @@ -65,60 +63,3 @@ def test_use_system_dotnet(mock_get_coreclr, mock_load, clean_environment):
assert cm.is_clr
assert DOTNET_ROOT_PATH.as_posix() == os.environ["DOTNET_ROOT"]
del os.environ["DOTNET_ROOT"]


@pytest.mark.skipif(os.name != "posix", reason="test for linux behavior")
@patch("dotnetcore2.__file__", new=DOTNETCORE2_FILE)
@patch("pythonnet.load")
@patch("clr_loader.get_coreclr", side_effect=Exception("Dummy exception"))
def test_use_dotnetcore2(mock_get_coreclr, mock_load, clean_environment, capsys):
import pyedb.dotnet.clr_module as cm

captured = capsys.readouterr()
from pyedb.dotnet.clr_module import LINUX_WARNING

assert cm.is_clr
assert DOTNETCORE2_BIN == os.environ["DOTNET_ROOT"]
assert LINUX_WARNING in captured.out


@pytest.mark.skipif(os.name != "posix", reason="test for linux behavior")
@patch("dotnetcore2.__file__", new=DOTNETCORE2_FILE)
@patch("pythonnet.load")
@patch("clr_loader.find_runtimes", return_value=[])
def test_use_dotnet_root_env_variable_failure(mock_find_runtimes, mock_load, clean_environment, capsys):
os.environ["DOTNET_ROOT"] = DOTNET_ROOT

with pytest.raises(RuntimeError):
import pyedb.dotnet.clr_module # noqa: F401


@pytest.mark.skipif(os.name != "posix", reason="test for linux behavior")
@patch("dotnetcore2.__file__", new=DOTNETCORE2_FILE)
@patch("pythonnet.load")
def test_use_dotnet_root_env_variable_success_dotnetcore2(mock_load, clean_environment, capsys):
os.environ["DOTNET_ROOT"] = DOTNETCORE2_BIN

import pyedb.dotnet.clr_module as cm

captured = capsys.readouterr()
from pyedb.dotnet.clr_module import LINUX_WARNING

assert cm.is_clr
assert DOTNETCORE2_BIN == os.environ["DOTNET_ROOT"]
assert LINUX_WARNING not in captured.out


@pytest.mark.skipif(os.name != "posix", reason="test for linux behavior")
@patch("dotnetcore2.__file__", new=DOTNETCORE2_FILE)
@patch("pythonnet.load")
@patch("clr_loader.find_runtimes")
def test_use_dotnet_root_env_variable_success(mock_find_runtimes, mock_load, clean_environment, capsys):
os.environ["DOTNET_ROOT"] = DOTNET_ROOT
mock_runtime = MagicMock()
mock_runtime.name = "Microsoft.NETCore.App"
mock_find_runtimes.return_value = [mock_runtime]

import pyedb.dotnet.clr_module # noqa: F401

assert os.environ["DOTNET_ROOT"]
Loading