Skip to content

CHORE: Setting up ruff #1233

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

27 changes: 6 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,17 @@ ci:

repos:

- repo: https://github.com/psf/black
rev: 23.10.1 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.9
hooks:
- id: black
args:
- --line-length=120
- id: ruff
- id: ruff-format

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies: [black==23.10.1]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [
--max-line-length, "120",
ansys, codegen, doc, examples, tests
]
additional_dependencies: [black==25.1.0]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
1 change: 1 addition & 0 deletions doc/print_errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Read errors output from a Sphinx build and remove duplicate groups."""

import os
import pathlib
import sys
Expand Down
133 changes: 125 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,131 @@ Source = "https://github.com/ansys/pyedb"
Discussions = "https://github.com/ansys/pyedb/discussions"
Releases = "https://github.com/ansys/pyedb/releases"

[tool.black]
line-length = 88

[tool.isort]
profile = "black"
force_sort_within_sections = true
default_section = "THIRDPARTY"
src_paths = ["doc", "src", "tests"]
[tool.ruff]
line-length = 120
fix = true

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
docstring-code-format = true

[tool.ruff.lint]
select = [
"D", # pydocstyle, see https://docs.astral.sh/ruff/rules/#pydocstyle-d
"E", # pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"F", # pyflakes, see https://docs.astral.sh/ruff/rules/#pyflakes-f
"I", # isort, see https://docs.astral.sh/ruff/rules/#isort-i
"N", # pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
"PTH", # flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
"W", # pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
]
ignore = [
# "D" - pydocstyle, see https://docs.astral.sh/ruff/rules/#pydocstyle-d
"D100", # undocumented-public-module
"D101", # undocumented-public-class
"D102", # undocumented-public-method
"D103", # undocumented-public-function
"D104", # undocumented-public-package
"D105", # undocumented-magic-method
"D106", # undocumented-public-nested-class
"D200", # unnecessary-multiline-docstring
"D202", # blank-line-after-function
"D205", # missing-blank-line-after-summary
"D208", # over-indentation
"D209", # new-line-after-last-paragraph
"D210", # surrounding-whitespace
"D214", # overindented-section
"D215", # overindented-section-underline
"D301", # escape-sequence-in-docstring
"D400", # missing-trailing-period
"D401", # non-imperative-mood
"D403", # first-word-uncapitalized
"D404", # docstring-starts-with-this
"D405", # non-capitalized-section-name
"D406", # missing-new-line-after-section-name
"D407", # missing-dashed-underline-after-section
"D409", # mismatched-section-underline-length
"D410", # no-blank-line-after-section
"D411", # no-blank-line-before-section
"D412", # blank-lines-between-header-and-content
"D414", # empty-docstring-section
"D419", # empty-docstring

# "E" - pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"E402", # module-import-not-at-top-of-file
"E711", # none-comparison
"E713", # not-in-test
"E721", # type-comparison
"E722", # bare-except
"E731", # lambda-assignment
"E741", # ambiguous-variable-name
"E743", # ambiguous-function-name

# "F" - pyflakes, see https://docs.astral.sh/ruff/rules/#pyflakes-f
"F401", # unused-import
"F523", # string-dot-format-extra-positional-arguments
"F541", # f-string-missing-placeholders
"F811", # redefined-while-unused
"F821", # undefined-name
"F841", # unused-variable

# "N" - pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
"N801", # invalid-class-name
"N802", # invalid-function-name
"N803", # invalid-argument-name
"N806", # non-lowercase-variable-in-function
"N812", # lowercase-imported-as-non-lowercase
"N813", # camelcase-imported-as-lowercase
"N815", # mixed-case-variable-in-class-scope
"N817", # camelcase-imported-as-acronym
"N818", # error-suffix-on-exception-name
"N999", # invalid-module-name

# "PTH" - flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"PTH100", # os-path-abspath
"PTH101", # os-chmod
"PTH102", # os-mkdir
"PTH103", # os-makedirs
"PTH104", # os-rename
"PTH107", # os-remove
"PTH108", # os-unlink
"PTH110", # os-path-exists
"PTH111", # os-path-expanduser
"PTH112", # os-path-isdir
"PTH113", # os-path-isfile
"PTH116", # os-stat
"PTH118", # os-path-join
"PTH119", # os-path-basename
"PTH120", # os-path-dirname
"PTH122", # os-path-splitext
"PTH123", # builtin-open
"PTH202", # os-path-getsize

# "TD" - flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
"TD001", # invalid-todo-tag
"TD002", # missing-todo-author
"TD003", # missing-todo-link
"TD004", # missing-todo-colon
"TD005", # missing-todo-description
"TD006", # invalid-todo-capitalization

# "W" - pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"W605" # invalid-escape-sequence
]

[tool.ruff.lint.pydocstyle]
# Use Numpy-style docstrings.
convention = "numpy"

[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = ["doc", "src", "tests"]
combine-as-imports = true

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.codespell]
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'
Expand Down
2 changes: 1 addition & 1 deletion src/pyedb/configuration/cfg_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def _retrieve_ic_die_properties_from_edb(self):
def _set_ic_die_properties_to_edb(self):
from ansys.edb.core.definition.die_property import (
DieOrientation as GrpcDieOrientation,
DieType as GrpcDieType,
)
from ansys.edb.core.definition.die_property import DieType as GrpcDieType
from ansys.edb.core.utility.value import Value as GrpcValue

cp = self.pyedb_obj.component_property
Expand Down
4 changes: 0 additions & 4 deletions src/pyedb/configuration/cfg_padstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ def __init__(self, parent):
def get_solder_ball_definition(self):
from ansys.edb.core.definition.solder_ball_property import (
SolderballPlacement as GrpcSolderballPlacement,
)
from ansys.edb.core.definition.solder_ball_property import (
SolderballShape as GrpcSolderballShape,
)

Expand Down Expand Up @@ -256,8 +254,6 @@ def get_pad_parameters_from_edb(self):
def set_pad_parameters_to_edb(self, param):
from ansys.edb.core.definition.padstack_def_data import (
PadGeometryType as GrpcPadGeometryType,
)
from ansys.edb.core.definition.padstack_def_data import (
PadType as GrpcPadType,
)
from ansys.edb.core.utility.value import Value as GrpcValue
Expand Down
2 changes: 0 additions & 2 deletions src/pyedb/configuration/cfg_ports_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,6 @@ def set_parameters_to_edb(self, edb_primitives):
from ansys.edb.core.geometry.point_data import PointData as GrpcPointData
from ansys.edb.core.terminal.edge_terminal import (
EdgeTerminal as GrpcEdgeTerminal,
)
from ansys.edb.core.terminal.edge_terminal import (
PrimitiveEdge as GrpcPrimitiveEdge,
)
from ansys.edb.core.utility.value import Value as GrpcValue
Expand Down
3 changes: 1 addition & 2 deletions src/pyedb/dotnet/clr_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non
# TODO: Fall backing to dotnetcore2 should be removed in a near future.
except Exception:
warnings.warn(
"Unable to set .NET root and locate the runtime configuration file. "
"Falling back to using dotnetcore2."
"Unable to set .NET root and locate the runtime configuration file. Falling back to using dotnetcore2."
)
warnings.warn(LINUX_WARNING)

Expand Down
47 changes: 27 additions & 20 deletions src/pyedb/dotnet/database/Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@

"""

