Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
48b7bea
Test template for reading design
RobPasMue Feb 9, 2023
cbec5d0
Add skeleton methods
RobPasMue Feb 9, 2023
2c8d78c
Activate testing (even though empty method)
RobPasMue Feb 9, 2023
a04e032
Improvements on instantiation of Design read
RobPasMue Feb 9, 2023
11643c0
WIP: reading through design
RobPasMue Feb 9, 2023
b47c998
WIP - failing tests
RobPasMue Feb 10, 2023
5e529ed
Implement upload_file()
jonahrb Feb 14, 2023
325ebc5
Write test
jonahrb Feb 14, 2023
adefb39
Merge branch 'main' into feat/query-server-for-design
RobPasMue Feb 16, 2023
b796ffa
Merge branch 'main' into feat/upload-file
RobPasMue Feb 16, 2023
8d542e4
Merge branch 'main' into feat/upload-file
jonahrb Feb 16, 2023
8b33702
read bytes of file inside method now
jonahrb Feb 16, 2023
d1150ef
fix test
jonahrb Feb 16, 2023
4755c82
Update src/ansys/geometry/core/modeler.py
RobPasMue Feb 17, 2023
c253067
Merge branch 'main' into feat/upload-file
RobPasMue Feb 17, 2023
add59d1
Merge branch 'main' into feat/query-server-for-design
RobPasMue Feb 17, 2023
6a5369b
Merge branch 'main' into feat/upload-file
RobPasMue Feb 17, 2023
d19855d
Merge branch 'main' into feat/query-server-for-design
RobPasMue Feb 21, 2023
1755974
Merge branch 'main' into feat/query-server-for-design
RobPasMue Mar 2, 2023
d7a4aca
Implementing JSON logic
RobPasMue Mar 2, 2023
2bf7140
Skip test run on Linux
RobPasMue Mar 2, 2023
a4c1c03
Merge branch 'main' into feat/query-server-for-design
RobPasMue Mar 3, 2023
d67c7f3
Merge branch 'main' into feat/query-server-for-design
RobPasMue Mar 9, 2023
c1af27f
Merge branch 'feat/query-server-for-design' into feat/read-json
jonahrb Apr 7, 2023
6817dec
fix imprint/project occurrences
jonahrb Apr 17, 2023
d1f5d02
add test
jonahrb Apr 17, 2023
7257809
non-JSON working implementation
jonahrb Apr 18, 2023
c3e96e8
read materials and named_selections
jonahrb Apr 20, 2023
39353a6
Merge branch 'main' into feat/read-existing-design
jonahrb Apr 20, 2023
2873987
SharedTopology and CoordinateSystems
jonahrb Apr 20, 2023
d5c4d3d
Merge branch 'main' into feat/read-json
RobPasMue Apr 21, 2023
d13916b
cleanup, resolve comments
jonahrb Apr 24, 2023
897e88e
Merge branch 'main' into feat/upload-file
jonahrb Apr 26, 2023
4d0f509
now using ObjectPaths for id
jonahrb Apr 28, 2023
9dd47da
Bump ansys-api-geometry 0.2.8
jonahrb May 2, 2023
918e413
cleanup
jonahrb May 2, 2023
c5fb211
Merge branch 'main' into feat/read-json
RobPasMue May 3, 2023
698c02c
fix: pre-commit issues
RobPasMue May 3, 2023
b30c177
Merge branch 'main' into feat/read-json
RobPasMue May 10, 2023
75e029b
fix: solving code style issues
RobPasMue May 10, 2023
215f98e
add tests to linux
jonahrb May 10, 2023
17a1d6f
cleanup
jonahrb May 10, 2023
a71af92
Merge branch 'feat/read-existing-design' into feat/upload-file
jonahrb May 10, 2023
c2c77c1
Merge branch 'main' into feat/upload-file
jonahrb May 11, 2023
5ffeb84
implement open file
jonahrb May 11, 2023
81f94fe
cleanup
jonahrb May 11, 2023
b82fc79
cleanup
jonahrb May 11, 2023
ee6e16b
Merge branch 'main' into feat/upload-file
RobPasMue May 11, 2023
51c6128
fix test failure
jonahrb May 16, 2023
0389294
Merge branch 'feat/upload-file' of https://github.com/pyansys/pygeome…
jonahrb May 16, 2023
5d67a5d
Merge branch 'main' into feat/upload-file
RobPasMue May 16, 2023
f5599c1
Merge branch 'main' into feat/upload-file
RobPasMue May 18, 2023
904b48d
created the test_open_file to download and open a file and make sure …
dastan-ansys May 18, 2023
dc86318
Update tests/integration/test_design.py
jonahrb May 18, 2023
c37b2ad
Apply suggestions from code review
dastan-ansys May 22, 2023
1426292
Update test_design_import.py
dastan-ansys May 22, 2023
7dace38
Update test_design_import.py
dastan-ansys May 22, 2023
67b45a4
Update test_design_import.py
dastan-ansys May 22, 2023
5b18c64
Merge branch 'main' into feat/upload-file
RobPasMue May 22, 2023
c704f14
Merge branch 'main' into feat/upload-file
RobPasMue May 24, 2023
9409a4c
Merge branch 'main' into feat/upload-file
RobPasMue May 24, 2023
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
35 changes: 35 additions & 0 deletions src/ansys/geometry/core/modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging
from pathlib import Path

from ansys.api.geometry.v0.commands_pb2 import UploadFileRequest
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
from beartype.typing import TYPE_CHECKING, Optional, Union
from grpc import Channel

Expand Down Expand Up @@ -103,6 +105,39 @@ def close(self) -> None:
"""``Modeler`` easy-access method to the client's ``close()`` method."""
return self.client.close()

def upload_file(self, file_path: str) -> str:
"""
Upload a file from the client to the server. ``file_path`` must include the extension.
The new file created on the server will have the same name and extension.

Parameters
----------
file_path : str
The path of the file. Must include extension.

Returns
-------
file_path : str
The full path of the uploaded file on the server machine.
"""
import os

if not os.path.exists(file_path):
message = f"Could not find file: {file_path}"
raise ValueError(message)
if os.path.isdir(file_path):
raise ValueError("File path must lead to a file, not a directory.")

file_name = os.path.split(file_path)[1]

with open(file_path, "rb") as file:
data = file.read()

c_stub = CommandsStub(self._client.channel)

response = c_stub.UploadFile(UploadFileRequest(data=data, file_name=file_name))
return response.file_path

def __repr__(self):
"""String representation of the modeler."""
lines = []
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/test_design.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test design interaction."""

import os

from pint import Quantity
import pytest

Expand Down Expand Up @@ -801,6 +803,25 @@ def test_download_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactor
assert fmd_file.exists()


def test_upload_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):
file = tmp_path_factory.mktemp("upload_file") / "example.scdocx"
file_size = 1024

# Write random bytes
with open(file, "wb") as fout:
fout.write(os.urandom(file_size))

assert file.exists()

# Read the file to get its bytes
with open(file, "rb") as f:
data = f.read()

# Upload file
path_on_server = modeler.upload_file(data, "example.scdocx")
assert path_on_server is not None


def test_slot_extrusion(modeler: Modeler):
"""Test the extrusion of a slot."""
# Create your design on the server side
Expand Down