Skip to content

Commit 90dae29

Browse files
committed
Create examples.download_easy_statistics
1 parent d45cca2 commit 90dae29

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

examples/08-python-operators/00-wrapping_numpy_capabilities.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,9 @@
5656
#
5757
# Download and display the Python script.
5858

59-
from ansys.dpf.core import examples
60-
59+
from ansys.dpf.core.examples import download_easy_statistics
6160

62-
GITHUB_SOURCE_URL = (
63-
"https://github.com/ansys/pydpf-core/raw/master/doc/source/examples/07-python-operators/plugins"
64-
)
65-
EXAMPLE_FILE = GITHUB_SOURCE_URL + "/easy_statistics.py"
66-
operator_file_path = examples.downloads._retrieve_file(
67-
EXAMPLE_FILE, "easy_statistics.py", "python_plugins"
68-
)
61+
operator_file_path = download_easy_statistics()
6962

7063
with open(operator_file_path, "r") as f:
7164
for line in f.readlines():

src/ansys/dpf/core/examples/downloads.py

+43-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434

3535
EXAMPLE_REPO = "https://github.com/ansys/example-data/raw/master/"
3636

37+
GITHUB_SOURCE_URL = (
38+
"https://github.com/ansys/pydpf-core/raw/"
39+
"master/doc/source/examples/07-python-operators/plugins/"
40+
)
41+
3742

3843
def delete_downloads(verbose=True):
3944
"""Delete all downloaded examples to free space or update the files"""
@@ -2066,7 +2071,7 @@ def download_gltf_plugin(
20662071
--------
20672072
20682073
>>> from ansys.dpf.core import examples
2069-
>>> path = examples.download_average_filter_plugin()
2074+
>>> path = examples.download_gltf_plugin()
20702075
20712076
"""
20722077
file_list = [
@@ -2086,13 +2091,46 @@ def download_gltf_plugin(
20862091
)
20872092

20882093

2094+
def download_easy_statistics(
2095+
should_upload: bool = True, server=None, return_local_path=False
2096+
) -> Union[str, None]:
2097+
"""Make the plugin available server side, if the server is remote the plugin is uploaded
2098+
server side. Returns the path of the plugin folder.
2099+
2100+
Parameters
2101+
----------
2102+
should_upload:
2103+
Whether the file should be uploaded server side when the server is remote.
2104+
server:
2105+
Server with channel connected to the remote or local instance. When
2106+
``None``, attempts to use the global server.
2107+
return_local_path:
2108+
If ``True``, the local path is returned as is, without uploading, nor searching
2109+
for mounted volumes.
2110+
2111+
Returns
2112+
-------
2113+
str
2114+
Path to the plugin folder.
2115+
2116+
Examples
2117+
--------
2118+
2119+
>>> from ansys.dpf.core import examples
2120+
>>> path = examples.download_easy_statistics()
2121+
2122+
"""
2123+
file_name = "easy_statistics.py"
2124+
EXAMPLE_FILE = GITHUB_SOURCE_URL + file_name
2125+
operator_file_path = _retrieve_file(
2126+
EXAMPLE_FILE, filename=file_name, directory="python_plugins"
2127+
)
2128+
return find_files(operator_file_path, should_upload, server, return_local_path)
2129+
2130+
20892131
def _retrieve_plugin(
20902132
file_list: list[str], should_upload: bool = True, server=None, return_local_path=False
20912133
) -> Union[str, None]:
2092-
GITHUB_SOURCE_URL = (
2093-
"https://github.com/ansys/pydpf-core/raw/"
2094-
"master/doc/source/examples/07-python-operators/plugins/"
2095-
)
20962134
path = None
20972135
for file in file_list:
20982136
EXAMPLE_FILE = GITHUB_SOURCE_URL + file

0 commit comments

Comments
 (0)