Skip to content

Commit 9cd64d5

Browse files
authored
Merge pull request #89 from smoia/int/ruff
Move to Ruff and insert more automation on updates
2 parents e99c705 + 36bcd70 commit 9cd64d5

23 files changed

+250
-230
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
labels:
8+
- "Internal"

.github/workflows/bot.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: bot
2+
concurrency:
3+
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
4+
cancel-in-progress: true
5+
on: # yamllint disable-line rule:truthy
6+
pull_request
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
auto-merge:
14+
runs-on: ubuntu-latest
15+
if: (github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.user.login == 'pre-commit-ci[bot]') && github.repository == 'physiopy/peakdet'
16+
steps:
17+
- name: Enable auto-merge for bot PRs
18+
run: gh pr merge --auto --squash "$PR_URL"
19+
env:
20+
PR_URL: ${{ github.event.pull_request.html_url }}
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1+
ci:
2+
autoupdate_schedule: quarterly
3+
14
# See https://pre-commit.com for more information
25
# See https://pre-commit.com/hooks.html for more hooks
36
repos:
47
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.6.0
8+
rev: v5.0.0
69
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
- id: check-added-large-files
11-
- id: check-case-conflict
12-
- id: check-merge-conflict
13-
- repo: https://github.com/psf/black
14-
rev: 24.8.0
15-
hooks:
16-
- id: black
17-
- repo: https://github.com/pycqa/isort
18-
rev: 5.13.2
19-
hooks:
20-
- id: isort
21-
- repo: https://github.com/pycqa/flake8
22-
rev: 7.1.1
23-
hooks:
24-
- id: flake8
25-
- repo: https://github.com/pycqa/pydocstyle
26-
rev: 6.3.0
27-
hooks:
28-
- id: pydocstyle
10+
- id: trailing-whitespace
11+
- id: end-of-file-fixer
12+
- id: check-yaml
13+
- id: check-added-large-files
14+
- id: check-case-conflict
15+
- id: check-merge-conflict
16+
2917
- repo: https://github.com/pre-commit/pygrep-hooks
3018
rev: v1.10.0
3119
hooks:
3220
- id: rst-backticks
3321
- id: rst-directive-colons
3422
- id: rst-inline-touching-normal
23+
3524
- repo: https://github.com/codespell-project/codespell
36-
rev: v2.3.0
25+
rev: v2.4.1
3726
hooks:
3827
- id: codespell
3928
args: ["-L", "trough,troughs"]
29+
30+
- repo: https://github.com/astral-sh/ruff-pre-commit
31+
rev: v0.12.2
32+
hooks:
33+
- id: ruff
34+
name: ruff linter
35+
args: [--fix]
36+
files: peakdet
37+
- id: ruff-format
38+
name: ruff formatter
39+
files: peakdet

peakdet/_version.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
8484
stderr=(subprocess.PIPE if hide_stderr else None),
8585
)
8686
break
87-
except EnvironmentError:
87+
except OSError:
8888
e = sys.exc_info()[1]
8989
if e.errno == errno.ENOENT:
9090
continue
@@ -97,8 +97,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
9797
print("unable to find command, tried %s" % (commands,))
9898
return None, None
9999
stdout = p.communicate()[0].strip()
100-
if sys.version_info[0] >= 3:
101-
stdout = stdout.decode()
100+
stdout = stdout.decode()
102101
if p.returncode != 0:
103102
if verbose:
104103
print("unable to run %s (error)" % dispcmd)
@@ -116,7 +115,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
116115
"""
117116
rootdirs = []
118117

119-
for i in range(3):
118+
for _i in range(3):
120119
dirname = os.path.basename(root)
121120
if dirname.startswith(parentdir_prefix):
122121
return {
@@ -147,7 +146,7 @@ def git_get_keywords(versionfile_abs):
147146
# _version.py.
148147
keywords = {}
149148
try:
150-
f = open(versionfile_abs, "r")
149+
f = open(versionfile_abs)
151150
for line in f.readlines():
152151
if line.strip().startswith("git_refnames ="):
153152
mo = re.search(r'=\s*"(.*)"', line)
@@ -162,7 +161,7 @@ def git_get_keywords(versionfile_abs):
162161
if mo:
163162
keywords["date"] = mo.group(1)
164163
f.close()
165-
except EnvironmentError:
164+
except OSError:
166165
pass
167166
return keywords
168167

@@ -524,7 +523,7 @@ def get_versions():
524523
# versionfile_source is the relative path from the top of the source
525524
# tree (where the .git directory might live) to this file. Invert
526525
# this to find the root from __file__.
527-
for i in cfg.versionfile_source.split("/"):
526+
for _i in cfg.versionfile_source.split("/"):
528527
root = os.path.dirname(root)
529528
except NameError:
530529
return {

peakdet/analytics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
Functions and classes for generating analytics on physiological data
43
"""

