Skip to content
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

38 solve errors that lead to nightly build failing #39

Merged
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e

## [Unreleased]

### Changed
* ruff.toml : removed deprecated ruff rules ANN101 and ANN102 from excluded rules
* Use f-string, where possible, instead of '%' style string formatting

### Solved
* src/farn/core/case.py : Changed the way how local variables get added / manipulated through code. Replaced access to `locals()` with `sys._getframe().f_locals` when manipulating local variables. This change became necessary as Python 3.13 changed the way Python's builtin `locals()` method works. See [PEP 667](https://peps.python.org/pep-0667/) for details.

### Dependencies
* Updated to ruff>=0.8.3 (from ruff>=0.6.3)
* Updated to pyright>=1.1.390 (from pyright>=1.1.378)
Expand Down
2 changes: 0 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ ignore = [
"PLR0912", # Too many branches <- @TODO: reactivate and resolve @CLAROS, 2024-10-21
"PLR0915", # Too many statements <- @TODO: reactivate and resolve @CLAROS, 2024-10-21
# Ruff lint rules considered as too strict and hence ignored
"ANN101", # Missing type annotation for `self` argument in instance methods (NOTE: also listed as deprecated by Ruff)
"ANN102", # Missing type annotation for `cls` argument in class methods (NOTE: also listed as deprecated by Ruff)
"FIX002", # Line contains TODO, consider resolving the issue
"TD003", # Missing issue link on the line following a TODO
"S101", # Use of assert detected
Expand Down
8 changes: 1 addition & 7 deletions src/farn/cli/farn.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,7 @@ def t4(p: tuple[float, float]) -> tuple[float, float]:
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.geometry(
"%dx%d+%d+%d"
% (
x_size,
y_size,
screen_width / 2 - x_size / 2,
screen_height / 2 - y_size / 2,
)
newGeometry=f"{x_size}x{y_size}+{int(screen_width / 2 - x_size / 2)}+{int(screen_height / 2 - y_size / 2)}"
)
image = tk.PhotoImage(file=temp_file)
canvas = tk.Canvas(root, height=y_size, width=x_size, bg="dark slate gray")
Expand Down
11 changes: 6 additions & 5 deletions src/farn/core/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import re
import sys
from collections.abc import MutableMapping, MutableSequence, Sequence
from copy import deepcopy
from enum import IntEnum
Expand Down Expand Up @@ -136,7 +137,7 @@ def is_valid(self) -> bool:
)
return False

# transfer a white list of case properties to locals() for subsequent filtering
# transfer a white list of case properties to frame.f_locals for subsequent filtering
available_vars: set[str] = set()
for attribute in dir(self):
try:
Expand All @@ -150,7 +151,7 @@ def is_valid(self) -> bool:
"condition",
"command_sets",
]:
locals()[attribute] = eval(f"self.{attribute}") # noqa: S307
sys._getframe().f_locals[attribute] = eval(f"self.{attribute}") # noqa: S307, SLF001 # type: ignore[reportPrivateUsage]
available_vars.add(attribute)
except Exception: # noqa: PERF203
logger.exception(
Expand All @@ -164,7 +165,7 @@ def is_valid(self) -> bool:
for parameter in self.parameters:
if parameter.name and not re.match("^_", parameter.name):
try:
exec(f"{parameter.name} = {parameter.value}") # noqa: S102
sys._getframe().f_locals[parameter.name] = parameter.value # noqa: SLF001 # type: ignore[reportPrivateUsage]
available_vars.add(parameter.name)
except Exception:
logger.exception(
Expand Down Expand Up @@ -264,8 +265,8 @@ def to_dict(self) -> dict[str, Any]:
def __str__(self) -> str:
return str(self.to_dict())

def __eq__(self, __o: object) -> bool:
return str(self) == str(__o)
def __eq__(self, other: object) -> bool:
return str(self) == str(other)


class Cases(list[Case]):
Expand Down
7 changes: 3 additions & 4 deletions src/farn/sampling/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def _generate_values_using_sobol_sampling(self) -> ndarray[tuple[int,], np.dtype
sobol_engine: Sobol = Sobol(
d=self.number_of_fields,
scramble=False,
seed=None,
rng=None,
)

if self.onset > 0:
Expand Down Expand Up @@ -601,9 +601,8 @@ def _generate_case_names(
self,
samples: dict[str, list[Any]],
) -> None:
self.case_names = [
f'{self.layer_name}_{format(i, "0%i" % self.leading_zeros)}' for i in range(self.number_of_samples)
]
_format_specifier: str = f"0{self.leading_zeros}d"
self.case_names = [f"{self.layer_name}_{format(i, _format_specifier)}" for i in range(self.number_of_samples)]
samples["_case_name"] = self.case_names

def _check_length_matches_number_of_names(
Expand Down
Loading