Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
df68d26
Add get and create methods to objects
Gobot1234 Jan 27, 2026
61d4c66
Update src/ansys/fluent/core/solver/settings_builtin_bases.py
Gobot1234 Jan 28, 2026
f274df3
add a test case
Gobot1234 Jan 28, 2026
4e5c6be
check get on non creatable objects
Gobot1234 Jan 28, 2026
269c59e
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot Jan 28, 2026
c40e9ed
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot Jan 28, 2026
91882b2
Update src/ansys/fluent/core/solver/flobject.py
Gobot1234 Jan 28, 2026
9430310
fix tests + warning and fmt
Gobot1234 Jan 28, 2026
c38d797
generate the types for this
Gobot1234 Jan 28, 2026
9d6dacc
slightly fix up generation
Gobot1234 Jan 28, 2026
73cafbe
add all
Gobot1234 Jan 28, 2026
d42a24a
add some more tests
Gobot1234 Jan 28, 2026
779bb60
Apply suggestions from code review
Gobot1234 Jan 28, 2026
51664a4
Apply suggestions from code review
Gobot1234 Jan 29, 2026
c3c5aee
Merge branch 'main' into jhilton/create-and-find
Gobot1234 Feb 3, 2026
20ce7f9
add more tests and fix the data
Gobot1234 Feb 3, 2026
ae11446
Merge branch 'jhilton/create-and-find' of https://github.com/ansys/py…
Gobot1234 Feb 3, 2026
fedf799
touch of work still doesnt work
Gobot1234 Feb 13, 2026
fb48b06
add all as an alias for allowed_values
Gobot1234 Mar 16, 2026
a81582c
Merge branch 'main' into jhilton/create-and-find
Gobot1234 Apr 24, 2026
dae1864
Apply suggestions from code review
Gobot1234 May 5, 2026
644de8b
update docs
May 12, 2026
a173cd8
make stuff actually work
May 12, 2026
4be2437
remove unsupported tests
May 12, 2026
83f560d
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot May 12, 2026
61e1717
add some comments
Gobot1234 May 13, 2026
f22c11d
Update src/ansys/fluent/core/codegen/builtin_settingsgen.py
Gobot1234 May 13, 2026
2a8df61
Potential fix for pull request finding
Gobot1234 May 13, 2026
e48d985
remove warning as it's too noisy
May 14, 2026
4bf9cdf
more service fixes
May 14, 2026
f9724f6
chore: adding changelog file 4866.added.md [dependabot-skip]
pyansys-ci-bot May 14, 2026
a29e52c
add missing reciprocals
May 14, 2026
95558fe
remove kwarg setting source
May 14, 2026
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/4866.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add get and create methods and **kwarg support for create
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/codegen/allapigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def generate(version: str, static_infos: dict, verbose: bool = False):
pickle.dump(api_tree, f)
if not config.codegen_skip_builtin_settings:
builtin_settingsgen.generate(version)
# Generate main .pyi file for the latest version processed
builtin_settingsgen.generate_main_pyi(version)
Comment on lines +56 to +57


if __name__ == "__main__":
Expand Down
115 changes: 110 additions & 5 deletions src/ansys/fluent/core/codegen/builtin_settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from ansys.fluent.core.utils.fluent_version import FluentVersion, all_versions

_PY_FILE = config.codegen_outdir / "solver" / "settings_builtin.py"
_PYI_FILE = config.codegen_outdir / "solver" / "settings_builtin.pyi"

_CLASS_NAME_OVERRIDES = {
"ReadCaseData": "ReadCaseAndData",
Expand Down Expand Up @@ -83,6 +82,29 @@ def _get_named_objects_in_path(root, path, kind):
return named_objects, final_type


def _has_create_method(root, path):
"""Check if a setting object has a create method."""
try:
cls = root
comps = path.split(".")
for comp in comps:
cls = cls._child_classes[comp]
# Check if the class has 'create' in its child classes or command names
return "create" in getattr(cls, "_child_classes", {}) or "create" in getattr(
cls, "command_names", []
Comment on lines +88 to +89

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can we comment why we check both of these. Otherwise, it looks speculative.

)
except (KeyError, AttributeError):
return False


def _get_reciprocal_name(name: str) -> str | None:
"""Get the reciprocal name (singular/plural counterpart) from DATA."""
try:
return DATA[name][2]
except KeyError:
return None


def generate(version: str):
"""Generate builtin setting classes."""
print("Generating builtin settings...")
Expand Down Expand Up @@ -132,14 +154,14 @@ def _write_deprecated_alias_class(
"import warnings\n\n\n"
)
f.write("__all__ = [\n")
for legacy_name, (kind, _) in DATA.items():
for legacy_name, (kind, _, _) in DATA.items():
name = _get_public_class_name(legacy_name)
_write_symbol_to_all(name, kind)
if name != legacy_name:
_write_symbol_to_all(legacy_name, kind)
f.write("]\n\n")
for legacy_name, v in DATA.items():
kind, path = v
kind, path, _ = v
name = _get_public_class_name(legacy_name)
if isinstance(path, dict):
version_supported = False
Expand Down Expand Up @@ -210,6 +232,7 @@ def _write_deprecated_alias_class(
" return super().__new__(cls, settings_source=settings_source, **kwargs)\n\n"
)


with open(_PYI_FILE, "w") as f:
for version in FluentVersion:
f.write(
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
Expand All @@ -229,10 +252,92 @@ def _write_deprecated_alias_class(
f.write(f" type(settings_root_{v.number}.{p}),\n")
f.write("): ...\n\n")

# Generate version-specific .pyi files
pyi_file = (
config.codegen_outdir / "solver" / f"settings_builtin_{version.number}.pyi"
)
with open(pyi_file, "w") as f:
# Import base classes and deprecated decorator
f.write(
"from typing_extensions import deprecated\n"
"from ansys.fluent.core.solver.settings_builtin_bases import _SingletonSetting, _CreatableNamedObjectSetting, _NonCreatableNamedObjectSetting, _CommandSetting\n"
)
# Import version-specific root for type hints
f.write(
f"from ansys.fluent.core.generated.solver.settings_{version.number} import root as settings_root_{version.number}\n"
)
f.write("\n\n")
for legacy_name, v in DATA.items():
kind, path, recip = v
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
name = _get_public_class_name(legacy_name)
if isinstance(path, dict):
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
version_supported = False
for version_set, p in path.items():
if version in version_set:
path = p
version_supported = True
break
if not version_supported:
continue
named_objects, final_type = _get_named_objects_in_path(root, path, kind)
if kind == "NamedObject":
kind = f"{final_type}NamedObject"
path_with_child = f"{path}.child_object_type"
f.write(f"class {name}(\n")
f.write(f" _{kind}Setting,\n")
f.write(
f" type(settings_root_{version.number}.{path_with_child}),\n"
)
f.write("):\n")
if final_type == "Creatable":
f.write(
f" create = settings_root_{version.number}.{path}.create\n"
)
else:
f.write(" ...\n")
f.write("\n")
else:
# For Singleton and Command types
# Check if this is a plural class by looking at its reciprocal
if kind == "Singleton" and recip:
# Add deprecated decorator for plural container classes
f.write(f'@deprecated("Use {recip}.all() instead")\n')

f.write(f"class {name}(\n")
f.write(f" _{kind}Setting,\n")
f.write(f" type(settings_root_{version.number}.{path}),\n")
f.write("):\n")
# Check if singleton has create method
if kind == "Singleton" and _has_create_method(root, path):
f.write(
f" create = settings_root_{version.number}.{path}.create\n"
)
else:
f.write(" ...\n")
f.write("\n")

if name != legacy_name:
f.write(f"class {legacy_name}({name}): ...\n\n")


def generate_main_pyi(version_str: str):
"""Generate main settings_builtin.pyi that imports from a specific version."""
_MAIN_PYI_FILE = config.codegen_outdir / "solver" / "settings_builtin.pyi"
version_obj = FluentVersion(version_str)
with open(_MAIN_PYI_FILE, "w") as f:
Comment thread
Gobot1234 marked this conversation as resolved.
f.write(f"# Re-export from version {version_str}\n")
f.write(
f"from ansys.fluent.core.generated.solver.settings_builtin_{version_obj.number} import *\n"
)


if __name__ == "__main__":
version = "261" # for development
generate(version)
# Generate for all available versions
versions = sorted([v.number for v in all_versions()])
Comment on lines +335 to +336

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions 'all available versions' but the actual code in if __name__ == '__main__' generates for all versions. This might cause unexpected behavior if run directly vs imported, as the main generation flow uses a single version. Consider clarifying or consolidating the version selection logic.

Copilot uses AI. Check for mistakes.
for version in versions:
try:
generate(str(version))
except Exception as e:
print(f"Failed to generate for version {version}: {e}")
# Generate main .pyi that imports from the latest version
generate_main_pyi(str(versions[-1]))
23 changes: 22 additions & 1 deletion src/ansys/fluent/core/codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ListObject,
NamedObject,
get_cls,
settings_logger,
to_constant_name,
to_python_name,
)
Expand Down Expand Up @@ -200,10 +201,19 @@ def _get_unique_name(name):

def _write_function_stub(name, data, s_stub):
s_stub.write(f" def {name}(self")
if name == "create":
if not data["argument_names"] or "name" not in data["argument_names"]:
settings_logger.warning("Create method with no arguments %s", data)
else:
s_stub.write(", *") # allow only keyword arguments as best practice
for arg_name in data["argument_names"]:
arg_type = data["child_classes"][arg_name]["bases"][0]
py_arg_type = _arg_type_strings.get(arg_type, "Any")
s_stub.write(f", {arg_name}: {py_arg_type}")
if name == "create" and py_arg_type == "Any":
continue # don't write the object arguments for create as they shouldn't be used
Comment thread
Gobot1234 marked this conversation as resolved.
s_stub.write(
f", {arg_name}: {py_arg_type}{' = ...' if name == 'create' else ''}"
)
s_stub.write("):\n")
# TODO: add return type
doc = data["doc"]
Expand Down Expand Up @@ -283,6 +293,17 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO |
# to write only if it is not found in the _NAME_BY_HASH dict and avoid
# the _CLASS_WRITTEN set.
if k in command_names + query_names:

Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
# Special handling for create commands that only expose a "name" child.
# In this case, the actual arguments of the create operation are
# described by the associated child_object_type, not by the "name"
# placeholder itself. We therefore replace the argument_names and
# child_classes with those from child_object_type so that the
# generated stubs show the full set of creation parameters.
if k == "create" and v["child_classes"].keys() == {"name"}:
child_object_type = data["child_object_type"]
v["argument_names"] = child_object_type["child_names"]
v["child_classes"] = child_object_type["child_classes"]
_write_function_stub(k, v, s_stub)
classes_to_write[unique_name] = (child_python_name, v, hash_, False)
else:
Expand Down
12 changes: 9 additions & 3 deletions src/ansys/fluent/core/field_data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ class _SurfaceNames:
def __init__(self, allowed_surface_names):
self._allowed_surface_names = allowed_surface_names

def allowed_values(self):
def all(self):
"""Lists available surface names."""
return list(self._allowed_surface_names())

allowed_values = all

def validate(self, surfaces: List[str]) -> bool:
"""
Validate that the given surfaces are in the list of allowed surface names.
Expand Down Expand Up @@ -389,10 +391,12 @@ class _SurfaceIds:
def __init__(self, allowed_surface_ids):
self._allowed_surface_ids = allowed_surface_ids

def allowed_values(self):
def all(self):
"""Lists available surface ids."""
return self._allowed_surface_ids()

allowed_values = all

def validate(self, surface_ids: List[int]) -> bool:
"""
Validate that the given surface IDs are in the list of allowed surface IDs.
Expand Down Expand Up @@ -432,10 +436,12 @@ def is_active(self, field_name: VariableDescriptor | str) -> bool:
"""
return _to_field_name_str(field_name) in self._available_field_names()

def allowed_values(self):
def all(self):
"""Lists available scalar or vector field names as strings."""
return list(self._available_field_names())

allowed_values = all

def allowed_variables(self) -> list[VariableDescriptor]:
"""Return allowed field names as VariableDescriptor objects.

Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/rpvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __call__(self, var: str | None = None, val: Any | None = None) -> Any:
else (self._get_var(var) if var is not None else self._get_vars())
)

def allowed_values(self) -> List[str]:
def all(self) -> List[str]:
"""Returns list with the allowed rpvars names.

Returns
Expand All @@ -130,6 +130,8 @@ def allowed_values(self) -> List[str]:
"""
return lispy.parse(self._eval_fn("(cx-send '(map car rp-variables))"))

allowed_values = all

def _get_var(self, var: str):
allowed_rp_vars = self.allowed_values()
if var not in allowed_rp_vars:
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,10 +1518,12 @@ def false_if_none(val: bool | None) -> bool:
class PyTextual(PyParameter):
"""Provides interface for textual parameters."""

def allowed_values(self) -> list[str]:
def all(self) -> list[str]:
"""Get allowed values."""
return self.get_attr(Attribute.ALLOWED_VALUES.value)

allowed_values = all


class PyNumerical(PyParameter):
"""Provides interface for numerical parameters."""
Expand Down
12 changes: 7 additions & 5 deletions src/ansys/fluent/core/services/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,34 +363,36 @@ class _Arg:
def __init__(self, accessor):
self._accessor = accessor

def allowed_values(self):
def all(self):
"""Returns set of allowed values."""
if self._accessor.__class__.__name__ == "_AllowedScalarFieldNames":
warnings.warn(
"This usage is deprecated and will be removed in a future release. "
"Please use 'scalar_fields.allowed_values()' instead",
"Please use 'scalar_fields.all()' instead",
PyFluentDeprecationWarning,
)
elif self._accessor.__class__.__name__ == "_AllowedVectorFieldNames":
warnings.warn(
"This usage is deprecated and will be removed in a future release. "
"Please use 'vector_fields.allowed_values()' instead",
"Please use 'vector_fields.all()' instead",
PyFluentDeprecationWarning,
)
elif self._accessor.__class__.__name__ == "_AllowedSurfaceNames":
warnings.warn(
"This usage is deprecated and will be removed in a future release. "
"Please use 'field_data.surfaces.allowed_values()' instead",
"Please use 'field_data.surfaces.all()' instead",
PyFluentDeprecationWarning,
)
elif self._accessor.__class__.__name__ == "_AllowedSurfaceIDs":
warnings.warn(
"This usage is deprecated and will be removed in a future release. "
"Please use 'field_data.surface_ids.allowed_values()' instead",
"Please use 'field_data.surface_ids.all()' instead",
PyFluentDeprecationWarning,
)
return sorted(self._accessor())

allowed_values = all

def __init__(self, field_data_accessor, args_allowed_values_accessors):
self._field_data_accessor = field_data_accessor
for arg_name, accessor in args_allowed_values_accessors.items():
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/services/solution_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,12 @@ class _Arg:
def __init__(self, accessor):
self._accessor = accessor

def allowed_values(self):
def all(self):
"""Get allowed values."""
return sorted(self._accessor())

allowed_values = all

def __init__(self, svar_accessor, args_allowed_values_accessors):
self._svar_accessor = svar_accessor
for arg_name, accessor in args_allowed_values_accessors.items():
Expand Down
Loading
Loading