diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a44948..288ceb1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,22 +4,22 @@ fail_fast: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/psf/black - rev: 24.8.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.1.0 hooks: - id: black args: [--line-length=128, --verbose] - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.3.0 hooks: - id: flake8 args: [--max-line-length=128, '--exclude=./.*,build,dist,official*,torch_ecg,references,*.ipynb', '--ignore=E501,W503,E203,F841,E402,E231,E731', --count, --statistics, --show-source] - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 7.0.0 hooks: - id: isort args: [--profile=black, --line-length=128] diff --git a/cfg.py b/cfg.py index 8ba0aa0..685bc25 100644 --- a/cfg.py +++ b/cfg.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import os from copy import deepcopy diff --git a/data_reader.py b/data_reader.py index 95c6216..7623d7e 100644 --- a/data_reader.py +++ b/data_reader.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -""" -""" +""" """ import json import logging diff --git a/dataset.py b/dataset.py index 649a640..8735dc3 100644 --- a/dataset.py +++ b/dataset.py @@ -1252,14 +1252,10 @@ def _train_test_split(self, train_ratio: float = 0.8, force_recompute: bool = Fa with open(test_file_1, "w") as f1, open(test_file_2, "w") as f2: json.dump(test_set, f1, ensure_ascii=False) json.dump(test_set, f2, ensure_ascii=False) - print( - nildent( - f""" + print(nildent(f""" train set saved to \n\042{train_file_1}\042and\n\042{train_file_2}\042 test set saved to \n\042{test_file_1}\042and\n\042{test_file_2}\042 - """ - ) - ) + """)) else: with open(train_file, "r") as f: train_set = json.load(f) diff --git a/gather_results.py b/gather_results.py index db4ee70..35f48a5 100644 --- a/gather_results.py +++ b/gather_results.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import glob import json diff --git a/sample_data/__init__.py b/sample_data/__init__.py index daf2131..7d0f61f 100644 --- a/sample_data/__init__.py +++ b/sample_data/__init__.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import glob import os diff --git a/test_entry.py b/test_entry.py index 02a6375..e0ea602 100644 --- a/test_entry.py +++ b/test_entry.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import glob import os diff --git a/trainer.py b/trainer.py index 38bf605..ccbb440 100644 --- a/trainer.py +++ b/trainer.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import argparse import logging @@ -149,8 +148,7 @@ def train( comment=f"OPT_{config.task}_{_model.__name__}{cnn_name}{rnn_name}{attn_name}_{config.train_optimizer}_LR_{lr}_BS_{batch_size}", ) - msg = textwrap.dedent( - f""" + msg = textwrap.dedent(f""" Starting training: ------------------ Task: {config.task} @@ -163,8 +161,7 @@ def train( Optimizer: {config.train_optimizer} Dataset classes: {train_dataset.all_classes} --------------------------------------------------- - """ - ) + """) if logger: logger.info(msg) @@ -347,15 +344,13 @@ def train( else: eval_train_msg = "" for k, v in eval_res.items(): - msg = textwrap.dedent( - f""" + msg = textwrap.dedent(f""" Train epoch_{epoch + 1}: -------------------- train/epoch_loss: {epoch_loss}{eval_train_msg} test/task_metric_{k}: {v} --------------------------------- - """ - ) + """) if logger: logger.info(msg) else: @@ -378,12 +373,10 @@ def train( print(msg) break - msg = textwrap.dedent( - f""" + msg = textwrap.dedent(f""" best metric = {best_metric}, obtained at epoch {best_epoch} - """ - ) + """) if logger: logger.info(msg) else: diff --git a/utils/__init__.py b/utils/__init__.py index cd7d3cb..2de9e21 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import os import sys diff --git a/utils/misc.py b/utils/misc.py index 9951486..b632a9b 100644 --- a/utils/misc.py +++ b/utils/misc.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import datetime import json diff --git a/utils/scoring_metrics_test.py b/utils/scoring_metrics_test.py index fd1b29d..16aee6e 100644 --- a/utils/scoring_metrics_test.py +++ b/utils/scoring_metrics_test.py @@ -1,5 +1,4 @@ -""" -""" +""" """ import argparse import glob @@ -165,14 +164,10 @@ def run_single_test(rec: str, classes: Optional[List[str]] = None, verbose: bool return print(f" {os.path.basename(rec)} starts ".center(30, "-")) - print( - textwrap.dedent( - f""" + print(textwrap.dedent(f""" record = {os.path.basename(rec)}, class = {header.comments[0]}, - """ - ) - ) + """)) custom_onset_scoring_mask, custom_offset_scoring_mask = gen_endpoint_score_mask( siglen=header.sig_len, diff --git a/utils/utils_interval.py b/utils/utils_interval.py index 83eb024..406b213 100644 --- a/utils/utils_interval.py +++ b/utils/utils_interval.py @@ -10,6 +10,7 @@ 2. distinguish openness and closedness """ + import time from copy import deepcopy from numbers import Real