Skip to content

Commit

Permalink
Merge branch 'master' into feat/migration-from-autodoc-to-autoapi
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Dec 13, 2024
2 parents d16becb + af30b32 commit ed2b6e8
Show file tree
Hide file tree
Showing 54 changed files with 1,772 additions and 447 deletions.
21 changes: 10 additions & 11 deletions .ci/build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import subprocess
from pathlib import Path
import os
import sys
import shutil
Expand Down Expand Up @@ -39,15 +40,13 @@
print("Created temporary directory: ", tmpdirname)

# Create the temporary build-opts.cfg
build_opts_path = os.path.join(tmpdirname, "build-opts.cfg")
with open(build_opts_path, "w") as build_opts_file:
build_opts_file.write(f"[bdist_wheel]\nplat-name={requested_platform}")
os.environ["DIST_EXTRA_CONFIG"] = build_opts_path
build_opts_path = Path(tmpdirname) / "build-opts.cfg"

build_opts_path.write_text(f"[bdist_wheel]\nplat-name={requested_platform}", encoding="utf-8")
os.environ["DIST_EXTRA_CONFIG"] = str(build_opts_path)

# Move the binaries
gatebin_folder_path = os.path.join(
os.path.curdir, os.path.join("src", "ansys", "dpf", "gatebin")
)
gatebin_folder_path = Path.cwd() / "src" / "ansys" / "dpf" / "gatebin"
binaries_to_move = []
moved = []
if "win" in requested_platform or "any" == requested_platform:
Expand All @@ -60,15 +59,15 @@
binaries_to_move.extend(["_version.py"])

for binary_name in binaries_to_move:
src = os.path.join(gatebin_folder_path, binary_name)
dst = os.path.join(tmpdirname, binary_name)
src = gatebin_folder_path / binary_name
dst = Path(tmpdirname) / binary_name
print(f"Moving {src} to {dst}")
shutil.move(src=src, dst=dst)
moved.append([dst, src])

if "any" == requested_platform:
# Also remove the gatebin folder
os.rmdir(gatebin_folder_path)
gatebin_folder_path.rmdir()

# Call the build
if not args.wheelhouse:
Expand All @@ -83,7 +82,7 @@

if "any" == requested_platform:
# Recreate the gatebin folder
os.mkdir(gatebin_folder_path)
gatebin_folder_path.mkdir()

# Move binaries back
for move_back in moved:
Expand Down
20 changes: 10 additions & 10 deletions .ci/code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import shutil


local_dir = os.path.dirname(os.path.abspath(__file__))
TARGET_PATH = os.path.join(local_dir, os.pardir, "src", "ansys", "dpf", "core", "operators")
files = glob.glob(os.path.join(TARGET_PATH, "*"))
for f in files:
if Path(f).stem == "specification":
local_dir = Path(__file__).parent
TARGET_PATH = local_dir.parent / "src" / "ansys" / "dpf" / "core" / "operators"
files = TARGET_PATH.glob("*")
for file_path in files:
if file_path.stem == "specification":
continue
if Path(f).name == "build.py":
if file_path.name == "build.py":
continue
if Path(f).name == "operator.mustache":
if file_path.name == "operator.mustache":
continue
try:
if os.path.isdir(f):
shutil.rmtree(f)
if file_path.is_dir():
shutil.rmtree(file_path)
else:
os.remove(f)
file_path.unlink()
except:
pass

Expand Down
19 changes: 10 additions & 9 deletions .ci/run_examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import glob
import pathlib
from pathlib import Path
import subprocess
import sys

Expand All @@ -11,22 +11,23 @@
os.environ["PYVISTA_OFF_SCREEN"] = "true"
os.environ["MPLBACKEND"] = "Agg"

actual_path = pathlib.Path(__file__).parent.absolute()
print(os.path.join(actual_path, os.path.pardir, "examples"))
actual_path = Path(__file__).parent.absolute()
examples_path = actual_path.parent / "examples"
print(examples_path)

# Get the DPF server version
server = dpf.server.get_or_create_server(None)
server_version = server.version
server.shutdown()
print(f"Server version: {server_version}")

