Skip to content

Commit effc7f8

Browse files
authored
Fix/examples custom operator downloads (#1945)
* Switch to master for download in 00-wrapping_numpy_capabilities.py * Switch to master for download in 01-package_python_operators.py * Change downloads.py/_retrieve_file to not restrict to basename, allowing to define subpaths * Remove useless imports * Switch to master branch for 02-python_operators_with_dependencies.py
1 parent e03aa18 commit effc7f8

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@
5757
# Download and display the Python script.
5858

5959
from ansys.dpf.core import examples
60-
from ansys.dpf import core as dpf
6160

6261

6362
GITHUB_SOURCE_URL = (
64-
"https://github.com/ansys/pydpf-core/" "raw/examples/first_python_plugins/python_plugins"
63+
"https://github.com/ansys/pydpf-core/raw/master/doc/source/examples/07-python-operators/plugins"
6564
)
6665
EXAMPLE_FILE = GITHUB_SOURCE_URL + "/easy_statistics.py"
6766
operator_file_path = examples.downloads._retrieve_file(

examples/08-python-operators/01-package_python_operators.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,24 @@
5858
import os
5959

6060
from ansys.dpf.core import examples
61-
from ansys.dpf import core as dpf
6261

6362

6463
print("\033[1m average_filter_plugin")
65-
file_list = ["__init__.py", "operators.py", "operators_loader.py", "common.py"]
64+
file_list = [
65+
"average_filter_plugin/__init__.py",
66+
"average_filter_plugin/operators.py",
67+
"average_filter_plugin/operators_loader.py",
68+
"average_filter_plugin/common.py",
69+
]
6670
plugin_folder = None
6771
GITHUB_SOURCE_URL = (
6872
"https://github.com/ansys/pydpf-core/raw/"
69-
"examples/first_python_plugins/python_plugins/average_filter_plugin"
73+
"master/doc/source/examples/07-python-operators/plugins/"
7074
)
7175

7276
for file in file_list:
73-
EXAMPLE_FILE = GITHUB_SOURCE_URL + "/average_filter_plugin/" + file
74-
operator_file_path = examples.downloads._retrieve_file(
75-
EXAMPLE_FILE, file, "python_plugins/average_filter_plugin"
76-
)
77+
EXAMPLE_FILE = GITHUB_SOURCE_URL + file
78+
operator_file_path = examples.downloads._retrieve_file(EXAMPLE_FILE, file, "python_plugins")
7779
plugin_folder = os.path.dirname(operator_file_path)
7880
print(f"\033[1m {file}:\n \033[0m")
7981
with open(operator_file_path, "r") as f:

examples/08-python-operators/02-python_operators_with_dependencies.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import os
6161

6262
from ansys.dpf.core import examples
63-
from ansys.dpf import core as dpf
6463

6564

6665
print("\033[1m gltf_plugin")
@@ -73,17 +72,16 @@
7372
"gltf_plugin/texture.png",
7473
"gltf_plugin.xml",
7574
]
76-
import os
77-
78-
folder_root = os.path.join(os.getcwd().rsplit("pydpf-core", 1)[0], "pydpf-core")
79-
source_path_in_repo = r"doc\source\examples\07-python-operators\plugins"
80-
operator_folder = os.path.join(folder_root, source_path_in_repo)
81-
print(operator_folder)
8275
plugin_path = None
76+
folder_root = os.path.join(os.getcwd().rsplit("pydpf-core", 1)[0], "pydpf-core")
77+
GITHUB_SOURCE_URL = (
78+
"https://github.com/ansys/pydpf-core/raw/"
79+
"master/doc/source/examples/07-python-operators/plugins/"
80+
)
8381

8482
for file in file_list:
85-
operator_file_path = os.path.join(operator_folder, file)
86-
83+
EXAMPLE_FILE = GITHUB_SOURCE_URL + file
84+
operator_file_path = examples.downloads._retrieve_file(EXAMPLE_FILE, file, "python_plugins")
8785
print(f"\033[1m {file}\n \033[0m")
8886
if (
8987
os.path.splitext(file)[1] == ".py" or os.path.splitext(file)[1] == ".xml"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _retrieve_file(url, filename, directory):
8282
from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH
8383

8484
# First check if file has already been downloaded
85-
local_path = os.path.join(LOCAL_DOWNLOADED_EXAMPLES_PATH, directory, os.path.basename(filename))
85+
local_path = os.path.join(LOCAL_DOWNLOADED_EXAMPLES_PATH, directory, filename)
8686
local_path_no_zip = local_path.replace(".zip", "")
8787
if os.path.isfile(local_path_no_zip) or os.path.isdir(local_path_no_zip):
8888
return local_path_no_zip

0 commit comments

Comments
 (0)