Skip to content
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

chore: fix styling issues, stricter flake8 checks #3468

Merged
merged 9 commits into from
Nov 11, 2024
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
6 changes: 3 additions & 3 deletions .ci/compare_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ def compare_flobject():
RuntimeError
If flobject.py is inconsistent in Fluent and PyFluent.
"""
image_name = f"ghcr.io/ansys/pyfluent:v24.1.0"
image_name = "ghcr.io/ansys/pyfluent:v24.1.0"
container_name = uuid.uuid4().hex
is_linux = platform.system() == "Linux"
subprocess.run(
f"docker container create --name {container_name} {image_name}",
shell=is_linux,
)
xml_source = f"/ansys_inc/v241/fluent/fluent24.1.0/cortex/pylib/flapi/flobject.py"
xml_source = "/ansys_inc/v241/fluent/fluent24.1.0/cortex/pylib/flapi/flobject.py"
subprocess.run(
f"docker cp {container_name}:{xml_source} fluent_flobject.py", shell=is_linux
)
subprocess.run(f"docker container rm {container_name}", shell=is_linux)
p = subprocess.run(
f"diff -u fluent_flobject.py src/ansys/fluent/core/solver/flobject.py",
"diff -u fluent_flobject.py src/ansys/fluent/core/solver/flobject.py",
shell=is_linux,
capture_output=True,
text=True,
Expand Down
9 changes: 4 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[flake8]
exclude = venv, doc/_build, src/ansys/api/fluent/v0/*, src/ansys/fluent/core/meshing/tui.py, src/ansys/fluent/core/solver/tui.py, src/ansys/fluent/core/solver/settings/*, src/ansys/fluent/core/datamodel/*
max-line-length = 88
exclude = src/ansys/fluent/core/generated
count = True
max-complexity = 10
statistics = True
select = W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806
extend-ignore = E203, E501
max-complexity = 10
max-line-length = 88
extend-ignore = E203, E501, C901
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@ repos:
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [
'flake8-annotations==3.0.1'
]
args: [
--exclude, src/ansys/fluent/core/generated,
--select, W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806,
mkundu1 marked this conversation as resolved.
Show resolved Hide resolved
#--select, W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806 ANN001 ANN201 ANN205 ANN206,
--count,
--statistics,
--max-complexity, "10",
--max-line-length, "88",
--extend-ignore, E203 E501,
ansys, doc, examples, tests
--extend-ignore, E203 E501 C901,
src, doc, examples, tests
]

- repo: https://github.com/codespell-project/codespell
Expand Down
6 changes: 3 additions & 3 deletions doc/api_rstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _generate_api_source_rst_files(folder: str, files: list):
rst.write(f".. _ref_{file}:\n\n")
if folder:
if "root" in file:
rst.write(f"solver.settings\n")
rst.write("solver.settings\n")
rst.write(f'{"="*(len("solver.settings"))}\n\n')
rst.write(
"The :ref:`ref_root` is the top-level solver settings object. It contains all\n"
Expand All @@ -176,7 +176,7 @@ def _generate_api_source_rst_files(folder: str, files: list):
rst.write(f"ansys.fluent.core.{file}\n")
rst.write(f'{"="*(len(f"ansys.fluent.core.{file}"))}\n\n')
rst.write(f".. automodule:: ansys.fluent.core.{file}\n")
if not "root" in file:
if "root" not in file:
_write_common_rst_members(rst_file=rst)


Expand All @@ -195,7 +195,7 @@ def _generate_api_index_rst_files():
index.write(f'{"="*(len(f"ansys.fluent.core.{folder}"))}\n\n')
index.write(f".. automodule:: ansys.fluent.core.{folder}\n")
_write_common_rst_members(rst_file=index)
index.write(f".. toctree::\n")
index.write(".. toctree::\n")
index.write(" :maxdepth: 2\n")
index.write(" :hidden:\n\n")
for file in files:
Expand Down
2 changes: 1 addition & 1 deletion doc/rstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def _write_datamodel_index_doc(datamodels: list, mode: str):
f.write(f".. _ref_{mode}_datamodel:\n\n")
f.write(f"{datamodel_mode}\n")
f.write(f"{'=' * len(datamodel_mode)}\n\n")
f.write(f".. automodule:: ansys.fluent.core.datamodel\n")
f.write(".. automodule:: ansys.fluent.core.datamodel\n")
f.write(" :autosummary:\n\n")
f.write(" :autosummary-members:\n\n")
f.write(".. toctree::\n")
Expand Down
20 changes: 10 additions & 10 deletions doc/settings_rstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _populate_parents_list(cls):
child_cls_name = child_cls.__name__
if not parents_dict.get(child_cls_name):
parents_dict[child_cls_name] = []
if not cls in parents_dict[child_cls_name]:
if cls not in parents_dict[child_cls_name]:
parents_dict[child_cls_name].append(cls)

if hasattr(cls, "command_names"):
Expand All @@ -71,7 +71,7 @@ def _populate_parents_list(cls):
child_cls_name = child_cls.__name__
if not parents_dict.get(child_cls_name):
parents_dict[child_cls_name] = []
if not cls in parents_dict[child_cls_name]:
if cls not in parents_dict[child_cls_name]:
parents_dict[child_cls_name].append(cls)

if hasattr(cls, "argument_names"):
Expand All @@ -80,15 +80,15 @@ def _populate_parents_list(cls):
child_cls_name = child_cls.__name__
if not parents_dict.get(child_cls_name):
parents_dict[child_cls_name] = []
if not cls in parents_dict[child_cls_name]:
if cls not in parents_dict[child_cls_name]:
parents_dict[child_cls_name].append(cls)

if hasattr(cls, "child_object_type"):
child_cls = getattr(cls, "child_object_type")
child_cls_name = child_cls.__name__
if not parents_dict.get(child_cls_name):
parents_dict[child_cls_name] = []
if not cls in parents_dict[child_cls_name]:
if cls not in parents_dict[child_cls_name]:
parents_dict[child_cls_name].append(cls)

if hasattr(cls, "child_names"):
Expand Down Expand Up @@ -131,7 +131,7 @@ def _populate_rst_from_settings(rst_dir, cls, version):
r.write(f"{istr1}:show-inheritance:\n\n")

if has_children:
r.write(f".. rubric:: Attributes\n\n")
r.write(".. rubric:: Attributes\n\n")
data_dict = {}
data_dict["Attribute"] = "Summary"
for child in cls.child_names:
Expand All @@ -141,7 +141,7 @@ def _populate_rst_from_settings(rst_dir, cls, version):
_generate_table_for_rst(r, data_dict)

if has_commands:
r.write(f".. rubric:: Methods\n\n")
r.write(".. rubric:: Methods\n\n")
data_dict = {}
data_dict["Method"] = "Summary"
for child in cls.command_names:
Expand All @@ -151,7 +151,7 @@ def _populate_rst_from_settings(rst_dir, cls, version):
_generate_table_for_rst(r, data_dict)

if has_arguments:
r.write(f".. rubric:: Arguments\n\n")
r.write(".. rubric:: Arguments\n\n")
data_dict = {}
data_dict["Argument"] = "Summary"
for child in cls.argument_names:
Expand All @@ -165,11 +165,11 @@ def _populate_rst_from_settings(rst_dir, cls, version):
ref_string = f":ref:`{child_cls.__name__} <{child_cls.__name__}>`"
data_dict = {}
data_dict[ref_string] = child_cls.__doc__.strip("\n").split("\n")[0]
r.write(f".. rubric:: Named object type\n\n")
r.write(".. rubric:: Named object type\n\n")
r.write(f"{ref_string}\n\n\n")

if parents_dict.get(cls_name):
r.write(f".. rubric:: Included in:\n\n")
r.write(".. rubric:: Included in:\n\n")
data_dict = {}
data_dict["Parent"] = "Summary"
for parent in parents_dict.get(cls_name):
Expand All @@ -180,7 +180,7 @@ def _populate_rst_from_settings(rst_dir, cls, version):
data_dict[ref_string] = parent.__doc__.strip("\n").split("\n")[0]
_generate_table_for_rst(r, data_dict)

if not rstpath in rst_list:
if rstpath not in rst_list:
rst_list.append(rstpath)
if has_children:
for child in cls.child_names:
Expand Down
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def _stop_fluent_container(gallery_conf, fname):
"backreferences_dir": None,
# Modules for which function level galleries are created. In
"doc_module": "ansys-fluent-core",
"ignore_pattern": "flycheck*",
"thumbnail_size": (350, 350),
"reset_modules_order": "after",
"reset_modules": (_stop_fluent_container),
Expand Down
8 changes: 5 additions & 3 deletions examples/00-fluent/DOE_ML.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# Import required libraries/modules
# =================================

# flake8: noqa: E402

from pathlib import Path

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -216,10 +218,10 @@
# * Prediction on Unseen/Test Data (scikit-learn)
# * Parity Plot (Matplotlib and Seaborn)

from pprint import pprint # noqa: F401
# from pprint import pprint

from sklearn.ensemble import RandomForestRegressor # noqa: F401
from sklearn.linear_model import LinearRegression # noqa: F401
# from sklearn.ensemble import RandomForestRegressor
# from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
from sklearn.model_selection import RepeatedKFold, cross_val_score
from xgboost import XGBRegressor
Expand Down
10 changes: 4 additions & 6 deletions examples/00-fluent/conjugate_heat_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@

import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import ansys.fluent.visualization as viz # noqa: F401
from ansys.fluent.visualization.matplotlib import Plots # noqa: F401
from ansys.fluent.visualization.matplotlib import matplot_windows_manager # noqa: F401
from ansys.fluent.visualization.matplotlib import Plots
from ansys.fluent.visualization.pyvista import Graphics, pyvista_windows_manager
from ansys.fluent.visualization.pyvista.pyvista_windows_manager import PyVistaWindow

Expand Down Expand Up @@ -100,7 +98,7 @@
r"CappingRequired": r"No",
r"InvokeShareTopology": r"No",
r"NonConformal": r"Yes",
r"SetupType": r"The geometry consists of both fluid and solid regions and/or voids", # noqa: E501
r"SetupType": r"The geometry consists of both fluid and solid regions and/or voids",
}
)

Expand Down Expand Up @@ -331,7 +329,7 @@
meshing.workflow.TaskObject["Run Custom Journal"].Rename(NewName=r"set-periodicity")
meshing.workflow.TaskObject["set-periodicity"].Arguments = dict(
{
r"JournalString": r"""/bo rps translational semi-auto periodic-1-high periodic-2-high periodic-3-high periodic-4-high , 0 0 -2.3 # noqa: E501
r"JournalString": r"""/bo rps translational semi-auto periodic-1-high periodic-2-high periodic-3-high periodic-4-high , 0 0 -2.3
/bo rps translational semi-auto periodic-5* , 0 0 -2.3
/bo rps translational semi-auto periodic-6-high , 0 0 -2.3
/bo rps translational semi-auto periodic-7-high , 0 0 -2.3
Expand Down Expand Up @@ -371,7 +369,7 @@
r"wall-fluid-tet-4-solid-tet-4",
r"wall-fluid-tet-3-solid-tet-3",
r"wall-fluid-tet-2-solid-tet-2",
r"wall-fluid-tet-2-solid-tet-2-wall-fluid-tet-3-solid-tet-3-fluid-tet-2-solid-tet-2", # noqa: E501
r"wall-fluid-tet-2-solid-tet-2-wall-fluid-tet-3-solid-tet-3-fluid-tet-2-solid-tet-2",
r"wall-fluid-tet-1-solid-tet-1",
r"wall-fluid-sweep-fin-solid-sweep-fin.1",
r"wall-fluid-sweep-fin-solid-sweep-fin",
Expand Down
2 changes: 2 additions & 0 deletions examples/00-fluent/lunar_lander_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
# Perform required imports, including downloading the required geometry files.
# The mesh has been pre-made for this problem.

# flake8: noqa: E402

from itertools import chain

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion examples/00-fluent/modeling_ablation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# Fluent Solution Setup
# ==================================================================================

from ansys.fluent.visualization import set_config
from ansys.fluent.visualization import set_config # noqa: E402

set_config(blocking=True, set_view_on_display="isometric")

Expand Down
2 changes: 1 addition & 1 deletion examples/00-fluent/tyler_sofrin_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"axial_comp_fullWheel_DFT_23R2.cas.h5",
"pyfluent/examples/Tyler-Sofrin-Modes-Compressor",
save_path=save_path,
) # noqa: E501
)

examples.download_file(
"axial_comp_fullWheel_DFT_23R2.dat.h5",
Expand Down
1 change: 1 addition & 0 deletions src/ansys/fluent/core/codegen/builtin_settingsgen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Generate builtin setting classes."""

