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 6, 2024
1 parent e2f0a65 commit 9e18458
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/ansys/dpf/core/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""

import os
from pathlib import Path
import warnings
import traceback
from typing import Union
Expand Down Expand Up @@ -142,7 +143,7 @@ def set_result_file_path(self, filepath, key=""):
['/tmp/file.rst']
"""
extension = os.path.splitext(filepath)[1]
extension = Path(filepath).suffix
# Handle .res files from CFX
if key == "" and extension == ".res":
key = "cas"
Expand All @@ -162,7 +163,7 @@ def set_result_file_path(self, filepath, key=""):
def guess_result_key(filepath: str) -> str:
"""Guess result key for files without a file extension."""
result_keys = ["d3plot", "binout"]
base_name = os.path.basename(filepath)
base_name = Path(filepath).name
# Handle files without extension
for result_key in result_keys:
if result_key in base_name:
Expand All @@ -172,14 +173,13 @@ def guess_result_key(filepath: str) -> str:
@staticmethod
def guess_second_key(filepath: str) -> str:
"""For files with an h5 or cff extension, look for another extension."""

# These files usually end with .cas.h5 or .dat.h5
accepted = ["cas", "dat"]
without_ext = os.path.splitext(filepath)[0]
new_split = os.path.splitext(without_ext)
new_split = Path(filepath).suffixes
new_key = ""
if len(new_split) > 1:
key = new_split[1][1:]
if key in accepted:
new_key = key
if new_split[0].strip(".") in accepted:
new_key = new_split[0].strip(".")
return new_key

def set_domain_result_file_path(
Expand Down Expand Up @@ -241,9 +241,12 @@ def add_file_path(self, filepath, key="", is_domain: bool = False, domain_id=0):
"""
# The filename needs to be a fully qualified file name
if not os.path.dirname(filepath):
# if not os.path.dirname(filepath)

filepath = Path(filepath)
if not filepath.parent.name:
# append local path
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
filepath = Path.cwd() / filepath.name

Check warning on line 249 in src/ansys/dpf/core/data_sources.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/data_sources.py#L249

Added line #L249 was not covered by tests
if is_domain:
if key == "":
raise NotImplementedError("A key must be given when using is_domain=True.")
Expand Down Expand Up @@ -280,9 +283,10 @@ def add_domain_file_path(self, filepath, key, domain_id):
"""
# The filename needs to be a fully qualified file name
if not os.path.dirname(filepath):
filepath = Path(filepath)
if not filepath.parent.name:
# append local path
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
filepath = Path.cwd() / filepath.name

Check warning on line 289 in src/ansys/dpf/core/data_sources.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/data_sources.py#L289

Added line #L289 was not covered by tests
self._api.data_sources_add_domain_file_path_with_key_utf8(
self, str(filepath), key, domain_id
)
Expand All @@ -307,9 +311,10 @@ def add_file_path_for_specified_result(self, filepath, key="", result_key=""):
The default is ``""``, in which case the key is found directly.
"""
# The filename needs to be a fully qualified file name
if not os.path.dirname(filepath):
filepath = Path(filepath)
if not filepath.parent.name:
# append local path
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
filepath = Path.cwd() / filepath.name

Check warning on line 317 in src/ansys/dpf/core/data_sources.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/data_sources.py#L317

Added line #L317 was not covered by tests

self._api.data_sources_add_file_path_for_specified_result_utf8(
self, str(filepath), key, result_key
Expand Down

0 comments on commit 9e18458

Please sign in to comment.