peakdet/cli/run.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# -*- coding: utf-8 -*-
1+
"""Parser and physio workflow."""
2+
23
import argparse
34
import datetime
45
import glob
@@ -40,7 +41,7 @@
4041

4142

4243
def get_parser():
43-
"""Parser for GUI and command-line arguments"""
44+
"""Parser for GUI and command-line arguments."""
4445
parser = argparse.ArgumentParser()
4546
parser.add_argument(
4647
"file_template",
@@ -53,7 +54,7 @@ def get_parser():
5354
)
5455

5556
inp_group = parser.add_argument_group(
56-
"Inputs", "Options to specify " "format of input files"
57+
"Inputs", "Options to specify format of input files"
5758
)
5859
inp_group.add_argument(
5960
"--modality",
@@ -83,7 +84,7 @@ def get_parser():
8384
)
8485

8586
out_group = parser.add_argument_group(
86-
"Outputs", "Options to specify " "format of output files"
87+
"Outputs", "Options to specify format of output files"
8788
)
8889
out_group.add_argument(
8990
"-o",
@@ -104,12 +105,12 @@ def get_parser():
104105
"-s",
105106
"--savehistory",
106107
action="store_true",
107-
help="Whether to save history of data processing " "for each file.",
108+
help="Whether to save history of data processing for each file.",
108109
)
109110

