Skip to content

Commit a9a968a

Browse files
committed
fix: reverted example files
1 parent f6aa2ab commit a9a968a

File tree

5 files changed

+55
-43
lines changed

5 files changed

+55
-43
lines changed

examples/05-file-IO/00-hdf5_double_float_comparison.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# Import the ``dpf-core`` module and its examples files, and then create a
3737
# temporary directory.
3838

39-
from pathlib import Path
39+
import os
4040

4141
from ansys.dpf import core as dpf
4242
from ansys.dpf.core import examples
@@ -78,8 +78,8 @@
7878
# Define a temporary folder for outputs
7979
tmpdir = dpf.core.make_tmp_dir_server(dpf.SERVER)
8080
files = [
81-
Path(dpf.path_utilities.join(tmpdir, "dpf_float.h5")),
82-
Path(dpf.path_utilities.join(tmpdir, "dpf_double.h5")),
81+
dpf.path_utilities.join(tmpdir, "dpf_float.h5"),
82+
dpf.path_utilities.join(tmpdir, "dpf_double.h5"),
8383
]
8484
###############################################################################
8585
# Export with simple precision.
@@ -98,8 +98,8 @@
9898
# Download the resulting .h5 files if necessary
9999

100100
if not dpf.SERVER.local_server:
101-
float_file_path = Path.cwd() / "dpf_float.h5"
102-
double_file_path = Path.cwd() / "dpf_double.h5"
101+
float_file_path = os.path.join(os.getcwd(), "dpf_float.h5")
102+
double_file_path = os.path.join(os.getcwd(), "dpf_double.h5")
103103
dpf.download_file(files[0], float_file_path)
104104
dpf.download_file(files[1], double_file_path)
105105
else:
@@ -109,8 +109,8 @@
109109

110110
###############################################################################
111111
# Compare simple precision versus double precision.
112-
float_precision = float_file_path.stat().st_size
113-
double_precision = double_file_path.stat().st_size
112+
float_precision = os.stat(float_file_path).st_size
113+
double_precision = os.stat(double_file_path).st_size
114114
print(
115115
f"size with float precision: {float_precision}\n"
116116
f"size with double precision: {double_precision}"

examples/05-file-IO/04-basic-load-file.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@
5858
# ~~~~~~~~~~~~~
5959
# Export the fields container in the CSV format:
6060

61-
from pathlib import Path
61+
import os
6262

6363
csv_file_name = "simple_bar_fc.csv"
6464
# Define an output path for the resulting .csv file
6565
if not dpf.SERVER.local_server:
6666
# Define it server-side if using a remote server
6767
tmp_dir_path = dpf.core.make_tmp_dir_server(dpf.SERVER)
68-
server_file_path = Path(dpf.path_utilities.join(tmp_dir_path, csv_file_name))
68+
server_file_path = dpf.path_utilities.join(tmp_dir_path, csv_file_name)
6969
else:
70-
server_file_path = Path.cwd() / csv_file_name
70+
server_file_path = os.path.join(os.getcwd(), csv_file_name)
7171

7272
# Perform the export to csv on the server side
7373
export_csv_operator = dpf.operators.serialization.field_to_csv()
@@ -81,7 +81,7 @@
8181
# Download the file ``simple_bar_fc.csv``:
8282

8383
if not dpf.SERVER.local_server:
84-
downloaded_client_file_path = Path.cwd() / "simple_bar_fc_downloaded.csv"
84+
downloaded_client_file_path = os.path.join(os.getcwd(), "simple_bar_fc_downloaded.csv")
8585
dpf.download_file(server_file_path, downloaded_client_file_path)
8686
else:
8787
downloaded_client_file_path = server_file_path
@@ -98,7 +98,7 @@
9898
mesh.plot(server_fc_out)
9999

100100
# Remove file to avoid polluting.
101-
downloaded_client_file_path.unlink()
101+
os.remove(downloaded_client_file_path)
102102

103103
###############################################################################
104104
# Make operations over the fields container

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@
5757
# Download and display the Python script.
5858

5959
from ansys.dpf.core.examples import download_easy_statistics
60-
from pathlib import Path
6160

62-
operator_file_path = Path(download_easy_statistics())
61+
operator_file_path = download_easy_statistics()
6362

64-
with operator_file_path.open() as file:
65-
for line in file.readlines():
63+
with open(operator_file_path, "r") as f:
64+
for line in f.readlines():
6665
print("\t\t\t" + line)
6766

6867
###############################################################################
@@ -77,14 +76,15 @@
7776
# - The third argument is the name of the function used to record operators.
7877
#
7978

79+
import os
8080
from ansys.dpf import core as dpf
8181
from ansys.dpf.core import examples
8282

8383
# Python plugins are not supported in process.
8484
dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer)
8585

86-
operator_server_file_path = Path(dpf.upload_file_in_tmp_folder(operator_file_path))
87-
dpf.load_library(operator_server_file_path.parent, "py_easy_statistics", "load_operators")
86+
operator_server_file_path = dpf.upload_file_in_tmp_folder(operator_file_path)
87+
dpf.load_library(os.path.dirname(operator_server_file_path), "py_easy_statistics", "load_operators")
8888

8989
###############################################################################
9090
# Instantiate the operator.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
# for the plug-in package that is used to record operators.
7373
#
7474

75+
import os
76+
7577
from ansys.dpf import core as dpf
7678
from ansys.dpf.core import examples
7779

