Skip to content

chore: Perform deprecation call from generated data. #4162

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

Merged
merged 5 commits into from
Jun 17, 2025
Merged
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
1 change: 1 addition & 0 deletions doc/changelog.d/4162.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Perform deprecation call from generated data.
5 changes: 3 additions & 2 deletions doc/settings_rstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ def _populate_rst_from_settings(rst_dir, cls, version):
r.write(f'{"="*(len(cls_orig_name))}\n\n')
deprecated = getattr(cls, "_deprecated_version", None)
if deprecated:
r.write(f".. deprecated:: Ansys {cls._deprecated_version}\n\n")
deprecated_class_version.update({cls_name: deprecated})
release_version = "20" + cls._deprecated_version.replace(".", "R")
r.write(f".. deprecated:: Ansys {release_version}\n\n")
deprecated_class_version.update({cls_name: release_version})
r.write(
f".. autoclass:: ansys.fluent.core.generated.solver.settings_{version}.{cls_name}\n"
)
Expand Down
3 changes: 1 addition & 2 deletions src/ansys/fluent/core/codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO |
s.write(f" _version = {data['version']!r}\n")
deprecated = data["deprecated_version"]
if deprecated:
release_version = "20" + data["deprecated_version"].replace(".", "R")
s.write(f" _deprecated_version = {release_version!r}\n")
s.write(f" _deprecated_version = {deprecated!r}\n")
s_stub.write(" _deprecated_version: str\n")
s.write(f" fluent_name = {data['fluent_name']!r}\n")
# _python_name preserves the original non-suffixed name of the class.
Expand Down
49 changes: 28 additions & 21 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ def _get_class_from_paths(root_cls, some_path: list[str], other_path: list[str])
return cls, full_path


def _is_deprecated(obj) -> bool | None:
"""Whether the object is deprecated in a specific Fluent version."""
if FluentVersion(obj._version) >= FluentVersion.v252:
# "_deprecated_version" is part of generated data since 25R2
deprecated_version = getattr(obj, "_deprecated_version", None)
else:
deprecated_version = obj.get_attrs(["deprecated-version"])
if deprecated_version:
deprecated_version = deprecated_version.get("attrs", deprecated_version)
deprecated_version = (
deprecated_version.get("deprecated-version") if deprecated_version else None
)
return deprecated_version and (
FluentVersion(float(deprecated_version)) <= FluentVersion.v222
or FluentVersion(obj._version) >= FluentVersion(deprecated_version)
)


class Base:
"""Provides the base class for settings and command objects.

Expand Down Expand Up @@ -400,19 +418,6 @@ def get_attr(
return None
return val

def _is_deprecated(self) -> bool:
"""Whether the object is deprecated in a specific Fluent version.'"""
deprecated_version = self.get_attrs(["deprecated-version"])
if deprecated_version:
deprecated_version = deprecated_version.get("attrs", deprecated_version)
deprecated_version = (
deprecated_version.get("deprecated-version") if deprecated_version else None
)
return deprecated_version and (
float(deprecated_version) <= 22.2
or FluentVersion(self._version) >= FluentVersion(deprecated_version)
)

def is_active(self) -> bool:
"""Whether the object is active."""
attr = self.get_attr(_InlineConstants.is_active)
Expand Down Expand Up @@ -949,7 +954,7 @@ def _command_query_name_filter(
for name in names:
if name not in excluded and name.startswith(prefix):
child = getattr(parent, name)
if child.is_active() and not child._is_deprecated():
if child.is_active() and not _is_deprecated(child):
ret.append([name, child.__class__.__bases__[0].__name__, child.__doc__])
return ret

Expand Down Expand Up @@ -1063,7 +1068,7 @@ def get_active_child_names(self):
ret = []
for child_name in self.child_names:
child = getattr(self, child_name)
if child.is_active() and not child._is_deprecated():
if child.is_active() and not _is_deprecated(child):
ret.append(child_name)
return ret

Expand All @@ -1072,7 +1077,7 @@ def get_active_command_names(self):
ret = []
for command_name in self.command_names:
command = getattr(self, command_name)
if command.is_active() and not command._is_deprecated():
if command.is_active() and not _is_deprecated(command):
ret.append(command_name)
return ret

Expand All @@ -1081,7 +1086,7 @@ def get_active_query_names(self):
ret = []
for query_name in self.query_names:
query = getattr(self, query_name)
if query.is_active() and not query._is_deprecated():
if query.is_active() and not _is_deprecated(query):
ret.append(query_name)
return ret

Expand All @@ -1091,7 +1096,8 @@ def __dir__(self):
[
child
for child in self.child_names + self.command_names + self.query_names
if getattr(self, child)._is_deprecated()
if getattr(self, child).is_active()
and _is_deprecated(getattr(self, child))
]
)

Expand All @@ -1108,7 +1114,7 @@ def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
for child_name in self.child_names:
if child_name not in excluded and child_name.startswith(prefix):
child = getattr(self, child_name)
if child.is_active() and not child._is_deprecated():
if child.is_active() and not _is_deprecated(child):
ret.append(
[
child_name,
Expand Down Expand Up @@ -1648,7 +1654,8 @@ def __dir__(self):
[
child
for child in self.argument_names
if getattr(self, child)._is_deprecated()
if getattr(self, child).is_active()
and _is_deprecated(getattr(self, child))
]
)

Expand All @@ -1665,7 +1672,7 @@ def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
for argument_name in self.argument_names:
if argument_name not in excluded and argument_name.startswith(prefix):
argument = getattr(self, argument_name)
if argument.is_active() and not argument._is_deprecated():
if argument.is_active() and not _is_deprecated(argument):
ret.append(
[
argument_name,
Expand Down