Skip to content

Commit 02ba8d0

Browse files
ecoussoux-ansyssvandenb-devpre-commit-ci[bot]SMoraisAnsys
authored
CHORE: Setting up ruff (#1233)
* chore: Introduce ruff config, remove flake8, update pre-commit-config (no formatting), enforce I(sort) rule * chore: Update revs for blacken-docs pre-commit hook * chore: Apply ruff formatting, add corresponding hook to pre-commit-config and update files accordingly * Exhaustive list of ignored ruff linting rules and enable auto-fix * MISC: Auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci * chore: Update list of ignored rules for ruff and pre-commit hooks, apply ruff linting and formatting * Apply suggestions from code review Co-authored-by: Sébastien Morais <[email protected]> * chore: Rework improper formatting of some code examples inside docstrings * MISC: Auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci --------- Co-authored-by: svandenb-dev <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sébastien Morais <[email protected]>
1 parent 9bf4827 commit 02ba8d0

File tree

84 files changed

+522
-555
lines changed

Some content is hidden

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

84 files changed

+522
-555
lines changed

.flake8

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

.pre-commit-config.yaml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,17 @@ ci:
1010

1111
repos:
1212

13-
- repo: https://github.com/psf/black
14-
rev: 23.10.1 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.12.10
1515
hooks:
16-
- id: black
17-
args:
18-
- --line-length=120
16+
- id: ruff-check
17+
- id: ruff-format
1918

2019
- repo: https://github.com/adamchainz/blacken-docs
21-
rev: 1.16.0
20+
rev: 1.19.1
2221
hooks:
2322
- id: blacken-docs
24-
additional_dependencies: [black==23.10.1]
25-
26-
- repo: https://github.com/pycqa/isort
27-
rev: 5.12.0
28-
hooks:
29-
- id: isort
30-
args: ["--profile=black"]
31-
32-
- repo: https://github.com/PyCQA/flake8
33-
rev: 6.1.0
34-
hooks:
35-
- id: flake8
36-
args: [
37-
--max-line-length, "120",
38-
ansys, codegen, doc, examples, tests
39-
]
23+
additional_dependencies: [black==25.1.0]
4024

4125
- repo: https://github.com/codespell-project/codespell
4226
rev: v2.3.0

doc/print_errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Read errors output from a Sphinx build and remove duplicate groups."""
2+
23
import os
34
import pathlib
45
import sys

pyproject.toml

Lines changed: 127 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,133 @@ Source = "https://github.com/ansys/pyedb"
8888
Discussions = "https://github.com/ansys/pyedb/discussions"
8989
Releases = "https://github.com/ansys/pyedb/releases"
9090

91-
[tool.black]
92-
line-length = 88
93-
94-
[tool.isort]
95-
profile = "black"
96-
force_sort_within_sections = true
97-
default_section = "THIRDPARTY"
98-
src_paths = ["doc", "src", "tests"]
91+
[tool.ruff]
92+
line-length = 120
93+
fix = true
94+
95+
[tool.ruff.format]
96+
quote-style = "double"
97+
indent-style = "space"
98+
docstring-code-format = true
99+
100+
[tool.ruff.lint]
101+
select = [
102+
"D", # pydocstyle, see https://docs.astral.sh/ruff/rules/#pydocstyle-d
103+
"E", # pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
104+
"F", # pyflakes, see https://docs.astral.sh/ruff/rules/#pyflakes-f
105+
"I", # isort, see https://docs.astral.sh/ruff/rules/#isort-i
106+
"N", # pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
107+
"PTH", # flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
108+
"TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
109+
"W", # pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
110+
]
111+
ignore = [
112+
# "D" - pydocstyle, see https://docs.astral.sh/ruff/rules/#pydocstyle-d
113+
"D100", # undocumented-public-module
114+
"D101", # undocumented-public-class
115+
"D102", # undocumented-public-method
116+
"D103", # undocumented-public-function
117+
"D104", # undocumented-public-package
118+
"D105", # undocumented-magic-method
119+
"D106", # undocumented-public-nested-class
120+
"D200", # unnecessary-multiline-docstring
121+
"D202", # blank-line-after-function
122+
"D205", # missing-blank-line-after-summary
123+
"D208", # over-indentation
124+
"D209", # new-line-after-last-paragraph
125+
"D210", # surrounding-whitespace
126+
"D214", # overindented-section
127+
"D215", # overindented-section-underline
128+
"D301", # escape-sequence-in-docstring
129+
"D400", # missing-trailing-period
130+
"D401", # non-imperative-mood
131+
"D403", # first-word-uncapitalized
132+
"D404", # docstring-starts-with-this
133+
"D405", # non-capitalized-section-name
134+
"D406", # missing-new-line-after-section-name
135+
"D407", # missing-dashed-underline-after-section
136+
"D409", # mismatched-section-underline-length
137+
"D410", # no-blank-line-after-section
138+
"D411", # no-blank-line-before-section
139+
"D412", # blank-lines-between-header-and-content
140+
"D414", # empty-docstring-section
141+
"D419", # empty-docstring
142+
143+
# "E" - pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
144+
"E402", # module-import-not-at-top-of-file
145+
"E711", # none-comparison
146+
"E712", # true-false-comparison
147+
"E713", # not-in-test
148+
"E721", # type-comparison
149+
"E722", # bare-except
150+
"E731", # lambda-assignment
151+
"E741", # ambiguous-variable-name
152+
"E743", # ambiguous-function-name
153+
154+
# "F" - pyflakes, see https://docs.astral.sh/ruff/rules/#pyflakes-f
155+
"F401", # unused-import
156+
"F523", # string-dot-format-extra-positional-arguments
157+
"F541", # f-string-missing-placeholders
158+
"F811", # redefined-while-unused
159+
"F821", # undefined-name
160+
"F841", # unused-variable
161+
162+
# "N" - pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
163+
"N801", # invalid-class-name
164+
"N802", # invalid-function-name
165+
"N803", # invalid-argument-name
166+
"N806", # non-lowercase-variable-in-function
167+
"N812", # lowercase-imported-as-non-lowercase
168+
"N813", # camelcase-imported-as-lowercase
169+
"N815", # mixed-case-variable-in-class-scope
170+
"N816", # mixed-case-variable-in-global-scope
171+
"N817", # camelcase-imported-as-acronym
172+
"N818", # error-suffix-on-exception-name
173+
"N999", # invalid-module-name
174+
175+
# "PTH" - flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
176+
"PTH100", # os-path-abspath
177+
"PTH101", # os-chmod
178+
"PTH102", # os-mkdir
179+
"PTH103", # os-makedirs
180+
"PTH104", # os-rename
181+
"PTH107", # os-remove
182+
"PTH108", # os-unlink
183+
"PTH110", # os-path-exists
184+
"PTH111", # os-path-expanduser
185+
"PTH112", # os-path-isdir
186+
"PTH113", # os-path-isfile
187+
"PTH116", # os-stat
188+
"PTH118", # os-path-join
189+
"PTH119", # os-path-basename
190+
"PTH120", # os-path-dirname
191+
"PTH122", # os-path-splitext
192+
"PTH123", # builtin-open
193+
"PTH202", # os-path-getsize
194+
195+
# "TD" - flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
196+
"TD001", # invalid-todo-tag
197+
"TD002", # missing-todo-author
198+
"TD003", # missing-todo-link
199+
"TD004", # missing-todo-colon
200+
"TD005", # missing-todo-description
201+
"TD006", # invalid-todo-capitalization
202+
203+
# "W" - pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
204+
"W605" # invalid-escape-sequence
205+
]
206+
207+
[tool.ruff.lint.pydocstyle]
208+
# Use Numpy-style docstrings.
209+
convention = "numpy"
210+
211+
[tool.ruff.lint.isort]
212+
force-sort-within-sections = true
213+
known-first-party = ["doc", "src", "tests"]
214+
combine-as-imports = true
215+
216+
[tool.ruff.lint.mccabe]
217+
max-complexity = 10
99218

100219
[tool.codespell]
101220
skip = '*.pyc,*.txt,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,*.a3dcomp,flycheck*,./.git/*,./.hypothesis/*,*.yml,./doc/build/*,./doc/images/*,./dist/*,*~,.hypothesis*,./doc/source/examples/*,*cover,*.dat,*.mac,*.cdb,*.CDB,build,./factory/*,PKG-INFO,*.mypy_cache/*,./_unused/*,pyproject.toml'

src/pyedb/dotnet/clr_module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non
5151
# TODO: Fall backing to dotnetcore2 should be removed in a near future.
5252
except Exception:
5353
warnings.warn(
54-
"Unable to set .NET root and locate the runtime configuration file. "
55-
"Falling back to using dotnetcore2."
54+
"Unable to set .NET root and locate the runtime configuration file. Falling back to using dotnetcore2."
5655
)
5756
warnings.warn(LINUX_WARNING)
5857

src/pyedb/dotnet/database/Variables.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
3636
"""
3737

38-
from __future__ import absolute_import # noreorder
39-
from __future__ import division
38+
from __future__ import (
39+
absolute_import, # noreorder
40+
division,
41+
)
4042

4143
import os
4244
import re
@@ -493,13 +495,13 @@ def decompose(self, variable_value): # pragma: no cover
493495
--------
494496
>>> hfss = Hfss()
495497
>>> print(hfss.variable_manager.decompose("5mm"))
496-
>>> (5.0, 'mm')
498+
>>> (5.0, "mm")
497499
>>> hfss["v1"] = "3N"
498500
>>> print(hfss.variable_manager.decompose("v1"))
499-
>>> (3.0, 'N')
501+
>>> (3.0, "N")
500502
>>> hfss["v2"] = "2*v1"
501503
>>> print(hfss.variable_manager.decompose("v2"))
502-
>>> (6.0, 'N')
504+
>>> (6.0, "N")
503505
"""
504506
if variable_value in self.independent_variable_names:
505507
val, unit = decompose_variable_value(self[variable_value].expression)
@@ -1009,8 +1011,13 @@ def set_variable(
10091011
creating the property if it does not already exist. Also make
10101012
it read-only and hidden and add a description.
10111013
1012-
>>> aedtapp.variable_manager.set_variable(variable_name="p2", expression="10mm", readonly=True, hidden=True,
1013-
... description="This is the description of this variable.")
1014+
>>> aedtapp.variable_manager.set_variable(
1015+
... variable_name="p2",
1016+
... expression="10mm",
1017+
... readonly=True,
1018+
... hidden=True,
1019+
... description="This is the description of this variable.",
1020+
... )
10141021
10151022
Set the value of the project variable ``$p1`` to ``"30mm"``,
10161023
creating the variable if it does not exist.
@@ -1708,7 +1715,7 @@ def decompose(self): # pragma: no cover
17081715
>>> hfss = Hfss()
17091716
>>> hfss["v1"] = "3N"
17101717
>>> print(hfss.variable_manager["v1"].decompose("v1"))
1711-
>>> (3.0, 'N')
1718+
>>> (3.0, "N")
17121719
17131720
"""
17141721
return decompose_variable_value(self.evaluated_value)
@@ -1760,9 +1767,9 @@ def format(self, format): # pragma: no cover
17601767
>>> from pyedb.dotnet.database.Variables import Variable
17611768
17621769
>>> v = Variable("10W")
1763-
>>> assert v.format("f") == '10.000000W'
1764-
>>> assert v.format("06.2f") == '010.00W'
1765-
>>> assert v.format("6.2f") == ' 10.00W'
1770+
>>> assert v.format("f") == "10.000000W"
1771+
>>> assert v.format("06.2f") == "010.00W"
1772+
>>> assert v.format("6.2f") == " 10.00W"
17661773
17671774
"""
17681775
return ("{0:" + format + "}{1}").format(self.numeric_value, self._units)

src/pyedb/dotnet/database/cell/layout.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""
2424
This module contains these classes: `EdbLayout` and `Shape`.
2525
"""
26+
2627
from typing import List, Union
2728

2829
from pyedb.dotnet.database.cell.hierarchy.component import EDBComponent

src/pyedb/dotnet/database/cell/primitive/primitive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class Primitive(Connectable):
3939
>>> from pyedb import Edb
4040
>>> edb = Edb(myedb, edbversion="2021.2")
4141
>>> edb_prim = edb.modeler.primitives[0]
42-
>>> edb_prim.is_void # Class Property
43-
>>> edb_prim.IsVoid() # EDB Object Property
42+
>>> edb_prim.is_void # Class Property
43+
>>> edb_prim.IsVoid() # EDB Object Property
4444
"""
4545

4646
def __init__(self, pedb, edb_object):

src/pyedb/dotnet/database/components.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
"""This module contains the `Components` class.
23+
"""This module contains the `Components` class."""
2424

25-
"""
2625
import codecs
2726
import json
2827
import math
@@ -541,16 +540,17 @@ def get_component_placement_vector(
541540
542541
Examples
543542
--------
544-
>>> edb1 = Edb(edbpath=targetfile1, edbversion="2021.2")
543+
>>> edb1 = Edb(edbpath=targetfile1, edbversion="2021.2")
545544
>>> hosting_cmp = edb1.components.get_component_by_name("U100")
546545
>>> mounted_cmp = edb2.components.get_component_by_name("BGA")
547546
>>> vector, rotation, solder_ball_height = edb1.components.get_component_placement_vector(
548-
... mounted_component=mounted_cmp,
549-
... hosting_component=hosting_cmp,
550-
... mounted_component_pin1="A12",
551-
... mounted_component_pin2="A14",
552-
... hosting_component_pin1="A12",
553-
... hosting_component_pin2="A14")
547+
... mounted_component=mounted_cmp,
548+
... hosting_component=hosting_cmp,
549+
... mounted_component_pin1="A12",
550+
... mounted_component_pin2="A14",
551+
... hosting_component_pin1="A12",
552+
... hosting_component_pin2="A14",
553+
... )
554554
"""
555555
m_pin1_pos = [0.0, 0.0]
556556
m_pin2_pos = [0.0, 0.0]
@@ -1270,7 +1270,7 @@ def deactivate_rlc_component(self, component=None, create_circuit_port=False, pe
12701270
Examples
12711271
--------
12721272
>>> from pyedb import Edb
1273-
>>> edb_file = r'C:\my_edb_file.aedb'
1273+
>>> edb_file = r"C:\my_edb_file.aedb"
12741274
>>> edb = Edb(edb_file)
12751275
>>> for cmp in list(edb.components.instances.keys()):
12761276
>>> edb.components.deactivate_rlc_component(component=cmp, create_circuit_port=False)
@@ -1750,9 +1750,9 @@ def set_component_model(self, componentname, model_type="Spice", modelpath=None,
17501750
17511751
>>> from pyedb import Edb
17521752
>>> edbapp = Edb("myaedbfolder")
1753-
>>> edbapp.components.set_component_model("A1", model_type="Spice",
1754-
... modelpath="pathtospfile",
1755-
... modelname="spicemodelname")
1753+
>>> edbapp.components.set_component_model(
1754+
... "A1", model_type="Spice", modelpath="pathtospfile", modelname="spicemodelname"
1755+
... )
17561756
17571757
"""
17581758
if not modelname:
@@ -2152,9 +2152,7 @@ def set_component_rlc(
21522152
21532153
>>> from pyedb import Edb
21542154
>>> edbapp = Edb("myaedbfolder")
2155-
>>> edbapp.components.set_component_rlc(
2156-
... "R1", res_value=50, ind_value=1e-9, cap_value=1e-12, isparallel=False
2157-
... )
2155+
>>> edbapp.components.set_component_rlc("R1", res_value=50, ind_value=1e-9, cap_value=1e-12, isparallel=False)
21582156
21592157
"""
21602158
if res_value is None and ind_value is None and cap_value is None:

src/pyedb/dotnet/database/dotnet/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222

2323
"""Database."""
24+
2425
import re
2526

2627
from pyedb.dotnet.database.general import convert_py_list_to_net_list

0 commit comments

Comments
 (0)