from __future__ import absolute_import # noreorder
from __future__ import division
from __future__ import (
absolute_import, # noreorder
division,
)

import os
import re
Expand Down Expand Up @@ -490,13 +492,13 @@ def decompose(self, variable_value): # pragma: no cover
--------
>>> hfss = Hfss()
>>> print(hfss.variable_manager.decompose("5mm"))
>>> (5.0, 'mm')
>>> (5.0, "mm")
>>> hfss["v1"] = "3N"
>>> print(hfss.variable_manager.decompose("v1"))
>>> (3.0, 'N')
>>> (3.0, "N")
>>> hfss["v2"] = "2*v1"
>>> print(hfss.variable_manager.decompose("v2"))
>>> (6.0, 'N')
>>> (6.0, "N")
"""
if variable_value in self.independent_variable_names:
val, unit = decompose_variable_value(self[variable_value].expression)
Expand Down Expand Up @@ -1006,8 +1008,13 @@ def set_variable(
creating the property if it does not already exist. Also make
it read-only and hidden and add a description.

>>> aedtapp.variable_manager.set_variable(variable_name="p2", expression="10mm", readonly=True, hidden=True,
... description="This is the description of this variable.")
>>> aedtapp.variable_manager.set_variable(
... variable_name="p2",
... expression="10mm",
... readonly=True,
... hidden=True,
... description="This is the description of this variable.",
... )

Set the value of the project variable ``$p1`` to ``"30mm"``,
creating the variable if it does not exist.
Expand Down Expand Up @@ -1704,7 +1711,7 @@ def decompose(self): # pragma: no cover
>>> hfss = Hfss()
>>> hfss["v1"] = "3N"
>>> print(hfss.variable_manager["v1"].decompose("v1"))
>>> (3.0, 'N')
>>> (3.0, "N")

"""
return decompose_variable_value(self.evaluated_value)
Expand All @@ -1730,9 +1737,9 @@ def rescale_to(self, units): # pragma: no cover

