Skip to content

Commit 06ea1ee

Browse files
authored
CI performance and improvements to export mech (#182)
1 parent 4e85a26 commit 06ea1ee

File tree

7 files changed

+117
-57
lines changed

7 files changed

+117
-57
lines changed

.github/workflows/ci_cd.yml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,60 @@ jobs:
6161
vale_flags: "--config=doc/.vale.ini"
6262

6363
smoke-tests:
64-
name: Build and Smoke tests
65-
runs-on: ${{ matrix.os }}
64+
name: Build and Smoke tests (Ubuntu only)
65+
runs-on: ubuntu-latest
6666
needs: [style]
6767
strategy:
6868
matrix:
69-
os: [windows-latest, ubuntu-latest, macos-latest]
69+
python-version: ['3.7', '3.8', '3.9', '3.10']
70+
fail-fast: false
71+
72+
steps:
73+
- uses: actions/checkout@v3
74+
75+
- name: Set up Python ${{ matrix.python-version }}
76+
uses: actions/setup-python@v4
77+
with:
78+
python-version: ${{ matrix.python-version }}
79+
cache: 'pip'
80+
cache-dependency-path: 'pyproject.toml'
81+
82+
- name: Install packages for building
83+
run: |
84+
pip install --upgrade build wheel
85+
pip install .
86+
87+
- name: Smoke test
88+
run: python -c "from ansys.geometry.core import __version__; print(__version__)"
89+
90+
- name: Store version
91+
run: |
92+
echo "PYGEOM_VERSION=$(python -c "from ansys.geometry.core import __version__; print(__version__)")" >> $GITHUB_ENV
93+
94+
- name: Generate wheelhouse
95+
run: |
96+
pip wheel . -w wheelhouse
97+
98+
- name: Zip wheelhouse
99+
uses: vimtor/action-zip@v1
100+
with:
101+
files: wheelhouse
102+
dest: ${{ env.PACKAGE_NAME }}-v${{ env.PYGEOM_VERSION }}-wheelhouse-${{ runner.os }}-${{ matrix.python-version }}.zip
103+
104+
- name: Upload Wheelhouse
105+
uses: actions/upload-artifact@v3
106+
with:
107+
name: ${{ env.PACKAGE_NAME }}-v${{ env.PYGEOM_VERSION }}-wheelhouse-${{ runner.os }}-${{ matrix.python-version }}
108+
path: '*.zip'
109+
retention-days: 7
110+
111+
remaining-smoke-tests:
112+
name: Build and Smoke tests (Windows, macOS)
113+
runs-on: ${{ matrix.os }}
114+
needs: [smoke-tests]
115+
strategy:
116+
matrix:
117+
os: [windows-latest, macos-latest]
70118
python-version: ['3.7', '3.8', '3.9', '3.10']
71119
fail-fast: false
72120

@@ -251,7 +299,7 @@ jobs:
251299
252300
package:
253301
name: Package library
254-
needs: [testing, docs]
302+
needs: [testing, docs, remaining-smoke-tests]
255303
runs-on: ubuntu-latest
256304
steps:
257305
- uses: actions/checkout@v3
-16 KB
Loading
Loading

doc/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
}
122122
nbsphinx_thumbnails = {
123123
"examples/basic_usage": "_static/thumbnails/basic_usage.png",
124+
"examples/dynamic_sketch_plane": "_static/thumbnails/dynamic_sketch_plane.png",
124125
}
125126

126127
typehints_defaults = "comma"

src/ansys/geometry/core/designer/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ansys.geometry.core.designer.body import Body
44
from ansys.geometry.core.designer.component import Component, SharedTopologyType
5-
from ansys.geometry.core.designer.design import Design
5+
from ansys.geometry.core.designer.design import Design, DesignFileFormat
66
from ansys.geometry.core.designer.edge import CurveType, Edge
77
from ansys.geometry.core.designer.face import Face, SurfaceType
88
from ansys.geometry.core.designer.selection import NamedSelection
@@ -12,6 +12,7 @@
1212
"Component",
1313
"CurveType",
1414
"Design",
15+
"DesignFileFormat",
1516
"Edge",
1617
"Face",
1718
"NamedSelection",