@@ -81,7 +83,7 @@
8183
tmp = dpf.make_tmp_dir_server()
8284
dpf.upload_files_in_folder(dpf.path_utilities.join(tmp, "average_filter_plugin"), plugin_folder)
8385
dpf.load_library(
84-
dpf.path_utilities.join(tmp, "average_filter_plugin"),
86+
os.path.join(dpf.path_utilities.join(tmp, "average_filter_plugin")),
8587
"py_average_filter",
8688
"load_operators",
8789
)

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@
5858
# created for you.
5959

6060
import os
61-
from pathlib import Path
6261

6362
from ansys.dpf.core import examples
6463

65-
plugin_path = Path(examples.download_gltf_plugin())
66-
folder_root = Path(__file__).parent.parent.parent
64+
plugin_path = examples.download_gltf_plugin()
65+
folder_root = os.path.join(os.getcwd().rsplit("pydpf-core", 1)[0], "pydpf-core")
6766

6867
# %%
6968
# To add third-party modules as dependencies to a plug-in package, you must
@@ -84,9 +83,8 @@
8483
# To simplify this step, you can add a requirements file in the plug-in package:
8584
#
8685
print("\033[1m gltf_plugin/requirements.txt: \n \033[0m")
87-
requirements_path = plugin_path / "requirements.txt"
88-
with requirements_path.open("r") as file:
89-
for line in file.readlines():
86+
with open(os.path.join(plugin_path, "requirements.txt"), "r") as f:
87+
for line in f.readlines():
9088
print("\t\t\t" + line)
9189

9290

@@ -119,21 +117,26 @@
119117
#
120118
# create_sites_for_python_operators.sh -pluginpath /path/to/plugin -zippath /path/to/plugin/assets/linx64.zip # noqa: E501
121119

122-
site_path = plugin_path / "assets" / "gltf_sites_winx64.zip"
123-
if os.name == "nt" and not site_path.exists():
124-
cmd_file = (
125-
folder_root / "doc" / "source" / "user_guide" / "create_sites_for_python_operators.ps1"
120+
121+
if os.name == "nt" and not os.path.exists(
122+
os.path.join(plugin_path, "assets", "gltf_sites_winx64.zip")
123+
):
124+
cmd_file = os.path.join(
125+
folder_root,
126+
"doc",
127+
"source",
128+
"user_guide",
129+
"create_sites_for_python_operators.ps1",
126130
)
127131
args = [
128132
"powershell",
129-
str(cmd_file),
133+
cmd_file,
130134
"-pluginpath",
131-
str(plugin_path),
135+
plugin_path,
132136
"-zippath",
133-
str(plugin_path / "assets" / "gltf_sites_winx64.zip"),
137+
os.path.join(plugin_path, "assets", "gltf_sites_winx64.zip"),
134138
]
135139
print(args)
136-
137140
import subprocess
138141

139142
process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -147,15 +150,20 @@
147150
)
148151
else:
149152
print("Installing pygltf in a virtual environment succeeded")
150-
151-
elif os.name == "posix" and not site_path.exists():
152-
cmd_file = (
153-
folder_root / "doc" / "source" / "user_guide" / "create_sites_for_python_operators.sh"
153+
elif os.name == "posix" and not os.path.exists(
154+
os.path.join(plugin_path, "assets", "gltf_sites_linx64.zip")
155+
):
156+
cmd_file = os.path.join(
157+
folder_root,
158+
"doc",
159+
"source",
160+
"user_guide",
161+
"create_sites_for_python_operators.sh",
154162
)
155163
run_cmd = f"{cmd_file}"
156164
args = (
157165
f' -pluginpath "{plugin_path}" '
158-
f"-zippath \"{plugin_path / "assets" / "gltf_sites_winx64.zip"}\""
166+
f"-zippath \"{os.path.join(plugin_path, 'assets', 'gltf_sites_linx64.zip')}\""
159167
)
160168
print(run_cmd + args)
161169
os.system(f"chmod u=rwx,o=x {cmd_file}")
@@ -181,9 +189,9 @@
181189
# Python plugins are not supported in process.
182190
dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer)
183191

184-
tmp = Path(dpf.make_tmp_dir_server())
185-
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"))
192+
tmp = dpf.make_tmp_dir_server()
193+
dpf.upload_files_in_folder(dpf.path_utilities.join(tmp, "plugins", "gltf_plugin"), plugin_path)
194+
dpf.upload_file(plugin_path + ".xml", dpf.path_utilities.join(tmp, "plugins", "gltf_plugin.xml"))
187195

188196
dpf.load_library(
189197
dpf.path_utilities.join(tmp, "plugins", "gltf_plugin"),
@@ -227,6 +235,8 @@
227235
# Use the custom operator
228236
# -----------------------
229237

238+
import os
239+
230240
model = dpf.Model(dpf.upload_file_in_tmp_folder(examples.find_static_rst()))
231241

232242
mesh = model.metadata.meshed_region
@@ -235,14 +245,14 @@
235245
displacement = model.results.displacement()
236246
displacement.inputs.mesh_scoping(skin_mesh)
237247
displacement.inputs.mesh(skin_mesh)
238-
new_operator.inputs.path(str(tmp / "out"))
248+
new_operator.inputs.path(os.path.join(tmp, "out"))
239249
new_operator.inputs.mesh(skin_mesh)
240250
new_operator.inputs.field(displacement.outputs.fields_container()[0])
241251
new_operator.run()
242252

243253
print("operator ran successfully")
244254

245-
dpf.download_file(tmp / "out.glb", Path.cwd / "out.glb")
255+
dpf.download_file(os.path.join(tmp, "out.glb"), os.path.join(os.getcwd(), "out.glb"))
246256

247257
# %%
248258
# You can download :download:`output <images/thumb/out.glb>` from the ``gltf`` operator.

0 commit comments

Comments
 (0)