for root, subdirectories, files in os.walk(os.path.join(actual_path, os.path.pardir, "examples")):
for root, subdirectories, files in os.walk(examples_path):
for subdirectory in subdirectories:
subdir = os.path.join(root, subdirectory)
for file in glob.iglob(os.path.join(subdir, "*.py")):
if sys.platform == "linux" and "08-python-operators" in file:
subdir = Path(root) / subdirectory
for file in subdir.glob("*.py"):
if sys.platform == "linux" and "08-python-operators" in str(file):
continue
elif "win" in sys.platform and "06-distributed_stress_averaging" in file:
elif "win" in sys.platform and "06-distributed_stress_averaging" in str(file):
# Currently very unstable in the GH CI
continue
print("\n--------------------------------------------------")
Expand All @@ -36,7 +37,7 @@
print(f"Example skipped as it requires DPF {minimum_version_str}.", flush=True)
continue
try:
out = subprocess.check_output([sys.executable, file])
out = subprocess.check_output([sys.executable, str(file)])
except subprocess.CalledProcessError as e:
sys.stderr.write(str(e.args))
if e.returncode != 3221225477:
Expand Down
47 changes: 14 additions & 33 deletions .ci/run_non_regression_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,30 @@
os.environ["MPLBACKEND"] = "Agg"

actual_path = pathlib.Path(__file__).parent.absolute()
print(os.path.join(actual_path, os.path.pardir, "examples"))
examples_path = actual_path.parent / "examples"
print(examples_path)


list_tests = [
os.path.join(actual_path, os.path.pardir, "examples", "00-basic"),
os.path.join(actual_path, os.path.pardir, "examples", "01-transient_analyses"),
os.path.join(actual_path, os.path.pardir, "examples", "02-modal_analyses"),
os.path.join(actual_path, os.path.pardir, "examples", "03-harmonic_analyses"),
os.path.join(actual_path, os.path.pardir, "examples", "06-plotting", "00-basic_plotting.py"),
os.path.join(
actual_path,
os.path.pardir,
"examples",
"06-plotting",
"05-plot_on_warped_mesh.py",
),
os.path.join(
actual_path,
os.path.pardir,
"examples",
"07-distributed-post",
"00-distributed_total_disp.py",
),
examples_path / "00-basic",
examples_path / "01-transient_analyses",
examples_path / "02-modal_analyses",
examples_path / "03-harmonic_analyses",
examples_path / "06-plotting" / "00-basic_plotting.py",
examples_path / "06-plotting" / "05-plot_on_warped_mesh.py",
examples_path / "07-distributed-post" / "00-distributed_total_disp.py",
]

if core.SERVER_CONFIGURATION != core.AvailableServerConfigs.InProcessServer:
list_tests.append(
os.path.join(
actual_path,
os.path.pardir,
"examples",
"08-python-operators",
"00-wrapping_numpy_capabilities.py",
)
)
list_tests.append(examples_path / "08-python-operators" / "00-wrapping_numpy_capabilities.py")

for path in list_tests:
if os.path.isdir(path):
for file in glob.iglob(os.path.join(path, "*.py")):
if path.is_dir():
for file in path.glob("*.py"):
print("\n--------------------------------------------------")
print(file)
try:
subprocess.check_call([sys.executable, file])
subprocess.check_call([sys.executable, str(file)])
except subprocess.CalledProcessError as e:
sys.stderr.write(str(e.args))
if e.returncode != 3221225477:
Expand All @@ -61,7 +42,7 @@
print("\n--------------------------------------------------")
print(path)
try:
subprocess.check_call([sys.executable, file])
subprocess.check_call([sys.executable, str(file)])
except subprocess.CalledProcessError as e:
sys.stderr.write(str(e.args))
if e.returncode != 3221225477:
Expand Down
40 changes: 17 additions & 23 deletions .ci/update_dpf_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@

import os
import glob
import pathlib
from pathlib import Path
import platform
import shutil
import zipfile


grpc_path_key = "DPFDV_ROOT"
gate_path_key = "ANSYSDPFPYGATE_ROOT"
core_path = pathlib.Path(__file__).parent.parent.resolve()
core_path = Path(__file__).parent.parent
if "ANSYSDPFCORE_ROOT" in os.environ:
core_path = os.environ["ANSYSDPFCORE_ROOT"]

grpc_path = os.getenv(grpc_path_key, None)
gate_path = os.getenv(gate_path_key, None)

if grpc_path is not None:
if grpc_path:
# Update ansys-grpc-dpf with latest in proto/dist
print("Updating ansys.grpc.dpf")
dist_path = os.path.join(grpc_path, "proto", "dist", "*")
dist_path = Path(grpc_path) / "proto" / "dist"
print(f"from {dist_path}")
destination = os.path.join(core_path, "src")
destination = Path(core_path) / "src"
print(f"into {destination}")
latest_wheel = max(glob.glob(dist_path), key=os.path.getctime)
latest_wheel = max(dist_path.glob("*"), key=os.path.getctime)
with zipfile.ZipFile(latest_wheel, "r") as wheel:
for file in wheel.namelist():
# print(file)
Expand All @@ -50,40 +50,34 @@
else:
print(f"{grpc_path_key} environment variable is not defined. " "Cannot update ansys-grpc-dpf.")

