From 90dae297883f101ff6a39ffbe37c16009ee42ee9 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 29 Nov 2024 13:28:55 +0100 Subject: [PATCH] Create examples.download_easy_statistics --- .../00-wrapping_numpy_capabilities.py | 11 +---- src/ansys/dpf/core/examples/downloads.py | 48 +++++++++++++++++-- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/examples/08-python-operators/00-wrapping_numpy_capabilities.py b/examples/08-python-operators/00-wrapping_numpy_capabilities.py index 4309cecbd5..63d242ec39 100644 --- a/examples/08-python-operators/00-wrapping_numpy_capabilities.py +++ b/examples/08-python-operators/00-wrapping_numpy_capabilities.py @@ -56,16 +56,9 @@ # # Download and display the Python script. -from ansys.dpf.core import examples - +from ansys.dpf.core.examples import download_easy_statistics -GITHUB_SOURCE_URL = ( - "https://github.com/ansys/pydpf-core/raw/master/doc/source/examples/07-python-operators/plugins" -) -EXAMPLE_FILE = GITHUB_SOURCE_URL + "/easy_statistics.py" -operator_file_path = examples.downloads._retrieve_file( - EXAMPLE_FILE, "easy_statistics.py", "python_plugins" -) +operator_file_path = download_easy_statistics() with open(operator_file_path, "r") as f: for line in f.readlines(): diff --git a/src/ansys/dpf/core/examples/downloads.py b/src/ansys/dpf/core/examples/downloads.py index c29f665f5b..95fdb30fd0 100644 --- a/src/ansys/dpf/core/examples/downloads.py +++ b/src/ansys/dpf/core/examples/downloads.py @@ -34,6 +34,11 @@ EXAMPLE_REPO = "https://github.com/ansys/example-data/raw/master/" +GITHUB_SOURCE_URL = ( + "https://github.com/ansys/pydpf-core/raw/" + "master/doc/source/examples/07-python-operators/plugins/" +) + def delete_downloads(verbose=True): """Delete all downloaded examples to free space or update the files""" @@ -2066,7 +2071,7 @@ def download_gltf_plugin( -------- >>> from ansys.dpf.core import examples - >>> path = examples.download_average_filter_plugin() + >>> path = examples.download_gltf_plugin() """ file_list = [ @@ -2086,13 +2091,46 @@ def download_gltf_plugin( ) +def download_easy_statistics( + should_upload: bool = True, server=None, return_local_path=False +) -> Union[str, None]: + """Make the plugin available server side, if the server is remote the plugin is uploaded + server side. Returns the path of the plugin folder. + + Parameters + ---------- + should_upload: + Whether the file should be uploaded server side when the server is remote. + server: + Server with channel connected to the remote or local instance. When + ``None``, attempts to use the global server. + return_local_path: + If ``True``, the local path is returned as is, without uploading, nor searching + for mounted volumes. + + Returns + ------- + str + Path to the plugin folder. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.download_easy_statistics() + + """ + file_name = "easy_statistics.py" + EXAMPLE_FILE = GITHUB_SOURCE_URL + file_name + operator_file_path = _retrieve_file( + EXAMPLE_FILE, filename=file_name, directory="python_plugins" + ) + return find_files(operator_file_path, should_upload, server, return_local_path) + + def _retrieve_plugin( file_list: list[str], should_upload: bool = True, server=None, return_local_path=False ) -> Union[str, None]: - GITHUB_SOURCE_URL = ( - "https://github.com/ansys/pydpf-core/raw/" - "master/doc/source/examples/07-python-operators/plugins/" - ) path = None for file in file_list: EXAMPLE_FILE = GITHUB_SOURCE_URL + file