From 8bf87819205ba50d65a3748d8c91bdddf74d4b35 Mon Sep 17 00:00:00 2001 From: moe-ad Date: Thu, 5 Dec 2024 17:16:15 +0100 Subject: [PATCH] doc: change to only .ci files --- .ci/build_wheel.py | 21 +++++++-------- .ci/code_generation.py | 19 ++++++------- .ci/run_examples.py | 9 ++++--- .ci/run_non_regression_examples.py | 43 +++++++++--------------------- .ci/update_dpf_dependencies.py | 40 ++++++++++++--------------- 5 files changed, 54 insertions(+), 78 deletions(-) diff --git a/.ci/build_wheel.py b/.ci/build_wheel.py index c3d43099ee..6acac20032 100644 --- a/.ci/build_wheel.py +++ b/.ci/build_wheel.py @@ -3,6 +3,7 @@ import argparse import subprocess +from pathlib import Path import os import sys import shutil @@ -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: @@ -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: @@ -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: diff --git a/.ci/code_generation.py b/.ci/code_generation.py index cb372e324a..98c3a9dd85 100644 --- a/.ci/code_generation.py +++ b/.ci/code_generation.py @@ -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 diff --git a/.ci/run_examples.py b/.ci/run_examples.py index 5a3da2b7bd..bd07cfea65 100644 --- a/.ci/run_examples.py +++ b/.ci/run_examples.py @@ -12,7 +12,8 @@ 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) # Get the DPF server version server = dpf.server.get_or_create_server(None) @@ -20,10 +21,10 @@ 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 examples_path.walk(): for subdirectory in subdirectories: - subdir = os.path.join(root, subdirectory) - for file in glob.iglob(os.path.join(subdir, "*.py")): + subdir = 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: diff --git a/.ci/run_non_regression_examples.py b/.ci/run_non_regression_examples.py index 247e074531..e492492fa8 100644 --- a/.ci/run_non_regression_examples.py +++ b/.ci/run_non_regression_examples.py @@ -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: diff --git a/.ci/update_dpf_dependencies.py b/.ci/update_dpf_dependencies.py index a6f9d72d13..8b201da3fb 100644 --- a/.ci/update_dpf_dependencies.py +++ b/.ci/update_dpf_dependencies.py @@ -15,7 +15,7 @@ import os import glob -import pathlib +from pathlib import Path import platform import shutil import zipfile @@ -23,21 +23,21 @@ 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) @@ -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(