if gate_path is not None:
if gate_path:
# Update ansys-dpf-gate
print("Updating ansys.dpf.gate generated code")
dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys", "dpf", "gate", "generated")
dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "generated"
print(f"from {dist_path}")
destination = os.path.join(core_path, "src", "ansys", "dpf", "gate", "generated")
destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "generated"
print(f"into {destination}")
shutil.copytree(
src=dist_path,
dst=destination,
dirs_exist_ok=True,
ignore=lambda directory, contents: ["__pycache__"] if directory[-5:] == "gate" else [],
ignore=lambda directory, contents: ["__pycache__"] if str(directory)[-5:] == "gate" else [],
)
dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys", "dpf", "gate", "__init__.py")

dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "__init__.py"
print(f"from {dist_path}")
destination = os.path.join(core_path, "src", "ansys", "dpf", "gate", "__init__.py")
destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "__init__.py"
print(f"into {destination}")
shutil.copy(
src=dist_path,
dst=destination,
)
shutil.copy(src=dist_path, dst=destination)
print("Done updating ansys.dpf.gate generated code")

# Update ansys-dpf-gatebin
print("Updating ansys.dpf.gatebin")
dist_path = os.path.join(gate_path, "ansys-dpf-gatebin", "ansys")
dist_path = Path(gate_path) / "ansys-dpf-gatebin" / "ansys"
print(f"from {dist_path}")
destination = os.path.join(core_path, "src", "ansys")
destination = Path(core_path) / "src" / "ansys"
print(f"into {destination}")
shutil.copytree(
src=dist_path,
dst=destination,
dirs_exist_ok=True,
)
shutil.copytree(src=dist_path, dst=destination, dirs_exist_ok=True)
print(f"Done updating ansys.dpf.gatebin for {platform.system()}")
else:
print(
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_operators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
git status
- name: "Create Pull Request"
uses: peter-evans/create-pull-request@v4
uses: peter-evans/create-pull-request@v7
with:
delete-branch: true
add-paths: |
Expand Down
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
ignored_pattern += f"|{example_name}"
ignored_pattern += "|11-server_types.py"
ignored_pattern += "|06-distributed_stress_averaging.py"
ignored_pattern += "|02-python_operators_with_dependencies.py"
ignored_pattern += r")"

# Autoapi ignore pattern
Expand Down
14 changes: 7 additions & 7 deletions examples/05-file-IO/00-hdf5_double_float_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# Import the ``dpf-core`` module and its examples files, and then create a
# temporary directory.

import os
from pathlib import Path

from ansys.dpf import core as dpf
from ansys.dpf.core import examples
Expand Down Expand Up @@ -78,8 +78,8 @@
# Define a temporary folder for outputs
tmpdir = dpf.core.make_tmp_dir_server(dpf.SERVER)
files = [
dpf.path_utilities.join(tmpdir, "dpf_float.h5"),
dpf.path_utilities.join(tmpdir, "dpf_double.h5"),
Path(dpf.path_utilities.join(tmpdir, "dpf_float.h5")),
Path(dpf.path_utilities.join(tmpdir, "dpf_double.h5")),
]
###############################################################################
# Export with simple precision.
Expand All @@ -98,8 +98,8 @@
# Download the resulting .h5 files if necessary

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

###############################################################################
# Compare simple precision versus double precision.
float_precision = os.stat(float_file_path).st_size
double_precision = os.stat(double_file_path).st_size
float_precision = float_file_path.stat().st_size
double_precision = double_file_path.stat().st_size
print(
f"size with float precision: {float_precision}\n"
f"size with double precision: {double_precision}"
Expand Down
10 changes: 5 additions & 5 deletions examples/05-file-IO/04-basic-load-file.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@
# ~~~~~~~~~~~~~
# Export the fields container in the CSV format:

import os
from pathlib import Path

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

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

if not dpf.SERVER.local_server:
downloaded_client_file_path = os.path.join(os.getcwd(), "simple_bar_fc_downloaded.csv")
downloaded_client_file_path = Path.cwd() / "simple_bar_fc_downloaded.csv"
dpf.download_file(server_file_path, downloaded_client_file_path)
else:
downloaded_client_file_path = server_file_path
Expand All @@ -98,7 +98,7 @@
mesh.plot(server_fc_out)

# Remove file to avoid polluting.
os.remove(downloaded_client_file_path)
downloaded_client_file_path.unlink()

###############################################################################
# Make operations over the fields container
Expand Down
Loading

0 comments on commit ed2b6e8

Please sign in to comment.