src/ansys/geometry/core/designer/design.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""``Design`` class module."""
22

3+
from enum import Enum
34
from pathlib import Path
45
from typing import List, Optional, Union
56

@@ -30,6 +31,15 @@
3031
from ansys.geometry.core.misc import check_type
3132

3233

34+
class DesignFileFormat(Enum):
35+
"""Available file formats supported by the Design class for download."""
36+
37+
SCDOCX = "SCDOCX", None
38+
PARASOLID_TEXT = "PARASOLID_TEXT", PartExportFormat.PARTEXPORTFORMAT_PARASOLID_TEXT
39+
PARASOLID_BIN = "PARASOLID_BIN", PartExportFormat.PARTEXPORTFORMAT_PARASOLID_BINARY
40+
INVALID = "INVALID", None
41+
42+
3343
class Design(Component):
3444
"""
3545
Provides a ``Design`` for organizing geometry assemblies.
@@ -125,72 +135,62 @@ def save(self, file_location: Union[Path, str]) -> None:
125135
self._grpc_client.log.debug(f"Design successfully saved at location {file_location}.")
126136

127137
@protect_grpc
128-
def download(self, file_location: Union[Path, str], as_stream: Optional[bool] = False) -> None:
138+
def download(
139+
self,
140+
file_location: Union[Path, str],
141+
format: Optional[DesignFileFormat] = DesignFileFormat.SCDOCX,
142+
as_stream: Optional[bool] = False,
143+
) -> None:
129144
"""Downloads a design from the active geometry server instance.
130145
131146
Parameters
132147
----------
133148
file_location : Union[Path, str]
134149
Location on disk where the file should be saved.
135-
as_stream : bool, Default: False
136-
Boolean indicating whether to use the gRPC stream functionality.
150+
format : Optional[DesignFileFormat]
151+
Format in which to export the design. By default, as an ``SCDOCX`` file.
152+
as_stream : bool, default: False
153+
Boolean indicating whether to use the gRPC stream functionality (if possible).
137154
or the single message approach. By default, ``False``
138155
"""
139156
# Sanity checks on inputs
140157
if isinstance(file_location, Path):
141158
file_location = str(file_location)
142159
check_type(file_location, str)
160+
check_type(format, DesignFileFormat)
161+
check_type(as_stream, bool)
143162

