Skip to content

feat: enable runscript for CoreService #1821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 14, 2025
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/1821.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable runscript for CoreService
6 changes: 5 additions & 1 deletion src/ansys/geometry/core/modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ def run_discovery_script_file(

# Check if API version is specified... if so, validate it
if api_version is not None:
if self.client.backend_type == BackendType.WINDOWS_SERVICE:
if self.client.backend_type in (
BackendType.WINDOWS_SERVICE,
BackendType.CORE_WINDOWS,
BackendType.CORE_LINUX,
):
self.client.log.warning(
"The Ansys Geometry Service only supports "
"scripts that are of its same API version."
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/files/disco_scripts/integrated_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
doc = GetActiveWindow().Document
doc = GetActiveDocument()
radius = MM(int(argsDict["radius"]))

sphere = Sphere.Create(Frame.World, radius)
Expand All @@ -8,6 +8,6 @@
b = Body.CreateSurfaceBody(sphere, box)
db = DesignBody.Create(doc.MainPart, "sphere", b)

numBodies = doc.MainPart.GetAllBodies().Count
numBodies = doc.MainPart.Bodies.Count

result = {"numBodies": numBodies}
Binary file modified tests/integration/files/disco_scripts/simple_script.dscript
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/integration/files/disco_scripts/simple_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Python Discovery Script
import math

doc = Document.Create()

sphere = Sphere.Create(
Expand Down
Binary file modified tests/integration/files/disco_scripts/simple_script.scscript
Binary file not shown.
25 changes: 3 additions & 22 deletions tests/integration/test_runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
from ansys.geometry.core.math.point import Point2D
from ansys.geometry.core.sketch import Sketch

from .conftest import DSCOSCRIPTS_FILES_DIR, skip_if_core_service
from .conftest import DSCOSCRIPTS_FILES_DIR


# Python (.py)
def test_python_simple_script(modeler: Modeler):
# Skip on CoreService
skip_if_core_service(modeler, test_python_simple_script.__name__, "run_discovery_script_file")

result = modeler.run_discovery_script_file(DSCOSCRIPTS_FILES_DIR / "simple_script.py")
pattern_db = re.compile(r"SpaceClaim\.Api\.[A-Za-z0-9]+\.DesignBody", re.IGNORECASE)
pattern_doc = re.compile(r"SpaceClaim\.Api\.[A-Za-z0-9]+\.Document", re.IGNORECASE)
Expand All @@ -49,11 +46,6 @@ def test_python_simple_script(modeler: Modeler):
def test_python_simple_script_ignore_api_version(
modeler: Modeler, caplog: pytest.LogCaptureFixture
):
# Skip on CoreService
skip_if_core_service(
modeler, test_python_simple_script_ignore_api_version.__name__, "run_discovery_script_file"
)

result = modeler.run_discovery_script_file(
DSCOSCRIPTS_FILES_DIR / "simple_script.py",
api_version=ApiVersions.LATEST,
Expand All @@ -73,18 +65,13 @@ def test_python_simple_script_ignore_api_version(


def test_python_failing_script(modeler: Modeler):
# Skip on CoreService
skip_if_core_service(modeler, test_python_failing_script.__name__, "run_discovery_script_file")
if modeler.client.backend_type == BackendType.CORE_LINUX:
pytest.skip(reason="Skipping test_python_failing_script. Operation fails on github.")
with pytest.raises(GeometryRuntimeError):
modeler.run_discovery_script_file(DSCOSCRIPTS_FILES_DIR / "failing_script.py")


def test_python_integrated_script(modeler: Modeler):
# Skip on CoreService
skip_if_core_service(
modeler, test_python_integrated_script.__name__, "run_discovery_script_file"
)

# Tests the workflow of creating a design in PyAnsys Geometry, modifying it with a script,
# and continuing to use it in PyAnsys Geometry

Expand All @@ -105,9 +92,6 @@ def test_python_integrated_script(modeler: Modeler):

# SpaceClaim (.scscript)
def test_scscript_simple_script(modeler: Modeler):
# Skip on CoreService
skip_if_core_service(modeler, test_scscript_simple_script.__name__, "run_discovery_script_file")

result = modeler.run_discovery_script_file(DSCOSCRIPTS_FILES_DIR / "simple_script.scscript")
assert len(result) == 2
pattern_db = re.compile(r"SpaceClaim\.Api\.[A-Za-z0-9]+\.DesignBody", re.IGNORECASE)
Expand All @@ -119,9 +103,6 @@ def test_scscript_simple_script(modeler: Modeler):

# Discovery (.dscript)
def test_dscript_simple_script(modeler: Modeler):
# Skip on CoreService
skip_if_core_service(modeler, test_dscript_simple_script.__name__, "run_discovery_script_file")

result = modeler.run_discovery_script_file(DSCOSCRIPTS_FILES_DIR / "simple_script.dscript")
assert len(result) == 2
pattern_db = re.compile(r"SpaceClaim\.Api\.[A-Za-z0-9]+\.DesignBody", re.IGNORECASE)
Expand Down
Loading