Skip to content

Commit 3eb6e99

Browse files
mkundu1pyansys-ci-bothpohekar
authored
build: Bump version 0.30.4 (#3954)
Integrate #3951 in 0.30 release --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Harshal Pohekar <[email protected]>
1 parent d7ad534 commit 3eb6e99

File tree

8 files changed

+110
-21
lines changed

8 files changed

+110
-21
lines changed

doc/changelog.d/3939.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip test_reduction_does_not_modify_case [skip tests]

doc/changelog.d/3951.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Preprocess xml content before sending it to ElementTree parser

src/ansys/fluent/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
from ansys.fluent.core.utils.fluent_version import FluentVersion # noqa: F401
6363
from ansys.fluent.core.utils.setup_for_fluent import setup_for_fluent # noqa: F401
6464

65-
__version__ = "0.30.3"
65+
__version__ = "0.30.4"
6666

6767
_VERSION_INFO = None
6868
"""

src/ansys/fluent/core/filereader/case_file.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545
from pathlib import Path
4646
from typing import Dict, List
4747

48-
from defusedxml.ElementTree import parse
48+
import defusedxml.ElementTree as ET
4949
import numpy as np
5050

5151
from ansys.fluent.core.solver.error_message import allowed_name_error_message
5252

5353
from . import lispy
54+
from .pre_processor import remove_unsupported_xml_chars
5455

5556
try:
5657
import h5py
@@ -731,15 +732,17 @@ def _get_processed_string(input_string: bytes) -> str:
731732

732733

733734
def _get_case_file_name_from_flprj(flprj_file):
734-
tree = parse(flprj_file)
735-
root = tree.getroot()
736-
folder_name = root.find("Metadata").find("CurrentSimulation").get("value")[5:-1]
737-
# If the project file name begins with a digit then the node to find will be prepended
738-
# with "_". Rather than making any assumptions that this is a hard rule, or what
739-
# the scope of the rule is, simply retry with the name prepended:
740-
folder_obj = (
741-
root.find(folder_name)
742-
if root.find(folder_name) and len(root.find(folder_name)) > 0
743-
else root.find("_" + folder_name)
744-
)
745-
return folder_obj.find("Input").find("Case").find("Target").get("value")
735+
with open(flprj_file, "r") as file:
736+
content = file.read()
737+
content = remove_unsupported_xml_chars(content)
738+
root = ET.fromstring(content)
739+
folder_name = root.find("Metadata").find("CurrentSimulation").get("value")[5:-1]
740+
# If the project file name begins with a digit then the node to find will be prepended
741+
# with "_". Rather than making any assumptions that this is a hard rule, or what
742+
# the scope of the rule is, simply retry with the name prepended:
743+
folder_obj = (
744+
root.find(folder_name)
745+
if root.find(folder_name) and len(root.find(folder_name)) > 0
746+
else root.find("_" + folder_name)
747+
)
748+
return folder_obj.find("Input").find("Case").find("Target").get("value")

src/ansys/fluent/core/filereader/data_file.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
from os.path import dirname
4040
from pathlib import Path
4141

42-
from defusedxml.ElementTree import parse
42+
import defusedxml.ElementTree as ET
4343
import numpy as np
4444

4545
from . import lispy
46+
from .pre_processor import remove_unsupported_xml_chars
4647

4748
try:
4849
import h5py
@@ -224,7 +225,15 @@ def get_face_vector_field_data(self, phase_name: str, surface_id: int) -> np.arr
224225

225226

226227
def _get_data_file_name_from_flprj(flprj_file):
227-
tree = parse(flprj_file)
228-
root = tree.getroot()
229-
folder_name = root.find("Metadata").find("CurrentSimulation").get("value")[5:-1]
230-
return root.find(folder_name).find("Input").find("Case").find("Target").get("value")
228+
with open(flprj_file, "r") as file:
229+
content = file.read()
230+
content = remove_unsupported_xml_chars(content)
231+
root = ET.fromstring(content)
232+
folder_name = root.find("Metadata").find("CurrentSimulation").get("value")[5:-1]
233+
return (
234+
root.find(folder_name)
235+
.find("Input")
236+
.find("Case")
237+
.find("Target")
238+
.get("value")
239+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""
24+
Pre-processor for XML content from Fluent project files.
25+
"""
26+
27+
import re
28+
29+
30+
def remove_unsupported_xml_chars(content: str):
31+
"""Remove unsupported XML characters from the content."""
32+
# Replace double colons in tag names with double underscores
33+
content = re.sub(r"</?([^> ]+)::", r"<\1__", content)
34+
35+
return content

tests/test_casereader.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
# SOFTWARE.
2222

2323
from os.path import dirname, join
24-
import pathlib
24+
from pathlib import Path
2525
import shutil
2626

27+
import defusedxml.ElementTree as ET
2728
import pytest
2829

2930
from ansys.fluent.core import examples
@@ -34,7 +35,9 @@
3435
MeshType,
3536
_get_processed_string,
3637
)
38+
from ansys.fluent.core.filereader.case_file import CaseFile
3739
from ansys.fluent.core.filereader.case_file import CaseFile as CaseReader
40+
from ansys.fluent.core.filereader.pre_processor import remove_unsupported_xml_chars
3841

3942

4043
def call_casereader(
@@ -145,7 +148,7 @@ def create_dir_structure_locally(copy_1: bool = False, copy_2: bool = False):
145148
return_without_path=False,
146149
)
147150
prj_dir = join(dirname(case_file_name), case_file_dir)
148-
pathlib.Path(prj_dir).mkdir(parents=True, exist_ok=True)
151+
Path(prj_dir).mkdir(parents=True, exist_ok=True)
149152
if copy_1:
150153
shutil.copy2(case_file_name, prj_dir)
151154
if copy_2:
@@ -344,3 +347,39 @@ def test_mesh_reader():
344347
assert mesh_reader_2d.precision() is None
345348
assert mesh_reader_3d.precision() is None
346349
assert case_reader.precision() == 2
350+
351+
352+
def test_preprocessor():
353+
content = """
354+
<Project type="object" class="PFolder">
355+
<Metadata type="object" class="ansys::Project::MetadataHoof">
356+
<ProjectStoragePolicy::FolderEnabled class="string" value="true"/>
357+
</Metadata>
358+
</Project>
359+
"""
360+
expected = """
361+
<Project type="object" class="PFolder">
362+
<Metadata type="object" class="ansys::Project::MetadataHoof">
363+
<ProjectStoragePolicy__FolderEnabled class="string" value="true"/>
364+
</Metadata>
365+
</Project>
366+
"""
367+
with pytest.raises(ET.ParseError):
368+
ET.fromstring(content)
369+
pre_processed = remove_unsupported_xml_chars(content)
370+
assert pre_processed == expected
371+
assert ET.fromstring(pre_processed)
372+
373+
374+
def test_read_flprj_3891():
375+
# Read the .flprj file from https://github.com/ansys/pyfluent/issues/3891
376+
data_zip = examples.download_file(
377+
"data.zip",
378+
"pyfluent/flprj_3891",
379+
return_without_path=False,
380+
)
381+
prj_file_name = next(Path(data_zip).with_suffix("").glob("*.flprj"))
382+
assert (
383+
CaseFile(project_file_name=prj_file_name).get_mesh().get_mesh_type()
384+
== MeshType.VOLUME
385+
)

tests/test_reduction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def test_reductions(
442442
_test_centroid_2_sources(solver1, solver2)
443443

444444

445+
@pytest.mark.skip("https://github.com/ansys/pyfluent/issues/3938")
445446
@pytest.mark.fluent_version(">=24.2")
446447
def test_reduction_does_not_modify_case(static_mixer_case_session: Any):
447448
solver = static_mixer_case_session

0 commit comments

Comments
 (0)