110111
edit_group = parser.add_argument_group(
111112
"Workflow arguments (optional!)",
112-
"Options to specify modifications " "to workflow",
113+
"Options to specify modifications to workflow",
113114
)
114115
edit_group.add_argument(
115116
"-n",
@@ -135,7 +136,10 @@ def get_parser():
135136
"--debug",
136137
dest="debug",
137138
action="store_true",
138-
help="Print additional debugging info and error diagnostics to log file. Default is False.",
139+
help=(
140+
"Print additional debugging info and error diagnostics to log file. "
141+
"Default is False."
142+
),
139143
default=False,
140144
)
141145
log_style_group_exclusive.add_argument(
@@ -162,12 +166,12 @@ def workflow(
162166
savehistory=True,
163167
noedit=False,
164168
thresh=0.2,
165-
measurements=ATTR_CONV.keys(),
169+
measurements=None,
166170
debug=False,
167171
quiet=False,
168172
):
169173
"""
170-
Basic workflow for physiological data
174+
Run basic workflow for physiological data.
171175
172176
Parameters
173177
----------
@@ -192,12 +196,15 @@ def workflow(
192196
Whether to disable interactive editing of physio data. Default: False
193197
thresh : [0, 1] float, optional
194198
Threshold for peak detection. Default: 0.2
195-
measurements : list, optional
199+
measurements : None or list, optional
196200
Which HRV-related measurements to save from data. See ``peakdet.HRV``
197-
for available measurements. Default: all available measurements.
201+
for available measurements.
202+
Default: None, that is all available measurements.
198203
verbose : bool, optional
199-
Whether to include verbose logs when catching exceptions that include diagnostics
204+
Whether to include verbose logs when catching exceptions that include diagnostic
200205
"""
206+
if measurements is None:
207+
measurements = ATTR_CONV.keys()
201208
outdir = os.path.dirname(output)
202209
logger.info(f"Current path is {outdir}")
203210

@@ -255,9 +262,9 @@ def workflow(
255262
)
256263

257264
# output file
258-
logger.info("OUTPUT FILE:\t\t{}".format(output))
265+
logger.info(f"OUTPUT FILE:\t\t{output}")
259266
# grab files from file template
260-
logger.info("FILE TEMPLATE:\t{}".format(file_template))
267+
logger.info(f"FILE TEMPLATE:\t{file_template}")
261268
files = glob.glob(file_template, recursive=True)
262269

263270
# convert measurements to peakdet.HRV attribute friendly names
@@ -277,7 +284,7 @@ def workflow(
277284
# check if output file exists -- if so, ensure headers will match
278285
head = "filename," + ",".join(measurements)
279286
if os.path.exists(output):
280-
with open(output, "r") as src:
287+
with open(output) as src:
281288
eheader = src.readlines()[0]
282289
# if existing output file does not have same measurements are those
283290
# requested on command line, warn and use existing measurements so
@@ -300,7 +307,7 @@ def workflow(
300307
# iterate through all files and do peak detection with manual editing
301308
for fname in files:
302309
fname = os.path.relpath(fname)
303-
logger.info("Currently processing {}".format(fname))
310+
logger.info(f"Currently processing {fname}")
304311

305312
# if we want to save history, this is the output name it would take
306313
outname = os.path.join(
@@ -343,10 +350,12 @@ def workflow(
343350

344351

345352
def main():
353+
"""Run main entrypoint."""
346354
logger.enable("")
347355
opts = get_parser().parse_args()
348356
workflow(**vars(opts))
349357

350358

351359
if __name__ == "__main__":
360+
"""Run main entrypoint."""
352361
main()

peakdet/editor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Functions and class for performing interactive editing of physiological data."""
32

43
import functools
@@ -63,7 +62,8 @@ def __init__(self, data):
6362
reject = functools.partial(self.on_edit, method="reject")
6463
insert = functools.partial(self.on_edit, method="insert")
6564

66-
# Check matplotlib version rectprops is deprecated with matplotlib 3.5.0 and then obsolete
65+
# Check matplotlib version rectprops is deprecated with matplotlib 3.5.0
66+
# and then obsolete
6767
if Version(matplotlib.__version__) >= Version("3.5.0"):
6868
property_name = "props"
6969
else:

peakdet/external.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
"""
3-
Functions for interacting with physiological data acquired by external packages
4-
"""
1+
"""Functions for interacting with physiological data acquired by external packages."""
52

63
import numpy as np
74
from loguru import logger
@@ -12,7 +9,7 @@
129
@utils.make_operation(exclude=[])
1310
def load_rtpeaks(fname, channel, fs):
1411
"""
15-
Loads data file as obtained from the ``rtpeaks`` Python module
12+
Load data file as obtained from the ``rtpeaks`` Python module.
1613
1714
Data file `fname` should have a single, comma-delimited header of format:
1815
@@ -37,18 +34,17 @@ def load_rtpeaks(fname, channel, fs):
3734
data : :class:`peakdet.Physio`
3835
Loaded physiological data
3936
"""
40-
4137
if fname.startswith("/"):
4238
logger.warning(
4339
"Provided file seems to be an absolute path. In order "
4440
"to ensure full reproducibility it is recommended that "
4541
"a relative path is provided."
4642
)
4743

48-
with open(fname, "r") as src:
44+
with open(fname) as src:
4945
header = src.readline().strip().split(",")
5046

51-
col = header.index("channel{}".format(channel))
47+
col = header.index(f"channel{channel}")
5248
data = np.loadtxt(fname, usecols=col, skiprows=1, delimiter=",")
5349
phys = physio.Physio(data, fs=fs)
5450

0 commit comments

Comments
 (0)