Skip to content

Commit 1360f72

Browse files
committed
doc: modified another src file
1 parent 5151914 commit 1360f72

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
run_cmd = f"{cmd_file}"
156156
args = (
157157
f' -pluginpath "{plugin_path}" '
158-
f'-zippath \"{plugin_path / "assets" / "gltf_sites_winx64.zip"}\"'
158+
f'-zippath "{plugin_path / "assets" / "gltf_sites_winx64.zip"}"'
159159
)
160160
print(run_cmd + args)
161161
os.system(f"chmod u=rwx,o=x {cmd_file}")
@@ -183,7 +183,9 @@
183183

184184
tmp = Path(dpf.make_tmp_dir_server())
185185
dpf.upload_files_in_folder(dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin"), plugin_path)
186-
dpf.upload_file(str(plugin_path) + ".xml", dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin.xml"))
186+
dpf.upload_file(
187+
str(plugin_path) + ".xml", dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin.xml")
188+
)
187189

188190
dpf.load_library(
189191
dpf.path_utilities.join(tmp, "plugins", "gltf_plugin"),

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Download example datasets from https://github.com/ansys/example-data"""
2727

2828
import os
29+
from pathlib import Path
2930
import urllib.request
3031
import warnings
3132
from typing import Union
@@ -45,35 +46,36 @@ def delete_downloads(verbose=True):
4546
from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH, examples
4647

4748
not_to_remove = [
48-
getattr(examples.examples, item)
49+
Path(getattr(examples.examples, item))
4950
for item in dir(examples.examples)
5051
if not item.startswith("_")
5152
and not item.endswith("_")
5253
and isinstance(getattr(examples.examples, item), str)
5354
]
5455
not_to_remove.extend(
5556
[
56-
os.path.join(os.path.dirname(examples.__file__), "__init__.py"),
57-
os.path.join(os.path.dirname(examples.__file__), "downloads.py"),
58-
os.path.join(os.path.dirname(examples.__file__), "examples.py"),
57+
Path(examples.__file__).parent / "__init__.py",
58+
Path(examples.__file__).parent / "downloads.py",
59+
Path(examples.__file__).parent / "examples.py",
5960
]
6061
)
6162
for root, dirs, files in os.walk(LOCAL_DOWNLOADED_EXAMPLES_PATH, topdown=False):
63+
root = Path(root)
6264
if root not in not_to_remove:
6365
for name in files:
64-
if not os.path.join(root, name) in not_to_remove:
66+
file_path = root / name
67+
if not file_path in not_to_remove:
6568
try:
66-
os.remove(os.path.join(root, name))
69+
file_path.unlink()
6770
if verbose:
68-
print(f"deleting {os.path.join(root, name)}")
71+
print(f"deleting {file_path}")
6972
except Exception as e:
70-
warnings.warn(
71-
f"couldn't delete {os.path.join(root, name)} with error:\n {e.args}"
72-
)
73+
warnings.warn(f"couldn't delete {file_path} with error:\n {e.args}")
7374
for root, dirs, files in os.walk(LOCAL_DOWNLOADED_EXAMPLES_PATH, topdown=False):
7475
if len(dirs) == 0 and len(files) == 0:
7576
try:
76-
os.rmdir(root)
77+
root = Path(root)
78+
root.rmdir()
7779
if verbose:
7880
print(f"deleting {root}")
7981
except Exception as e:
@@ -89,21 +91,22 @@ def _retrieve_file(url, filename, directory):
8991
from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH
9092

9193
# First check if file has already been downloaded
92-
local_path = os.path.join(LOCAL_DOWNLOADED_EXAMPLES_PATH, directory, filename)
93-
local_path_no_zip = local_path.replace(".zip", "")
94-
if os.path.isfile(local_path_no_zip) or os.path.isdir(local_path_no_zip):
95-
return local_path_no_zip
94+
local_examples_download_path = Path(LOCAL_DOWNLOADED_EXAMPLES_PATH)
95+
local_path = local_examples_download_path / directory / filename
96+
local_path_no_zip = Path(str(local_path).replace(".zip", ""))
97+
if local_path_no_zip.is_file() or local_path_no_zip.is_dir():
98+
return str(local_path_no_zip)
9699

97100
# grab the correct url retriever
98101
urlretrieve = urllib.request.urlretrieve
99102

100-
dirpath = os.path.dirname(local_path)
101-
if not os.path.isdir(dirpath):
102-
os.makedirs(dirpath, exist_ok=True)
103+
dirpath = local_path.parent
104+
if not dirpath.is_dir():
105+
dirpath.mkdir(exist_ok=True)
103106

104107
# Perform download
105108
_, resp = urlretrieve(url, local_path)
106-
return local_path
109+
return str(local_path)
107110

108111

109112
def _download_file(directory, filename, should_upload: bool, server, return_local_path):
@@ -1999,7 +2002,7 @@ def find_distributed_msup_folder(
19992002
server,
20002003
return_local_path,
20012004
)
2002-
return os.path.dirname(path)
2005+
return str(Path(path).parent)
20032006

20042007

20052008
def download_average_filter_plugin(
@@ -2135,7 +2138,7 @@ def _retrieve_plugin(
21352138
for file in file_list:
21362139
EXAMPLE_FILE = GITHUB_SOURCE_URL + file
21372140
operator_file_path = _retrieve_file(EXAMPLE_FILE, file, directory="python_plugins")
2138-
path = os.path.dirname(
2139-
find_files(operator_file_path, should_upload, server, return_local_path)
2141+
path = str(
2142+
Path(find_files(operator_file_path, should_upload, server, return_local_path)).parent
21402143
)
21412144
return path

0 commit comments

Comments
 (0)