"""
new_unit_system = unit_system(units)
assert (
new_unit_system == self.unit_system
), "New unit system {0} is inconsistent with the current unit system {1}."
assert new_unit_system == self.unit_system, (
"New unit system {0} is inconsistent with the current unit system {1}."
)
self._units = units
return self

Expand All @@ -1755,9 +1762,9 @@ def format(self, format): # pragma: no cover
>>> from pyedb.dotnet.database.Variables import Variable

>>> v = Variable("10W")
>>> assert v.format("f") == '10.000000W'
>>> assert v.format("06.2f") == '010.00W'
>>> assert v.format("6.2f") == ' 10.00W'
>>> assert v.format("f") == "10.000000W"
>>> assert v.format("06.2f") == "010.00W"
>>> assert v.format("6.2f") == " 10.00W"

"""
return ("{0:" + format + "}{1}").format(self.numeric_value, self._units)
Expand Down Expand Up @@ -1848,9 +1855,9 @@ def __add__(self, other): # pragma: no cover

"""
assert isinstance(other, Variable), "You can only add a variable with another variable."
assert (
self.unit_system == other.unit_system
), "Only ``Variable`` objects with the same unit system can be added."
assert self.unit_system == other.unit_system, (
"Only ``Variable`` objects with the same unit system can be added."
)
result_value = self.value + other.value
result_units = SI_UNITS[self.unit_system]
# If the units of the two operands are different, return SI-Units
Expand Down Expand Up @@ -1889,9 +1896,9 @@ def __sub__(self, other): # pragma: no cover

"""
assert isinstance(other, Variable), "You can only subtract a variable from another variable."
assert (
self.unit_system == other.unit_system
), "Only ``Variable`` objects with the same unit system can be subtracted."
assert self.unit_system == other.unit_system, (
"Only ``Variable`` objects with the same unit system can be subtracted."
)
result_value = self.value - other.value
result_units = SI_UNITS[self.unit_system]
# If the units of the two operands are different, return SI-Units
Expand Down
1 change: 1 addition & 0 deletions src/pyedb/dotnet/database/cell/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""
This module contains these classes: `EdbLayout` and `Shape`.
"""

from typing import Union

from pyedb.dotnet.database.cell.hierarchy.component import EDBComponent
Expand Down
4 changes: 2 additions & 2 deletions src/pyedb/dotnet/database/cell/primitive/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Primitive(Connectable):
>>> from pyedb import Edb
>>> edb = Edb(myedb, edbversion="2021.2")
>>> edb_prim = edb.modeler.primitives[0]
>>> edb_prim.is_void # Class Property
>>> edb_prim.IsVoid() # EDB Object Property
>>> edb_prim.is_void # Class Property
>>> edb_prim.IsVoid() # EDB Object Property
"""

def __init__(self, pedb, edb_object):
Expand Down
Loading
Loading