import os
from zipimport import zipimporter

from ansys.fluent.core import CODEGEN_OUTDIR, FluentVersion
from ansys.fluent.core.solver.flobject import CreatableNamedObjectMixin
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/fluent/core/codegen/datamodelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _populate_static_info(self):
print(
"Information: Icing settings not generated ( R23.1+ is required )\n"
)
except:
except Exception:
print(
"Information: Problem accessing flserver datamodel for icing settings\n"
)
Expand Down Expand Up @@ -361,7 +361,7 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0):
)
file.write("from typing import Any\n")
file.write("\n\n")
file.write(f"class Root(PyMenu):\n")
file.write("class Root(PyMenu):\n")
for k in commands:
_write_command_query_stub(
k,
Expand Down Expand Up @@ -402,7 +402,7 @@ def write_static_info(self) -> None:
"""Write API classes to files."""
api_tree = {"<meshing_session>": {}, "<solver_session>": {}}
for name, info in self._static_info.items():
if info.static_info == None:
if info.static_info is None:
continue
with open(info.file_name, "w", encoding="utf8") as f:
f.write("#\n")
Expand Down
18 changes: 9 additions & 9 deletions src/ansys/fluent/core/codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _write_function_stub(name, data, s_stub):
for arg_name in data["argument_names"]:
arg_type = _arg_type_strings[data["child_classes"][arg_name]["bases"][0]]
s_stub.write(f", {arg_name}: {arg_type}")
s_stub.write(f"):\n")
s_stub.write("):\n")
# TODO: add return type
doc = data["doc"]
doc = doc.strip().replace("\n", "\n ")
Expand Down Expand Up @@ -178,25 +178,25 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO |
s.write(f" fluent_name = {data['fluent_name']!r}\n")
# _python_name preserves the original non-suffixed name of the class.
s.write(f" _python_name = {python_name!r}\n")
s_stub.write(f" version: str\n")
s_stub.write(f" fluent_name: str\n")
s_stub.write(f" _python_name: str\n")
s_stub.write(" version: str\n")
s_stub.write(" fluent_name: str\n")
s_stub.write(" _python_name: str\n")
child_names = data["child_names"]
if child_names:
s.write(f" child_names = {child_names}\n")
s_stub.write(f" child_names: list[str]\n")
s_stub.write(" child_names: list[str]\n")
command_names = data["command_names"]
if command_names:
s.write(f" command_names = {command_names}\n")
s_stub.write(f" command_names: list[str]\n")
s_stub.write(" command_names: list[str]\n")
query_names = data["query_names"]
if query_names:
s.write(f" query_names = {query_names}\n")
s_stub.write(f" query_names: list[str]\n")
s_stub.write(" query_names: list[str]\n")
argument_names = data["argument_names"]
if argument_names:
s.write(f" argument_names = {argument_names}\n")
s_stub.write(f" argument_names: list[str]\n")
s_stub.write(" argument_names: list[str]\n")
classes_to_write = {} # values are (class_name, data, hash, should_write_stub)
if data["child_classes"]:
s.write(" _child_classes = dict(\n")
Expand Down Expand Up @@ -248,7 +248,7 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO |
return_type = data["return_type"]
if return_type:
s.write(f" return_type = {return_type!r}\n")
s_stub.write(f" return_type: str\n")
s_stub.write(" return_type: str\n")
s.write("\n")
for name, (python_name, data, hash_, should_write_stub) in classes_to_write.items():
if name not in _CLASS_WRITTEN:
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/codegen/settingsgen_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _populate_init(parent_dir, hash):
f.write("# This is an auto-generated file. DO NOT EDIT!\n")
f.write("#\n")
f.write("\n")
f.write(f'"""A package providing Fluent\'s Settings Objects in Python."""')
f.write('"""A package providing Fluent\'s Settings Objects in Python."""')
f.write("\n")
f.write("from ansys.fluent.core.solver.flobject import *\n\n")
f.write(f'SHASH = "{hash}"\n')
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/codegen/tuigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _get_tui_docdir(mode: str):
"source",
"api",
mode,
f"tui",
"tui",
)
)

Expand Down
Loading
Loading