Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junk: will delete the branch shortly #1956

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 10 additions & 9 deletions .ci/code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
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, "*"))
local_dir = Path(__file__).parent
TARGET_PATH = local_dir.parent / "src" / "ansys" / "dpf" / "core" / "operators"
files = glob.glob(str(TARGET_PATH / "*"))
for f in files:
if Path(f).stem == "specification":
file_path = Path(f)
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
13 changes: 7 additions & 6 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,19 +11,20 @@
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")):
subdir = Path(root) / subdirectory
for file in glob.iglob(str(subdir / "*.py")):
if sys.platform == "linux" and "08-python-operators" in file:
continue
elif "win" in sys.platform and "06-distributed_stress_averaging" in file:
Expand Down
43 changes: 12 additions & 31 deletions .ci/run_non_regression_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,26 @@
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 glob.iglob(str(path / "*.py")):
print("\n--------------------------------------------------")
print(file)
try:
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(glob.glob(str(dist_path)), 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
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
12 changes: 6 additions & 6 deletions examples/08-python-operators/00-wrapping_numpy_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@
# Download and display the Python script.

from ansys.dpf.core.examples import download_easy_statistics
from pathlib import Path

operator_file_path = download_easy_statistics()
operator_file_path = Path(download_easy_statistics())

with open(operator_file_path, "r") as f:
for line in f.readlines():
with operator_file_path.open() as file:
for line in file.readlines():
print("\t\t\t" + line)

###############################################################################
Expand All @@ -76,15 +77,14 @@
# - The third argument is the name of the function used to record operators.
#

import os
from ansys.dpf import core as dpf
from ansys.dpf.core import examples

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

operator_server_file_path = dpf.upload_file_in_tmp_folder(operator_file_path)
dpf.load_library(os.path.dirname(operator_server_file_path), "py_easy_statistics", "load_operators")
operator_server_file_path = Path(dpf.upload_file_in_tmp_folder(operator_file_path))
dpf.load_library(operator_server_file_path.parent, "py_easy_statistics", "load_operators")

###############################################################################
# Instantiate the operator.
Expand Down
Loading
Loading