Skip to content

Commit e88b9db

Browse files
style: pre-commit fixes
1 parent 1dbef67 commit e88b9db

File tree

6 files changed

+47
-33
lines changed

6 files changed

+47
-33
lines changed

docs/logging.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Logging Configuration
22

3-
The magpylib-material-response package uses structured logging with [Loguru](https://loguru.readthedocs.io/) to provide informative messages about computation progress and debugging information.
3+
The magpylib-material-response package uses structured logging with
4+
[Loguru](https://loguru.readthedocs.io/) to provide informative messages about
5+
computation progress and debugging information.
46

57
## Default Behavior
68

7-
By default, the library **does not output any log messages**. This follows best practices for Python libraries to avoid cluttering user output unless explicitly requested.
9+
By default, the library **does not output any log messages**. This follows best
10+
practices for Python libraries to avoid cluttering user output unless explicitly
11+
requested.
812

913
## Enabling Logging
1014

@@ -24,6 +28,7 @@ configure_logging()
2428
## Configuration Options
2529

2630
### Log Level
31+
2732
```python
2833
from magpylib_material_response import configure_logging
2934

@@ -37,6 +42,7 @@ configure_logging(level="WARNING")
3742
```
3843

3944
### Output Destination
45+
4046
```python
4147
import sys
4248
from magpylib_material_response import configure_logging
@@ -49,6 +55,7 @@ configure_logging(sink="/path/to/logfile.log")
4955
```
5056

5157
### Disable Colors and Time
58+
5259
```python
5360
from magpylib_material_response import configure_logging
5461

@@ -96,10 +103,7 @@ from magpylib_material_response.meshing import mesh_Cuboid
96103
configure_logging(level="INFO")
97104

98105
# Create a magnet
99-
magnet = magpy.magnet.Cuboid(
100-
dimension=(0.01, 0.01, 0.02),
101-
polarization=(0, 0, 1)
102-
)
106+
magnet = magpy.magnet.Cuboid(dimension=(0.01, 0.01, 0.02), polarization=(0, 0, 1))
103107
magnet.susceptibility = 0.1
104108

105109
# Mesh the magnet - you'll see meshing progress
@@ -109,9 +113,11 @@ meshed = mesh_Cuboid(magnet, target_elems=1000, verbose=True)
109113
apply_demag(meshed, inplace=True)
110114
```
111115

112-
This will output structured log messages showing the progress of operations, timing information, and any warnings or errors.
116+
This will output structured log messages showing the progress of operations,
117+
timing information, and any warnings or errors.
113118

114119
## See Also
115120

116121
- {doc}`examples/index` - Working examples that demonstrate logging output
117-
- [Loguru Documentation](https://loguru.readthedocs.io/) - Complete reference for the underlying logging library
122+
- [Loguru Documentation](https://loguru.readthedocs.io/) - Complete reference
123+
for the underlying logging library

src/magpylib_material_response/demag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ def filter_distance(
260260
if dsf == 0:
261261
logger.warning(
262262
"No interaction pairs left after distance factor filtering",
263-
percentage=f"{dsf:.2f}%"
263+
percentage=f"{dsf:.2f}%",
264264
)
265265
else:
266266
logger.info(
267267
"Interaction pairs left after distance factor filtering",
268-
percentage=f"{dsf:.2f}%"
268+
percentage=f"{dsf:.2f}%",
269269
)
270270
out = [mask]
271271
if return_params:
@@ -309,7 +309,7 @@ def match_pairs(src_list, min_log_time=1):
309309
perc = len(unique_inds) / len(unique_inv_inds) * 100
310310
logger.info(
311311
"Interaction pairs left after pair matching filtering",
312-
percentage=f"{perc:.2f}%"
312+
percentage=f"{perc:.2f}%",
313313
)
314314

315315
params = {

src/magpylib_material_response/logging_config.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
def get_logger(name: str | None = None):
2020
"""
2121
Get a named logger for the package.
22-
22+
2323
Parameters
2424
----------
2525
name : str, optional
2626
Logger name. If None, uses the package root logger.
27-
27+
2828
Returns
2929
-------
3030
loguru.Logger
@@ -43,11 +43,11 @@ def configure_logging(
4343
) -> None:
4444
"""
4545
Configure logging for the package.
46-
46+
4747
This function should be called by users who want to see logging output
4848
from the library. By default, the library doesn't output logs unless
4949
explicitly configured.
50-
50+
5151
Parameters
5252
----------
5353
level : str, optional
@@ -63,20 +63,28 @@ def configure_logging(
6363
"""
6464
# Remove existing handlers to avoid duplicates
6565
logger.remove()
66-
66+
6767
# Get configuration from environment or use defaults
6868
if level is None:
6969
level = os.getenv("MAGPYLIB_LOG_LEVEL", "INFO")
70-
70+
7171
if enable_colors is None:
72-
enable_colors = os.getenv("MAGPYLIB_LOG_COLORS", "true").lower() in ("true", "1", "yes")
73-
72+
enable_colors = os.getenv("MAGPYLIB_LOG_COLORS", "true").lower() in (
73+
"true",
74+
"1",
75+
"yes",
76+
)
77+
7478
if show_time is None:
75-
show_time = os.getenv("MAGPYLIB_LOG_TIME", "true").lower() in ("true", "1", "yes")
76-
79+
show_time = os.getenv("MAGPYLIB_LOG_TIME", "true").lower() in (
80+
"true",
81+
"1",
82+
"yes",
83+
)
84+
7785
if sink is None:
7886
sink = sys.stderr
79-
87+
8088
# Build format string
8189
time_part = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | " if show_time else ""
8290
format_str = (
@@ -85,17 +93,17 @@ def configure_logging(
8593
"<cyan>{extra[module]}</cyan> | "
8694
"{level.icon:<2} {message}"
8795
)
88-
96+
8997
# Configure the logger
9098
logger.add(
9199
sink,
92100
level=level,
93101
format=format_str,
94102
colorize=enable_colors,
95103
filter=lambda record: (
96-
record["extra"].get("module", "").startswith("magpylib_material_response") or
97-
record.get("name", "").startswith("magpylib_material_response")
98-
)
104+
record["extra"].get("module", "").startswith("magpylib_material_response")
105+
or record.get("name", "").startswith("magpylib_material_response")
106+
),
99107
)
100108

101109

@@ -107,4 +115,4 @@ def disable_logging() -> None:
107115

108116
# Set up a default minimal configuration that doesn't output anything
109117
# Users need to call configure_logging() to see logs
110-
disable_logging()
118+
disable_logging()

src/magpylib_material_response/meshing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def mesh_Cuboid(cuboid, target_elems, verbose=False, **kwargs):
7272
"Meshing Cuboid",
7373
dimensions=f"{nnn[0]}x{nnn[1]}x{nnn[2]}",
7474
elements=elems,
75-
target=target_elems
75+
target=target_elems,
7676
)
7777

7878
# secure input type
@@ -151,7 +151,7 @@ def mesh_Cylinder(cylinder, target_elems, verbose=False, **kwargs):
151151
"Meshing CylinderSegment",
152152
dimensions=f"{nphi}x{nr}x{nh}",
153153
elements=elems,
154-
target=target_elems
154+
target=target_elems,
155155
)
156156
r = np.linspace(r1, r2, nr + 1)
157157
dh = h / nh

src/magpylib_material_response/polyline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def _find_circle_center_and_tangent_points(
4343
d = r / tan_theta
4444
if d > norm_bc * max_ratio or d > norm_ab * max_ratio:
4545
# rold, dold = r, d
46-
logger.debug("Fillet parameters adjusted", r=r, d=d, norm_ab=norm_ab, norm_bc=norm_bc)
46+
logger.debug(
47+
"Fillet parameters adjusted", r=r, d=d, norm_ab=norm_ab, norm_bc=norm_bc
48+
)
4749
d = min(norm_bc * max_ratio, norm_ab * max_ratio)
4850
r = d * tan_theta if theta > 0 else 0
4951
# warnings.warn(f"Radius {rold:.4g} is too big and has been reduced to {r:.4g}")

src/magpylib_material_response/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def timelog(msg, min_log_time=1):
6666

6767
if end > min_log_time:
6868
logger.info(
69-
"Operation completed",
70-
operation=msg,
71-
duration_seconds=round(end, 3)
69+
"Operation completed", operation=msg, duration_seconds=round(end, 3)
7270
)
7371

7472

0 commit comments

Comments
 (0)