Skip to content

Commit

Permalink
doc: modified another src file
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Dec 9, 2024
1 parent 5151914 commit 1360f72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
run_cmd = f"{cmd_file}"
args = (
f' -pluginpath "{plugin_path}" '
f'-zippath \"{plugin_path / "assets" / "gltf_sites_winx64.zip"}\"'
f'-zippath "{plugin_path / "assets" / "gltf_sites_winx64.zip"}"'
)
print(run_cmd + args)
os.system(f"chmod u=rwx,o=x {cmd_file}")
Expand Down Expand Up @@ -183,7 +183,9 @@

tmp = Path(dpf.make_tmp_dir_server())
dpf.upload_files_in_folder(dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin"), plugin_path)
dpf.upload_file(str(plugin_path) + ".xml", dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin.xml"))
dpf.upload_file(
str(plugin_path) + ".xml", dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin.xml")
)

dpf.load_library(
dpf.path_utilities.join(tmp, "plugins", "gltf_plugin"),
Expand Down
47 changes: 25 additions & 22 deletions src/ansys/dpf/core/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Download example datasets from https://github.com/ansys/example-data"""

import os
from pathlib import Path
import urllib.request
import warnings
from typing import Union
Expand All @@ -45,35 +46,36 @@ def delete_downloads(verbose=True):
from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH, examples

not_to_remove = [
getattr(examples.examples, item)
Path(getattr(examples.examples, item))
for item in dir(examples.examples)
if not item.startswith("_")
and not item.endswith("_")
and isinstance(getattr(examples.examples, item), str)
]
not_to_remove.extend(
[
os.path.join(os.path.dirname(examples.__file__), "__init__.py"),
os.path.join(os.path.dirname(examples.__file__), "downloads.py"),
os.path.join(os.path.dirname(examples.__file__), "examples.py"),
Path(examples.__file__).parent / "__init__.py",
Path(examples.__file__).parent / "downloads.py",
Path(examples.__file__).parent / "examples.py",
]
)
for root, dirs, files in os.walk(LOCAL_DOWNLOADED_EXAMPLES_PATH, topdown=False):
root = Path(root)
if root not in not_to_remove:
for name in files:
if not os.path.join(root, name) in not_to_remove:
file_path = root / name
if not file_path in not_to_remove:
try:
os.remove(os.path.join(root, name))
file_path.unlink()
if verbose:
print(f"deleting {os.path.join(root, name)}")
print(f"deleting {file_path}")

Check warning on line 71 in src/ansys/dpf/core/examples/downloads.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L71 was not covered by tests
except Exception as e:
warnings.warn(
f"couldn't delete {os.path.join(root, name)} with error:\n {e.args}"
)
warnings.warn(f"couldn't delete {file_path} with error:\n {e.args}")

Check warning on line 73 in src/ansys/dpf/core/examples/downloads.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L73 was not covered by tests
for root, dirs, files in os.walk(LOCAL_DOWNLOADED_EXAMPLES_PATH, topdown=False):
if len(dirs) == 0 and len(files) == 0:
try:
os.rmdir(root)
root = Path(root)
root.rmdir()
if verbose:
print(f"deleting {root}")
except Exception as e:
Expand All @@ -89,21 +91,22 @@ def _retrieve_file(url, filename, directory):
from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH

# First check if file has already been downloaded
local_path = os.path.join(LOCAL_DOWNLOADED_EXAMPLES_PATH, directory, filename)
local_path_no_zip = local_path.replace(".zip", "")
if os.path.isfile(local_path_no_zip) or os.path.isdir(local_path_no_zip):
return local_path_no_zip
local_examples_download_path = Path(LOCAL_DOWNLOADED_EXAMPLES_PATH)
local_path = local_examples_download_path / directory / filename
local_path_no_zip = Path(str(local_path).replace(".zip", ""))
if local_path_no_zip.is_file() or local_path_no_zip.is_dir():
return str(local_path_no_zip)

# grab the correct url retriever
urlretrieve = urllib.request.urlretrieve

dirpath = os.path.dirname(local_path)
if not os.path.isdir(dirpath):
os.makedirs(dirpath, exist_ok=True)
dirpath = local_path.parent
if not dirpath.is_dir():
dirpath.mkdir(exist_ok=True)

# Perform download
_, resp = urlretrieve(url, local_path)
return local_path
return str(local_path)


def _download_file(directory, filename, should_upload: bool, server, return_local_path):
Expand Down Expand Up @@ -1999,7 +2002,7 @@ def find_distributed_msup_folder(
server,
return_local_path,
)
return os.path.dirname(path)
return str(Path(path).parent)

Check warning on line 2005 in src/ansys/dpf/core/examples/downloads.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2005 was not covered by tests


def download_average_filter_plugin(
Expand Down Expand Up @@ -2135,7 +2138,7 @@ def _retrieve_plugin(
for file in file_list:
EXAMPLE_FILE = GITHUB_SOURCE_URL + file
operator_file_path = _retrieve_file(EXAMPLE_FILE, file, directory="python_plugins")
path = os.path.dirname(
find_files(operator_file_path, should_upload, server, return_local_path)
path = str(
Path(find_files(operator_file_path, should_upload, server, return_local_path)).parent
)
return path

0 comments on commit 1360f72

Please sign in to comment.