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
70 changes: 35 additions & 35 deletions ansys/dpf/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_library(filename, name="", symbol="LoadOperators", server=None):

Parameters
----------
filename : str
filename : str or os.PathLike
Filename of the operator library.

name : str, optional
Expand Down Expand Up @@ -64,7 +64,7 @@ def upload_file_in_tmp_folder(file_path, new_file_name=None, server=None):

Parameters
----------
file_path : str
file_path : str or os.PathLike
file path on the client side to upload

new_file_name : str, optional
Expand Down Expand Up @@ -103,10 +103,10 @@ def upload_files_in_folder(

Parameters
----------
to_server_folder_path : str
to_server_folder_path : str or os.PathLike
folder path target where will be uploaded files on the server side

client_folder_path: str
client_folder_path: str or os.PathLike
folder path where the files that must be uploaded are located
on client side

Expand All @@ -133,10 +133,10 @@ def download_file(server_file_path, to_client_file_path, server=None):

Parameters
----------
server_file_path : str
server_file_path : str or os.PathLike
file path to download on the server side

to_client_file_path: str
to_client_file_path: str or os.PathLike
file path target where the file will be located client side

server : server.DPFServer, optional
Expand Down Expand Up @@ -168,10 +168,10 @@ def download_files_in_folder(

Parameters
----------
server_folder_path : str
server_folder_path : str or os.PathLike
folder path to download on the server side

to_client_folder_path: str
to_client_folder_path: str or os.PathLike
folder path target where the files will be located client side

specific_extension (optional) : str
Expand Down Expand Up @@ -202,10 +202,10 @@ def upload_file(file_path, to_server_file_path, server=None):

Parameters
----------
file_path : str
file_path : str or os.PathLike
file path on the client side to upload

to_server_file_path: str
to_server_file_path: str or os.PathLike
file path target where the file will be located server side

server : server.DPFServer, optional
Expand Down Expand Up @@ -340,15 +340,15 @@ def make_tmp_dir_server(self):
request = base_pb2.Empty()
return self._stub.CreateTmpDir(request).server_file_path

def load_library(self, filename, name="", symbol="LoadOperators"):
def load_library(self, file_path, name="", symbol="LoadOperators"):
"""Dynamically load an operators library for dpf.core.
Code containing this library's operators is generated in
ansys.dpf.core.operators

Parameters
----------
filename : str
Filename of the operator library.
file_path : str or os.PathLike
file_path of the operator library.

name : str, optional
Library name. Probably optional
Expand All @@ -365,13 +365,13 @@ def load_library(self, filename, name="", symbol="LoadOperators"):
"""
request = base_pb2.PluginRequest()
request.name = name
request.dllPath = filename
request.dllPath = str(file_path)
request.symbol = symbol
try:
self._stub.Load(request)
except Exception as e:
raise IOError(
f'Unable to load library "{filename}". File may not exist or'
f'Unable to load library "{str(file_path)}". File may not exist or'
f" is missing dependencies:\n{str(e)}"
)

Expand All @@ -391,7 +391,7 @@ def load_library(self, filename, name="", symbol="LoadOperators"):

code_gen = Operator("python_generator")
code_gen.connect(1, TARGET_PATH)
code_gen.connect(0, filename)
code_gen.connect(0, str(file_path))
code_gen.connect(2, False)
code_gen.run()

Expand Down Expand Up @@ -473,18 +473,18 @@ def download_file(self, server_file_path, to_client_file_path):

Parameters
----------
server_file_path : str
server_file_path : str or os.PathLike
file path to download on the server side

to_client_file_path: str
to_client_file_path: str or os.PathLike
file path target where the file will be located client side

Notes
-----
Print a progress bar
"""
request = base_pb2.DownloadFileRequest()
request.server_file_path = server_file_path
request.server_file_path = str(server_file_path)
chunks = self._stub.DownloadFile(request)
bar = None
tot_size = sys.float_info.max
Expand Down Expand Up @@ -517,10 +517,10 @@ def download_files_in_folder(

Parameters
----------
server_folder_path : str
server_folder_path : str or os.PathLike
Copy link
Contributor

Choose a reason for hiding this comment

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

@PProfizi could you please download the built doc out of the github actions and make sure that the API documentation of what you changed looks good? Because I'm afraid the "or" will not, since we always use ","

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000
Ok I'll change that. I started using "or" because a lot of times there was already "str, optional" and adding a coma seemed more confusing to me (like: "str, os.PathLike, optional").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000 I found an example of docstring similar to what I did here:

fields_container (ansys.grpc.dpf.collection_pb2.Collection or FieldsContainer, optional)

in

class ansys.dpf.core.custom_fields_container.ElShapeFieldsContainer(fields_container=None, server=None)

folder path to download on the server side

to_client_folder_path: str
to_client_folder_path: str or os.PathLike
folder path target where the files will be located client side

specific_extension (optional) : str
Expand All @@ -537,7 +537,7 @@ def download_files_in_folder(

"""
request = base_pb2.DownloadFileRequest()
request.server_file_path = server_folder_path
request.server_file_path = str(server_folder_path)
chunks = self._stub.DownloadFile(request)

num_files = 1
Expand All @@ -562,13 +562,13 @@ def download_files_in_folder(
):
separator = self._get_separator(server_path)
server_subpath = server_path.replace(
server_folder_path + separator, ""
str(server_folder_path) + separator, ""
)
subdir = ""
split = server_subpath.split(separator)
n = len(split)
i = 0
to_client_folder_path_copy = to_client_folder_path
to_client_folder_path_copy = str(to_client_folder_path)
if n > 1:
while i < (n - 1):
subdir = split[i]
Expand Down Expand Up @@ -607,10 +607,10 @@ def upload_files_in_folder(

Parameters
----------
to_server_folder_path : str
to_server_folder_path : str or os.PathLike
folder path target where will be uploaded files on the server side

client_folder_path: str
client_folder_path: str or os.PathLike
folder path where the files that must be uploaded are located
on client side

Expand All @@ -633,13 +633,13 @@ def upload_files_in_folder(
f,
filename,
server_paths,
to_server_folder_path,
str(to_server_folder_path),
subdirectory,
)
for file in files:
f = os.path.join(root, file)
server_paths = self._upload_and_get_server_path(
specific_extension, f, file, server_paths, to_server_folder_path
specific_extension, f, file, server_paths, str(to_server_folder_path)
)
break
return server_paths
Expand Down Expand Up @@ -678,10 +678,10 @@ def upload_file(self, file_path, to_server_file_path):

Parameters
----------
file_path : str
file_path : str or os.PathLike
file path on the client side to upload

to_server_file_path: str
to_server_file_path: str or os.PathLike
file path target where the file will be located server side

Returns
Expand All @@ -694,9 +694,9 @@ def upload_file(self, file_path, to_server_file_path):
Print a progress bar
"""
if os.stat(file_path).st_size == 0:
raise ValueError(file_path + " is empty")
raise ValueError(str(file_path) + " is empty")
return self._stub.UploadFile(
self.__file_chunk_yielder(file_path, to_server_file_path)
self.__file_chunk_yielder(str(file_path), str(to_server_file_path))
).server_file_path

@protect_grpc
Expand All @@ -706,7 +706,7 @@ def upload_file_in_tmp_folder(self, file_path, new_file_name=None):

Parameters
----------
file_path : str
file_path : str or os.PathLike
file path on the client side to upload

new_file_name : str, optional
Expand All @@ -727,10 +727,10 @@ def upload_file_in_tmp_folder(self, file_path, new_file_name=None):
else:
file_name = os.path.basename(file_path)
if os.stat(file_path).st_size == 0:
raise ValueError(file_path + " is empty")
raise ValueError(str(file_path) + " is empty")
return self._stub.UploadFile(
self.__file_chunk_yielder(
file_path=file_path, to_server_file_path=file_name, use_tmp_dir=True
file_path=str(file_path), to_server_file_path=file_name, use_tmp_dir=True
)
).server_file_path

Expand Down
18 changes: 9 additions & 9 deletions ansys/dpf/core/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DataSources:

Parameters
----------
result_path : str, optional
result_path : str or os.PathLike object, optional
Path of the result. The default is ``None``.
data_sources : ansys.grpc.dpf.data_sources_pb2.DataSources
gRPC data sources message. The default is ``None``.
Expand Down Expand Up @@ -68,7 +68,7 @@ def set_result_file_path(self, filepath, key=""):

Parameters
----------
filepath : str
filepath : str or os.PathLike object
Path to the result file.
key : str, optional
Extension of the file, which is used as a key for choosing the correct
Expand All @@ -89,7 +89,7 @@ def set_result_file_path(self, filepath, key=""):
request = data_sources_pb2.UpdateRequest()
request.result_path = True
request.key = key
request.path = filepath
request.path = str(filepath)
request.data_sources.CopyFrom(self._message)
self._stub.Update(request)

Expand All @@ -101,7 +101,7 @@ def set_domain_result_file_path(self, path, domain_id):

Parameters
----------
path: str
path: str or os.PathLike object
Path to the file.
domain_id: int, optional
Domain ID for the distributed files.
Expand All @@ -118,7 +118,7 @@ def set_domain_result_file_path(self, path, domain_id):
request.result_path = True
request.domain.domain_path = True
request.domain.domain_id = domain_id
request.path = path
request.path = str(path)
request.data_sources.CopyFrom(self._message)
self._stub.Update(request)

Expand All @@ -130,7 +130,7 @@ def add_file_path(self, filepath, key="", is_domain: bool = False, domain_id=0):

Parameters
----------
filepath : str
filepath : str or os.PathLike object
Path of the file.
key : str, optional
Extension of the file, which is used as a key for choosing the correct
Expand All @@ -155,7 +155,7 @@ def add_file_path(self, filepath, key="", is_domain: bool = False, domain_id=0):

request = data_sources_pb2.UpdateRequest()
request.key = key
request.path = filepath
request.path = str(filepath)
if is_domain:
request.domain.domain_path = True
request.domain.domain_id = domain_id
Expand All @@ -171,7 +171,7 @@ def add_file_path_for_specified_result(self, filepath, key="", result_key=""):

Parameters
----------
filepath : str
filepath : str or os.PathLike object
Path of the file.
key : str, optional
Extension of the file, which is used as a key for choosing the correct
Expand All @@ -189,7 +189,7 @@ def add_file_path_for_specified_result(self, filepath, key="", result_key=""):
request = data_sources_pb2.UpdateRequest()
request.key = key
request.result_key = result_key
request.path = filepath
request.path = str(filepath)
request.data_sources.CopyFrom(self._message)
self._stub.Update(request)

Expand Down
6 changes: 4 additions & 2 deletions ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def connect(self, pin, inpt, pin_out=0):
Number of the input pin.
inpt : str, int, double, bool, list of int, list of doubles,
Field, FieldsContainer, Scoping, ScopingsContainer, MeshedRegion,
MeshesContainer, DataSources, Operator
MeshesContainer, DataSources, Operator, os.PathLike
Object to connect to.
pin_out : int, optional
If the input is an operator, the output pin of the input operator. The
Expand Down Expand Up @@ -729,9 +729,11 @@ def _fillConnectionRequestMessage(request, inpt, server, pin_out=0):
workflow,
time_freq_support,
)

from pathlib import Path
if isinstance(inpt, str):
request.str = inpt
elif isinstance(inpt, Path):
request.str = str(inpt)
elif isinstance(inpt, bool):
request.bool = inpt
elif isinstance(inpt, int):
Expand Down
10 changes: 8 additions & 2 deletions ansys/dpf/core/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ def connect(self, inpt):
Parameters
----------
inpt : str, int, double, Field, FieldsContainer, Scoping, DataSources,
MeshedRegion, Output, Outputs, Operator
MeshedRegion, Output, Outputs, Operator, os.PathLike
Input of the operator.
"""
from pathlib import Path
# always convert ranges to lists
if isinstance(inpt, range):
inpt = list(inpt)
Expand All @@ -58,6 +59,8 @@ def connect(self, inpt):
)
elif isinstance(inpt, core.Model):
inpt = inpt.metadata.data_sources
elif isinstance(inpt, Path):
inpt = str(inpt)

input_type_name = type(inpt).__name__
if not (
Expand Down Expand Up @@ -182,9 +185,10 @@ def connect(self, inpt):
----------
inpt : str, int, double, Field, FieldsContainer, Scoping,
DataSources, MeshedRegion, ScopingsContainer, CyclicSupport,
..., Output, Outputs, Operator
..., Output, Outputs, Operator, os.PathLike
Input of the operator.
"""
from pathlib import Path
corresponding_pins = []
if isinstance(inpt, core.Operator):
if hasattr(inpt, "outputs"):
Expand All @@ -196,6 +200,8 @@ def connect(self, inpt):
)
elif isinstance(inpt, core.Model):
inpt = inpt.metadata.data_sources
elif isinstance(inpt, Path):
inpt = str(inpt)

input_type_name = type(inpt).__name__
for input_pin in self._inputs:
Expand Down
Loading