Skip to content
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

feat: allow for debug mode execution #1577

Closed
wants to merge 5 commits into from
Closed
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/1577.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow for debug mode execution
13 changes: 12 additions & 1 deletion src/ansys/geometry/core/modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from grpc import Channel

from ansys.api.dbu.v0.dbuapplication_pb2 import RunScriptFileRequest
from ansys.api.dbu.v0.dbuapplication_pb2 import RunScriptFileRequest, RunScriptType
from ansys.api.dbu.v0.dbuapplication_pb2_grpc import DbuApplicationStub
from ansys.api.dbu.v0.designs_pb2 import OpenRequest
from ansys.api.dbu.v0.designs_pb2_grpc import DesignsStub
Expand Down Expand Up @@ -382,6 +382,7 @@ def run_discovery_script_file(
script_args: dict[str, str] | None = None,
import_design: bool = False,
api_version: int | str | ApiVersions = None,
enable_debug_features: bool = False,
) -> tuple[dict[str, str], Optional["Design"]]:
"""Run a Discovery script file.

Expand Down Expand Up @@ -430,6 +431,9 @@ def run_discovery_script_file(
the specified API version. If the API version is not supported, the service will raise
an error. If you are using Discovery or SpaceClaim, the product will determine the API
version to use, so there is no need to specify this parameter.
enable_debug_features : bool, default: False
Whether to enable debug features for the script. By default, debug features are
disabled. Debug features are only available starting on 2025R1.

Returns
-------
Expand Down Expand Up @@ -475,6 +479,13 @@ def run_discovery_script_file(
api_version=api_version.value if api_version is not None else None,
)

# Enable debug features if requested
if enable_debug_features:
if self.client.backend_version > (25, 1, 0):
request.script_type = RunScriptType.DEBUG
else: # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on what Ken tells us about the debug mode, we might need to filter here if we run against DMS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

self.client.log.warning("Debug features are only available starting on 2025R1.")

self.client.log.debug(f"Running Discovery script file at {file_path}...")
response = ga_stub.RunScriptFile(request)

Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,19 @@ def test_dscript_simple_script(modeler: Modeler):
assert len(result) == 2
assert pattern_db.match(result["design_body"])
assert pattern_doc.match(result["design"])


# Discovery (.dscript)
def test_dscript_simple_script_debug_mode(modeler: Modeler):
# Skip on Linux
skip_if_linux(modeler, test_dscript_simple_script.__name__, "run_discovery_script_file")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, if debug run script won't be available on DMS before it's retired, we'll need to skip that test for DMS


result = modeler.run_discovery_script_file(
DSCOSCRIPTS_FILES_DIR / "simple_script.dscript", enable_debug_features=True
)
assert len(result) == 2
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)
assert len(result) == 2
assert pattern_db.match(result["design_body"])
assert pattern_doc.match(result["design"])
Loading