144163
# Process response (as stream or single file)
164+
stream_msg = f"Downloading design in {format.value[0]} format using stream mechanism."
165+
single_msg = (
166+
f"Downloading design in {format.value[0]} format using single-message mechanism."
167+
)
145168
received_bytes = bytes()
146-
if as_stream:
147-
self._grpc_client.log.debug("Downloading design using stream mechanism.")
148-
response_iterator = self._commands_stub.DownloadFileStream(Empty())
149-
for response in response_iterator:
150-
received_bytes += response.chunk
151-
else:
152-
self._grpc_client.log.debug("Downloading design using single-message mechanism.")
153-
response = self._commands_stub.DownloadFile(Empty())
169+
if format is DesignFileFormat.SCDOCX:
170+
if as_stream:
171+
self._grpc_client.log.debug(stream_msg)
172+
response_iterator = self._commands_stub.DownloadFileStream(Empty())
173+
for response in response_iterator:
174+
received_bytes += response.chunk
175+
else:
176+
self._grpc_client.log.debug(single_msg)
177+
response = self._commands_stub.DownloadFile(Empty())
178+
received_bytes += response.data
179+
elif (format is DesignFileFormat.PARASOLID_TEXT) or (
180+
format is DesignFileFormat.PARASOLID_BIN
181+
):
182+
if as_stream:
183+
self._grpc_client.log.warning(
184+
"Streaming mechanism not supported for Parasolid format."
185+
)
186+
self._grpc_client.log.debug(single_msg)
187+
response = self._design_stub.ExportDesign(ExportDesignRequest(format=format.value[1]))
154188
received_bytes += response.data
155-
156-
# Write to file
157-
downloaded_file = open(file_location, "wb")
158-
downloaded_file.write(received_bytes)
159-
downloaded_file.close()
160-
161-
self._grpc_client.log.debug(f"Design successfully downloaded at location {file_location}.")
162-
163-
@protect_grpc
164-
def export_parasolid(
165-
self, file_location: Union[Path, str], export_text_format: Optional[bool] = False
166-
) -> None:
167-
"""Downloads a design in parasolid format from the active geometry server instance.
168-
169-
Parameters
170-
----------
171-
file_location : Union[Path, str]
172-
Location on disk where the file should be saved.
173-
export_text_format : bool, default: False
174-
Boolean indicating whether to request in binary format or in text format.
175-
``True`` will request text format, ``False`` will request binary format.
176-
By default, ``False``.
177-
"""
178-
if isinstance(file_location, Path):
179-
file_location = str(file_location)
180-
check_type(file_location, str)
181-
182-
self._grpc_client.log.debug("Downloading design parasolid using single-message mechanism.")
183-
184-
# Process response as single file
185-
received_bytes = bytes()
186-
response = self._design_stub.ExportDesign(
187-
ExportDesignRequest(
188-
format=PartExportFormat.PARTEXPORTFORMAT_PARASOLID_TEXT
189-
if export_text_format
190-
else PartExportFormat.PARTEXPORTFORMAT_PARASOLID_BINARY
189+
else:
190+
self._grpc_client.log.warning(
191+
f"{format.value[0]} format requested not supported. Ignoring download request."
191192
)
192-
)
193-
received_bytes += response.data
193+
return
194194

195195
# Write to file
196196
downloaded_file = open(file_location, "wb")

tests/integration/test_design.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import pytest
55

66
from ansys.geometry.core import Modeler
7-
from ansys.geometry.core.designer import CurveType, SharedTopologyType, SurfaceType
7+
from ansys.geometry.core.designer import (
8+
CurveType,
9+
DesignFileFormat,
10+
SharedTopologyType,
11+
SurfaceType,
12+
)
813
from ansys.geometry.core.designer.face import FaceLoopType
914
from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
1015
from ansys.geometry.core.math import UNITVECTOR3D_Z, Frame, Plane, Point2D, Point3D, UnitVector3D
@@ -731,11 +736,16 @@ def test_download_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactor
731736
# Check for parasolid exports
732737
binary_parasolid_file = tmp_path_factory.mktemp("scdoc_files_download") / "cylinder.x_b"
733738
text_parasolid_file = tmp_path_factory.mktemp("scdoc_files_download") / "cylinder_stream.x_t"
734-
design.export_parasolid(binary_parasolid_file, export_text_format=False)
735-
design.export_parasolid(text_parasolid_file, export_text_format=True)
739+
design.download(binary_parasolid_file, format=DesignFileFormat.PARASOLID_BIN, as_stream=True)
740+
design.download(text_parasolid_file, format=DesignFileFormat.PARASOLID_TEXT)
736741
assert binary_parasolid_file.exists()
737742
assert text_parasolid_file.exists()
738743

744+
# Check also the invalid format is not supported - no download performed
745+
invalid_file = tmp_path_factory.mktemp("scdoc_files_download") / "invalid.file"
746+
design.download(invalid_file, format=DesignFileFormat.INVALID, as_stream=True)
747+
assert not invalid_file.exists()
748+
739749

740750
def test_slot_extrusion(modeler: Modeler):
741751
"""Test the extrusion of a slot."""

0 commit comments

Comments
 (0)