From: Jérôme Benoit Date: Wed, 5 Aug 2026 11:46:54 +0000 (+0200) Subject: style(optuna): apply ruff format to best-params I/O X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=81c74177558aaf1bcd7fbb06f1c068a9dfccc892;p=freqai-strategies.git style(optuna): apply ruff format to best-params I/O 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. --- diff --git a/ReforceXY/user_data/freqaimodels/ReforceXY.py b/ReforceXY/user_data/freqaimodels/ReforceXY.py index d8d7442..4d52aeb 100644 --- a/ReforceXY/user_data/freqaimodels/ReforceXY.py +++ b/ReforceXY/user_data/freqaimodels/ReforceXY.py @@ -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 diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 92061cb..97b3391 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -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: