Skip to content

Commit

Permalink
chore: enable ruff formatter on pre-commit (#1312)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
  • Loading branch information
RobPasMue and pyansys-ci-bot authored Jul 17, 2024
1 parent e78525e commit 646db2d
Show file tree
Hide file tree
Showing 54 changed files with 110 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repos:
rev: v0.5.2
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand All @@ -29,7 +30,6 @@ repos:
rev: v0.3.1
hooks:
- id: add-license-headers
files: '(src|examples|tests|docker)/.*\.(py)|\.(proto)'
args:
- --start_year=2023

Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1312.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chore: enable ruff formatter on pre-commit
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def get_wheelhouse_assets_dictionary():
assets_context_runners = ["ubuntu-latest", "windows-latest", "macos-latest"]
assets_context_python_versions = ["3.9", "3.10", "3.11", "3.12"]
if get_version_match(__version__) == "dev":

# Try to retrieve the content three times before failing
content = None
for _ in range(3):
Expand Down
2 changes: 1 addition & 1 deletion docker/build_docker_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

# Copy the Geometry Service files to the temporary directory
print(f">>> Copying Geometry Service files to temporary directory to {TMP_DIR}")
BIN_DIR = TMP_DIR / "bins" / "DockerWindows" /"bin" /"x64"/"Release_Headless" /"net472"
BIN_DIR = TMP_DIR / "bins" / "DockerWindows" / "bin" / "x64" / "Release_Headless" / "net472"

# Create the directory structure
shutil.copytree(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ name = "ansys.geometry.core"
[tool.ruff]
line-length = 100
fix = true
extend-exclude = ["tests/integration/files"]

[tool.ruff.format]
quote-style = "double"
Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/connection/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module providing definitions for the backend types."""

from enum import Enum, unique


Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/connection/docker_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module for connecting to a local Geometry Service Docker container."""

from enum import Enum
from functools import wraps
import os
Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/connection/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module for connecting to instances of the Geometry service."""

import logging
import os

Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/connection/product_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module containing the ``ProductInstance`` class."""

import logging
import os
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/connection/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
python -c "from ansys.geometry.core.connection import validate; validate()"
"""

from ansys.geometry.core.connection.client import GrpcClient


Expand Down
79 changes: 23 additions & 56 deletions src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Provides for managing a body."""

from abc import ABC, abstractmethod
from enum import Enum, unique
from functools import wraps
Expand Down Expand Up @@ -223,9 +224,7 @@ def add_midsurface_offset(self, offset: "MidSurfaceOffsetType") -> None:
return

@abstractmethod
def imprint_curves(
self, faces: List[Face], sketch: Sketch
) -> Tuple[List[Edge], List[Face]]:
def imprint_curves(self, faces: List[Face], sketch: Sketch) -> Tuple[List[Edge], List[Face]]:
"""Imprint all specified geometries onto specified faces of the body.
Parameters
Expand Down Expand Up @@ -318,9 +317,7 @@ def imprint_projected_curves(
return

@abstractmethod
def translate(
self, direction: UnitVector3D, distance: Union[Quantity, Distance, Real]
) -> None:
def translate(self, direction: UnitVector3D, distance: Union[Quantity, Distance, Real]) -> None:
"""Translate the body in a specified direction and distance.
Parameters
Expand Down Expand Up @@ -443,9 +440,7 @@ def copy(self, parent: "Component", name: str = None) -> "Body":
return

@abstractmethod
def tessellate(
self, merge: Optional[bool] = False
) -> Union["PolyData", "MultiBlock"]:
def tessellate(self, merge: Optional[bool] = False) -> Union["PolyData", "MultiBlock"]:
"""Tessellate the body and return the geometry as triangles.
Parameters
Expand Down Expand Up @@ -479,7 +474,7 @@ def tessellate(
>>> body = my_comp.extrude_sketch("my-sketch", sketch, 1 * u.m)
>>> blocks = body.tessellate()
>>> blocks
>>> MultiBlock (0x7f94ec757460)
>>> MultiBlock(0x7F94EC757460)
N Blocks: 6
X Bounds: 0.000, 4.000
Y Bounds: -1.000, 0.000
Expand Down Expand Up @@ -600,7 +595,7 @@ def subtract(self, other: Union["Body", Iterable["Body"]], keep_other: bool = Fa
return

@protect_grpc
def unite(self, other: Union["Body", Iterable["Body"]], keep_other : bool = False) -> None:
def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False) -> None:
"""Unite two (or more) bodies.
Notes
Expand Down Expand Up @@ -665,7 +660,7 @@ def __init__(
self._commands_stub = CommandsStub(self._grpc_client.channel)
self._tessellation = None

def reset_tessellation_cache(func): # noqa: N805
def reset_tessellation_cache(func): # noqa: N805
"""Decorate ``MasterBody`` methods that need tessellation cache update.
Parameters
Expand Down Expand Up @@ -751,23 +746,17 @@ def is_alive(self) -> bool: # noqa: D102
@protect_grpc
def volume(self) -> Quantity: # noqa: D102
if self.is_surface:
self._grpc_client.log.debug(
"Dealing with planar surface. Returning 0 as the volume."
)
self._grpc_client.log.debug("Dealing with planar surface. Returning 0 as the volume.")
return Quantity(0, DEFAULT_UNITS.SERVER_VOLUME)
else:
self._grpc_client.log.debug(
f"Retrieving volume for body {self.id} from server."
)
self._grpc_client.log.debug(f"Retrieving volume for body {self.id} from server.")
volume_response = self._bodies_stub.GetVolume(self._grpc_id)
return Quantity(volume_response.volume, DEFAULT_UNITS.SERVER_VOLUME)

@protect_grpc
@check_input_types
def assign_material(self, material: Material) -> None: # noqa: D102
self._grpc_client.log.debug(
f"Assigning body {self.id} material {material.name}."
)
self._grpc_client.log.debug(f"Assigning body {self.id} material {material.name}.")
self._bodies_stub.SetAssignedMaterial(
SetAssignedMaterialRequest(id=self._id, material=material.name)
)
Expand Down Expand Up @@ -911,16 +900,12 @@ def map(self, frame: Frame) -> None: # noqa: D102
@min_backend_version(24, 2, 0)
def mirror(self, plane: Plane) -> None: # noqa: D102
self._grpc_client.log.debug(f"Mirroring body {self.id}.")
self._bodies_stub.Mirror(
MirrorRequest(id=self.id, plane=plane_to_grpc_plane(plane))
)
self._bodies_stub.Mirror(MirrorRequest(id=self.id, plane=plane_to_grpc_plane(plane)))

@protect_grpc
@min_backend_version(24, 2, 0)
def get_collision(self, body: "Body") -> CollisionType: # noqa: D102
self._grpc_client.log.debug(
f"Get collision between body {self.id} and body {body.id}."
)
self._grpc_client.log.debug(f"Get collision between body {self.id} and body {body.id}.")
response = self._bodies_stub.GetCollision(
GetCollisionRequest(
body_1_id=self.id,
Expand Down Expand Up @@ -1037,16 +1022,14 @@ class Body(IBody):
Master body that this body is an occurrence of.
"""

def __init__(
self, id, name, parent_component: "Component", template: MasterBody
) -> None:
def __init__(self, id, name, parent_component: "Component", template: MasterBody) -> None:
"""Initialize the ``Body`` class."""
self._id = id
self._name = name
self._parent_component = parent_component
self._template = template

def reset_tessellation_cache(func): # noqa: N805
def reset_tessellation_cache(func): # noqa: N805
"""Decorate ``Body`` methods that require a tessellation cache update.
Parameters
Expand Down Expand Up @@ -1083,9 +1066,7 @@ def parent_component(self) -> "Component": # noqa: D102
@protect_grpc
@ensure_design_is_active
def faces(self) -> List[Face]: # noqa: D102
self._template._grpc_client.log.debug(
f"Retrieving faces for body {self.id} from server."
)
self._template._grpc_client.log.debug(f"Retrieving faces for body {self.id} from server.")
grpc_faces = self._template._bodies_stub.GetFaces(EntityIdentifier(id=self.id))
return [
Face(
Expand All @@ -1102,9 +1083,7 @@ def faces(self) -> List[Face]: # noqa: D102
@protect_grpc
@ensure_design_is_active
def edges(self) -> List[Edge]: # noqa: D102
self._template._grpc_client.log.debug(
f"Retrieving edges for body {self.id} from server."
)
self._template._grpc_client.log.debug(f"Retrieving edges for body {self.id} from server.")
grpc_edges = self._template._bodies_stub.GetEdges(EntityIdentifier(id=self.id))
return [
Edge(
Expand Down Expand Up @@ -1190,9 +1169,7 @@ def imprint_curves( # noqa: D102
is_found = True
break
if not is_found:
raise ValueError(
f"Face with ID {provided_face.id} is not part of this body."
)
raise ValueError(f"Face with ID {provided_face.id} is not part of this body.")

self._template._grpc_client.log.debug(
f"Imprinting curves provided on {self.id} "
Expand All @@ -1202,9 +1179,7 @@ def imprint_curves( # noqa: D102
imprint_response = self._template._commands_stub.ImprintCurves(
ImprintCurvesRequest(
body=self._id,
curves=sketch_shapes_to_grpc_geometries(
sketch._plane, sketch.edges, sketch.faces
),
curves=sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces),
faces=[face._id for face in faces],
)
)
Expand Down Expand Up @@ -1243,9 +1218,7 @@ def project_curves( # noqa: D102
curves = sketch_shapes_to_grpc_geometries(
sketch._plane, sketch.edges, sketch.faces, only_one_curve=only_one_curve
)
self._template._grpc_client.log.debug(
f"Projecting provided curves on {self.id}."
)
self._template._grpc_client.log.debug(f"Projecting provided curves on {self.id}.")

project_response = self._template._commands_stub.ProjectCurves(
ProjectCurvesRequest(
Expand Down Expand Up @@ -1281,9 +1254,7 @@ def imprint_projected_curves( # noqa: D102
curves = sketch_shapes_to_grpc_geometries(
sketch._plane, sketch.edges, sketch.faces, only_one_curve=only_one_curve
)
self._template._grpc_client.log.debug(
f"Projecting provided curves on {self.id}."
)
self._template._grpc_client.log.debug(f"Projecting provided curves on {self.id}.")

response = self._template._commands_stub.ImprintProjectedCurves(
ProjectCurvesRequest(
Expand Down Expand Up @@ -1345,9 +1316,7 @@ def copy(self, parent: "Component", name: str = None) -> "Body": # noqa: D102
def tessellate( # noqa: D102
self, merge: Optional[bool] = False
) -> Union["PolyData", "MultiBlock"]:
return self._template.tessellate(
merge, self.parent_component.get_world_transform()
)
return self._template.tessellate(merge, self.parent_component.get_world_transform())

def plot( # noqa: D102
self,
Expand All @@ -1373,7 +1342,7 @@ def intersect(self, other: Union["Body", Iterable["Body"]], keep_other: bool = F
self.__generic_boolean_op(other, keep_other, "intersect", "bodies do not intersect")

def subtract(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False) -> None: # noqa: D102
self.__generic_boolean_op(other, keep_other,"subtract", "empty (complete) subtraction")
self.__generic_boolean_op(other, keep_other, "subtract", "empty (complete) subtraction")

def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False) -> None: # noqa: D102
self.__generic_boolean_op(other, keep_other, "unite", "union operation failed")
Expand Down Expand Up @@ -1415,9 +1384,7 @@ def __generic_boolean_op(
all_response = []
for body2 in other:
response = self._template._bodies_stub.Boolean(
BooleanRequest(
body1=self.id, body2=body2.id, method=type_bool_op
)
BooleanRequest(body1=self.id, body2=body2.id, method=type_bool_op)
).empty_result
all_response.append(response)

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/geometry/core/designer/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ def plot(
... )
>>> for x, y in zip(xx.ravel(), yy.ravel()):
... sketch = Sketch(plane)
... sketch.circle(Point2D([x, y]), 0.2*u.m)
... sketch.circle(Point2D([x, y]), 0.2 * u.m)
... mycomp.extrude_sketch(f"body-{x}-{y}", sketch, 1 * u.m)
>>> mycomp
ansys.geometry.core.designer.Component 0x2203cc9ec50
Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/designer/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module providing fundamental data of an assembly."""

from beartype.typing import TYPE_CHECKING, List

from ansys.geometry.core.designer.body import MasterBody
Expand Down
18 changes: 9 additions & 9 deletions src/ansys/geometry/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def __init__(self, logger, extra=None): # noqa: D107
def process(self, msg, kwargs): # noqa: D102
kwargs["extra"] = {}
# This are the extra parameters sent to log
kwargs["extra"][
"instance_name"
] = self.extra.get_name() # here self.extra is the argument passed to the log records.
kwargs["extra"]["instance_name"] = (
self.extra.get_name()
) # here self.extra is the argument passed to the log records.
return msg, kwargs

def log_to_file(self, filename: str = FILE_NAME, level: int = LOG_LEVEL):
Expand Down Expand Up @@ -241,7 +241,7 @@ def log_to_stdout(self, level=LOG_LEVEL):
self.logger = add_stdout_handler(self.logger, level=level)
self.std_out_handler = self.logger.std_out_handler

def setLevel(self, level="DEBUG"): # noqa: N802
def setLevel(self, level="DEBUG"): # noqa: N802
"""Change the log level of the object and the attached handlers.
Parameters
Expand Down Expand Up @@ -337,15 +337,15 @@ class Logger:
created when a Geometry service instance is created.
>>> from ansys.geometry.core import Modeler
>>> modeler = Modeler(loglevel='DEBUG')
>>> modeler._log.info('This is a useful message')
>>> modeler = Modeler(loglevel="DEBUG")
>>> modeler._log.info("This is a useful message")
INFO - - <ipython-input-24-80df150fe31f> - <module> - This is LOG debug message.
Import the global PyAnsys Geometry logger and add a file output handler.
>>> import os
>>> from ansys.geometry.core import LOG
>>> file_path = os.path.join(os.getcwd(), 'pyansys-geometry.log')
>>> file_path = os.path.join(os.getcwd(), "pyansys-geometry.log")
>>> LOG.log_to_file(file_path)
"""

Expand Down Expand Up @@ -411,7 +411,7 @@ def log_to_file(self, filename=FILE_NAME, level=LOG_LEVEL):
>>> from ansys.geometry.core import LOG
>>> import os
>>> file_path = os.path.join(os.getcwd(), 'pyansys-geometry.log')
>>> file_path = os.path.join(os.getcwd(), "pyansys-geometry.log")
>>> LOG.log_to_file(file_path)
"""
self = addfile_handler(self, filename=filename, level=level, write_headers=True)
Expand All @@ -427,7 +427,7 @@ def log_to_stdout(self, level=LOG_LEVEL):
"""
self = add_stdout_handler(self, level=level)

def setLevel(self, level="DEBUG"): # noqa: N802
def setLevel(self, level="DEBUG"): # noqa: N802
"""Change the log level of the object and the attached handlers."""
self.logger.setLevel(level)
for each_handler in self.logger.handlers:
Expand Down
1 change: 1 addition & 0 deletions src/ansys/geometry/core/math/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Provides matrix primitive representations."""

from beartype import beartype as check_input_types
from beartype.typing import Optional, Union
import numpy as np
Expand Down
Loading

0 comments on commit 646db2d

Please sign in to comment.