Skip to content

Commit db2b0f4

Browse files
ecoussoux-ansyspyansys-ci-botSMoraisAnsyspre-commit-ci[bot]
authored andcommitted
CHORE: Setting up ruff (#6157)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Sébastien Morais <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ce7ef71 commit db2b0f4

File tree

242 files changed

+1429
-1255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+1429
-1255
lines changed

.flake8

Lines changed: 0 additions & 7 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,12 @@ exclude: |
2121
2222
repos:
2323

24-
- repo: https://github.com/psf/black
25-
rev: 25.1.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: v0.11.9
2626
hooks:
27-
- id: black
28-
args:
29-
- --line-length=120
30-
31-
- repo: https://github.com/pycqa/isort
32-
rev: 6.0.1
33-
hooks:
34-
- id: isort
35-
name: isort (python)
36-
args: ['--force-single-line-imports', '--profile', 'black']
37-
38-
- repo: https://github.com/PyCQA/flake8
39-
rev: 7.2.0
40-
hooks:
41-
- id: flake8
42-
args:
43-
- --max-line-length=120
44-
27+
- id: ruff
28+
- id: ruff-format
29+
4530
- repo: https://github.com/codespell-project/codespell
4631
rev: v2.4.1
4732
hooks:

doc/changelog.d/6157.maintenance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Setting up ruff

doc/print_errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Read errors output from a sphinx build and remove duplicate groups"""
2-
import sys
2+
33
import os
44
import pathlib
5+
import sys
56

67
sys.tracebacklimit = 0
78
my_path = pathlib.Path(__file__).parent.resolve()

doc/source/Resources/pyaedt_installer_from_aedt.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
VENV_DIR_PREFIX = ".pyaedt_env"
4242

4343
"""
44-
It is possible create Python virtual environment in a specific directory by setting variable VENV_DIR.
44+
It is possible create Python virtual environment in a specific directory by setting variable VENV_DIR.
4545
For example,
4646
VENV_DIR = "e:/pyaedt_env"
4747
"""
@@ -93,10 +93,10 @@ def run_pyinstaller_from_c_python(oDesktop):
9393
if is_student_version(oDesktop):
9494
command.append("--student")
9595
if is_linux:
96-
command.extend([r'--edt_root={}'.format(edt_root), '--python_version="{}"'.format(python_version)])
96+
command.extend([r"--edt_root={}".format(edt_root), '--python_version="{}"'.format(python_version)])
9797

9898
if wheelpyaedt:
99-
command.extend([r'--wheel={}'.format(wheelpyaedt)])
99+
command.extend([r"--wheel={}".format(wheelpyaedt)])
100100

101101
oDesktop.AddMessage("", "", 0, "Installing PyAEDT.")
102102
return_code = subprocess.call(command) # nosec
@@ -193,13 +193,14 @@ def parse_arguments_for_pyaedt_installer(args=None):
193193
parser.error("No arguments given!")
194194
return args
195195

196+
196197
def unzip_if_zip(path):
197198
"""Unzip path if it is a ZIP file."""
198199
import zipfile
199200

200201
# Extracted folder
201202
unzipped_path = path
202-
if path.suffix == '.zip':
203+
if path.suffix == ".zip":
203204
unzipped_path = path.parent / path.stem
204205
if unzipped_path.exists():
205206
shutil.rmtree(unzipped_path, ignore_errors=True)
@@ -266,7 +267,7 @@ def install_pyaedt():
266267
if args.version <= "231":
267268
command.append("pyaedt[all,dotnet]=='0.9.0'")
268269
else:
269-
command.append("pyaedt[all]")
270+
command.append("pyaedt[all]")
270271
subprocess.run(command, check=True) # nosec
271272
else:
272273
print("Installing PyAEDT using online sources")
@@ -333,7 +334,6 @@ def validate_disclaimer():
333334

334335

335336
if __name__ == "__main__":
336-
337337
if is_iron_python:
338338
if "GetIsNonGraphical" in oDesktop.__dir__() and oDesktop.GetIsNonGraphical():
339339
print("When using IronPython, this script is expected to be run in graphical mode.")

doc/source/Resources/toolkit_installer_from_aedt.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import os
2626
import sys
27+
2728
import subprocessdotnet as subprocess # nosec
2829

2930
# This script installs PyAEDT tabs (PyAEDT Console, Jupyter, Run Script and Extension Manager)
@@ -47,14 +48,17 @@ def run_pyinstaller_from_c_python(oDesktop, pyaedt_interpreter):
4748

4849
# Create Toolkits in PersonalLib
4950
import tempfile
51+
5052
python_script = os.path.join(tempfile.gettempdir(), "configure_pyaedt.py")
5153
if os.path.isfile(python_script):
5254
os.remove(python_script)
5355
with open(python_script, "w") as f:
5456
f.write("from ansys.aedt.core.extensions.installer.pyaedt_installer import add_pyaedt_to_aedt\n")
5557
f.write(
5658
'add_pyaedt_to_aedt(aedt_version="{}", personal_lib=r"{}")\n'.format(
57-
oDesktop.GetVersion()[:6], oDesktop.GetPersonalLibDirectory()))
59+
oDesktop.GetVersion()[:6], oDesktop.GetPersonalLibDirectory()
60+
)
61+
)
5862

5963
command = [pyaedt_interpreter, python_script]
6064
oDesktop.AddMessage("", "", 0, "Configuring PyAEDT panels in automation tab.")
@@ -67,21 +71,27 @@ def run_pyinstaller_from_c_python(oDesktop, pyaedt_interpreter):
6771
oDesktop.RefreshToolkitUI()
6872
msg = "PyAEDT configuration complete."
6973
if is_linux:
70-
msg += " Please ensure Ansys Electronics Desktop is launched in gRPC mode (i.e. launch ansysedt with -grpcsrv" \
71-
" argument) to take advantage of the new toolkits."
74+
msg += (
75+
" Please ensure Ansys Electronics Desktop is launched in gRPC mode (i.e. launch ansysedt with -grpcsrv"
76+
" argument) to take advantage of the new toolkits."
77+
)
7278

7379
if "GetIsNonGraphical" in oDesktop.__dir__() and not oDesktop.GetIsNonGraphical():
74-
from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon
80+
from System.Windows.Forms import MessageBox
81+
from System.Windows.Forms import MessageBoxButtons
82+
from System.Windows.Forms import MessageBoxIcon
83+
7584
oDesktop.AddMessage("", "", 0, msg)
76-
MessageBox.Show(msg, 'Info', MessageBoxButtons.OK, MessageBoxIcon.Information)
85+
MessageBox.Show(msg, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
7786
oDesktop.AddMessage("", "", 0, "Create a project if the PyAEDT panel is not visible.")
7887

7988

8089
if __name__ == "__main__":
81-
8290
python_interpreter = os.getenv(pyaedt_enviroment_variable)
8391
if python_interpreter:
84-
oDesktop.AddMessage("", "", 0, "Using Python environment defined with the environment variable PYAEDT_INTERPRETER.")
92+
oDesktop.AddMessage(
93+
"", "", 0, "Using Python environment defined with the environment variable PYAEDT_INTERPRETER."
94+
)
8595
if os.path.exists(python_interpreter):
8696
oDesktop.AddMessage("", "", 2, "Python environment does not exist.")
8797
sys.exit()

doc/source/conf.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,46 @@
22

33
# -- Project information -----------------------------------------------------
44
import datetime
5+
from importlib import import_module
56
import os
67
import pathlib
8+
from pprint import pformat
9+
import shutil
710
import sys
811
import warnings
912

10-
import numpy as np
11-
from sphinx_gallery.sorting import FileNameSortKey
12-
from ansys_sphinx_theme import (ansys_favicon,
13-
get_version_match,
14-
watermark,
15-
ansys_logo_white,
16-
ansys_logo_white_cropped, latex)
17-
from importlib import import_module
18-
from pprint import pformat
19-
from docutils.parsers.rst import Directive
13+
from ansys_sphinx_theme import ansys_favicon
14+
from ansys_sphinx_theme import ansys_logo_white
15+
from ansys_sphinx_theme import ansys_logo_white_cropped
16+
from ansys_sphinx_theme import get_version_match
17+
from ansys_sphinx_theme import latex
18+
from ansys_sphinx_theme import watermark
2019
from docutils import nodes
20+
from docutils.parsers.rst import Directive
21+
import numpy as np
2122
from sphinx import addnodes
22-
from sphinx.util import logging
23-
import shutil
2423

2524
# <-----------------Override the sphinx pdf builder---------------->
2625
# Some pages do not render properly as per the expected Sphinx LaTeX PDF signature.
2726
# This issue can be resolved by migrating to the autoapi format.
28-
# Additionally, when documenting images in formats other than the supported ones,
27+
# Additionally, when documenting images in formats other than the supported ones,
2928
# make sure to specify their types.
3029
from sphinx.builders.latex import LaTeXBuilder
30+
from sphinx.util import logging
31+
from sphinx_gallery.sorting import FileNameSortKey
32+
3133
LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]
3234

35+
from docutils.nodes import Element
3336
from sphinx.writers.latex import CR
3437
from sphinx.writers.latex import LaTeXTranslator
35-
from docutils.nodes import Element
38+
3639

3740
def visit_desc_content(self, node: Element) -> None:
38-
self.body.append(CR + r'\pysigstopsignatures')
41+
self.body.append(CR + r"\pysigstopsignatures")
3942
self.in_desc_signature = False
43+
44+
4045
LaTeXTranslator.visit_desc_content = visit_desc_content
4146

4247
# <----------------- End of sphinx pdf builder override---------------->
@@ -47,23 +52,22 @@ def visit_desc_content(self, node: Element) -> None:
4752

4853
# Sphinx event hooks
4954

55+
5056
class PrettyPrintDirective(Directive):
5157
"""Renders a constant using ``pprint.pformat`` and inserts it into the document."""
58+
5259
required_arguments = 1
5360

5461
def run(self):
55-
module_path, member_name = self.arguments[0].rsplit('.', 1)
62+
module_path, member_name = self.arguments[0].rsplit(".", 1)
5663

5764
member_data = getattr(import_module(module_path), member_name)
5865
code = pformat(member_data, 2, width=68)
5966

6067
literal = nodes.literal_block(code, code)
61-
literal['language'] = 'python'
68+
literal["language"] = "python"
6269

63-
return [
64-
addnodes.desc_name(text=member_name),
65-
addnodes.desc_content('', literal)
66-
]
70+
return [addnodes.desc_name(text=member_name), addnodes.desc_content("", literal)]
6771

6872

6973
def autodoc_skip_member(app, what, name, obj, skip, options):
@@ -87,6 +91,7 @@ def directory_size(directory_path):
8791
res /= 1e6
8892
return res
8993

94+
9095
def remove_doctree(app, exception):
9196
"""Remove the ``.doctree`` directory created during the documentation build."""
9297

@@ -100,10 +105,11 @@ def remove_doctree(app, exception):
100105
shutil.rmtree(app.doctreedir, ignore_errors=True)
101106
logger.info(f"Doctree removed.")
102107

108+
103109
def setup(app):
104-
app.add_directive('pprint', PrettyPrintDirective)
105-
app.connect('autodoc-skip-member', autodoc_skip_member)
106-
app.connect('build-finished', remove_doctree, priority=600)
110+
app.add_directive("pprint", PrettyPrintDirective)
111+
app.connect("autodoc-skip-member", autodoc_skip_member)
112+
app.connect("build-finished", remove_doctree, priority=600)
107113

108114

109115
local_path = os.path.dirname(os.path.realpath(__file__))
@@ -112,7 +118,6 @@ def setup(app):
112118
try:
113119
from ansys.aedt.core import __version__
114120
except ImportError:
115-
116121
sys.path.append(os.path.abspath(os.path.join(local_path)))
117122
sys.path.append(os.path.join(root_path))
118123
from ansys.aedt.core import __version__
@@ -181,8 +186,8 @@ def setup(app):
181186
"GL09", # Deprecation warning should precede extended summary
182187
"GL10", # reST directives {directives} must be followed by two colons
183188
# Return
184-
"RT04", # Return value description should start with a capital letter"
185-
"RT05", # Return value description should finish with "."
189+
"RT04", # Return value description should start with a capital letter"
190+
"RT05", # Return value description should finish with "."
186191
# Summary
187192
"SS01", # No summary found
188193
"SS02", # Summary does not start with a capital letter
@@ -319,7 +324,7 @@ def setup(app):
319324
# These paths are either relative to html_static_path
320325
# or fully qualified paths (eg. https://...)
321326
html_css_files = [
322-
'custom.css',
327+
"custom.css",
323328
]
324329

325330
# -- Options for LaTeX output ------------------------------------------------
@@ -338,6 +343,4 @@ def setup(app):
338343
# If we are on a release, we have to ignore the "release" URLs, since it is not
339344
# available until the release is published.
340345
if switcher_version != "dev":
341-
linkcheck_ignore.append(
342-
f"https://github.com/ansys/pyaedt/releases/tag/v{__version__}"
343-
) # noqa: E501
346+
linkcheck_ignore.append(f"https://github.com/ansys/pyaedt/releases/tag/v{__version__}") # noqa: E501

0 commit comments

Comments
 (0)