]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
style(optuna): apply ruff format to best-params I/O
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 5 Aug 2026 11:46:54 +0000 (13:46 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 5 Aug 2026 11:46:54 +0000 (13:46 +0200)
Reflow the lock helper, save fchown block and legacy resolver wrapping
to satisfy ruff format at the default 88-column width, matching the rest
of both files (main was format-clean). Whitespace and redundant grouping
parentheses only; the AST is unchanged.

ReforceXY/user_data/freqaimodels/ReforceXY.py
quickadapter/user_data/strategies/Utils.py

index d8d74425ccf0f6e4e20c84513fa937b6ed28b951..4d52aeb36f41a19ffe765ffcf20ab686db52821b 100644 (file)
@@ -1769,16 +1769,17 @@ class ReforceXY(BaseReinforcementLearningModel):
     def _locked_best_trial_params(
         best_trial_params_path: Path, *, exclusive: bool
     ) -> Iterator[None]:
-        lock_path = (
-            best_trial_params_path.parent / ReforceXY._BEST_PARAMS_LOCK_FILENAME
-        )
+        lock_path = best_trial_params_path.parent / ReforceXY._BEST_PARAMS_LOCK_FILENAME
         # O_NONBLOCK so a pre-existing FIFO (unlike a symlink, not caught by
         # O_NOFOLLOW) cannot hang this open before the S_ISREG guard rejects it.
         # A shared reader omits O_CREAT: a read-only mount cannot create the lock,
         # and os.replace atomicity keeps a lock-free read consistent.
         open_flags = (
-            (os.O_RDWR | os.O_CREAT) if exclusive else os.O_RDONLY
-        ) | os.O_CLOEXEC | os.O_NOFOLLOW | os.O_NONBLOCK
+            ((os.O_RDWR | os.O_CREAT) if exclusive else os.O_RDONLY)
+            | os.O_CLOEXEC
+            | os.O_NOFOLLOW
+            | os.O_NONBLOCK
+        )
         try:
             lock_fd = os.open(lock_path, open_flags, 0o666)
         except FileNotFoundError:
@@ -1846,9 +1847,7 @@ class ReforceXY(BaseReinforcementLearningModel):
         )
         temporary_path: Optional[Path] = None
         try:
-            with self._locked_best_trial_params(
-                best_trial_params_path, exclusive=True
-            ):
+            with self._locked_best_trial_params(best_trial_params_path, exclusive=True):
                 self._reject_best_trial_params_symlink(best_trial_params_path)
                 try:
                     existing_metadata = best_trial_params_path.stat()
@@ -1879,10 +1878,12 @@ class ReforceXY(BaseReinforcementLearningModel):
                                 os.fchown(
                                     write_file.fileno(),
                                     existing_metadata.st_uid
-                                    if temporary_metadata.st_uid != existing_metadata.st_uid
+                                    if temporary_metadata.st_uid
+                                    != existing_metadata.st_uid
                                     else -1,
                                     existing_metadata.st_gid
-                                    if temporary_metadata.st_gid != existing_metadata.st_gid
+                                    if temporary_metadata.st_gid
+                                    != existing_metadata.st_gid
                                     else -1,
                                 )
                             except PermissionError as chown_error:
@@ -1952,9 +1953,7 @@ class ReforceXY(BaseReinforcementLearningModel):
             except (json.JSONDecodeError, UnicodeDecodeError):
                 malformed = True
         if malformed:
-            with self._locked_best_trial_params(
-                best_trial_params_path, exclusive=True
-            ):
+            with self._locked_best_trial_params(best_trial_params_path, exclusive=True):
                 self._reject_best_trial_params_symlink(best_trial_params_path)
                 if not best_trial_params_path.is_file():
                     return None
index 92061cbc74d6033d7011e25a6682dddbecf45d5f..97b339164454516bce212b986d336ed859c91bea 100644 (file)
@@ -5326,9 +5326,7 @@ def _resolve_legacy_optuna_best_params(
     ambiguous and must be ignored (with a warning).
     """
     base = pair.split("/")[0]
-    legacy_best_params_path = (
-        base_path / f"optuna-{namespace}-best-params-{base}.json"
-    )
+    legacy_best_params_path = base_path / f"optuna-{namespace}-best-params-{base}.json"
     if (
         legacy_best_params_path == best_params_path
         or legacy_best_params_path.is_symlink()
@@ -5493,9 +5491,7 @@ def _validate_optuna_label_best_params(
     return params
 
 
-def _optuna_quarantine_path(
-    path: Path, now: datetime, *, tag: str, limit: int
-) -> Path:
+def _optuna_quarantine_path(path: Path, now: datetime, *, tag: str, limit: int) -> Path:
     """Quarantine target path for a corrupt Optuna artefact.
 
     The tag and timestamp are appended after the complete filename
@@ -5561,8 +5557,11 @@ def _locked_optuna_best_params(
     # A shared reader omits O_CREAT: a read-only mount cannot create the lock,
     # and os.replace atomicity keeps a lock-free read consistent.
     open_flags = (
-        (os.O_RDWR | os.O_CREAT) if exclusive else os.O_RDONLY
-    ) | os.O_CLOEXEC | os.O_NOFOLLOW | os.O_NONBLOCK
+        ((os.O_RDWR | os.O_CREAT) if exclusive else os.O_RDONLY)
+        | os.O_CLOEXEC
+        | os.O_NOFOLLOW
+        | os.O_NONBLOCK
+    )
     try:
         lock_fd = os.open(lock_path, open_flags, 0o666)
     except FileNotFoundError: