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

Start applying ruff rules #269

Merged
merged 38 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f8eaf8c
Apply ruff/Pyflakes rule F401
DimitriPapadopoulos Jan 26, 2025
7dd16d9
Apply ruff/Pyflakes rule F841
DimitriPapadopoulos Jan 26, 2025
03f2380
Apply ruff/pycodestyle rule E402
DimitriPapadopoulos Jan 26, 2025
43d9609
Apply ruff/pycodestyle rule E701
DimitriPapadopoulos Jan 18, 2025
cff62cc
Apply ruff/pycodestyle ruke E713
DimitriPapadopoulos Jan 18, 2025
cf5594b
Apply ruff/pycodestyle rule E722
DimitriPapadopoulos Jan 18, 2025
0a0cf30
Apply ruff/pycodestyle rule E731
DimitriPapadopoulos Jan 18, 2025
52cb37c
Apply ruff/pycodestyle rule W293
DimitriPapadopoulos Jan 26, 2025
ecc9c7e
Apply ruff/pycodestyle rule W391
DimitriPapadopoulos Jan 26, 2025
511bd4a
Apply ruff/pyupgrade rule UP006
DimitriPapadopoulos Jan 26, 2025
c9de37f
Apply ruff/pyupgrade rule UP007
DimitriPapadopoulos Jan 18, 2025
0a12fec
Apply ruff/pyupgrade rule UP009
DimitriPapadopoulos Jan 18, 2025
356ffcf
Apply ruff/pyupgrade rule UP012
DimitriPapadopoulos Jan 18, 2025
c53f9bc
Apply ruff/pyupgrade rule UP020
DimitriPapadopoulos Jan 18, 2025
517c1f3
Apply ruff/pyupgrade rule UP025
DimitriPapadopoulos Jan 18, 2025
f7f867b
Apply ruff/pyupgrade rule B007
DimitriPapadopoulos Jan 18, 2025
dcdfb52
Apply ruff/pyupgrade rule B018
DimitriPapadopoulos Jan 18, 2025
31a3e2f
Apply ruff/flake8-comprehensions rule C405
DimitriPapadopoulos Jan 18, 2025
d3ca87b
Apply ruff/flake8-comprehensions rule C408
DimitriPapadopoulos Jan 18, 2025
afcc9ab
Apply ruff/flake8-comprehensions rule C419
DimitriPapadopoulos Jan 18, 2025
4110339
Apply ruff/flake8-implicit-str-concat rule ISC001
DimitriPapadopoulos Jan 18, 2025
03ebafa
Apply ruff/flake8-implicit-str-concat rule ISC002
DimitriPapadopoulos Jan 26, 2025
5e3feee
Apply ruff/flake8-implicit-str-concat rule ISC003
DimitriPapadopoulos Jan 18, 2025
e66455a
Apply ruff/flake8-simplify rule SIM102
DimitriPapadopoulos Jan 18, 2025
560a231
Apply ruff/flake8-simplify rule SIM201
DimitriPapadopoulos Jan 18, 2025
fead287
Apply ruff/flynt rule FLY002
DimitriPapadopoulos Jan 18, 2025
3d3a19c
Apply ruff/Perflint rule PERF401
DimitriPapadopoulos Jan 18, 2025
dcb02c5
Apply ruff/refurb rule FURB110
DimitriPapadopoulos Jan 26, 2025
123ed2c
Apply ruff/refurb rule FURB113
DimitriPapadopoulos Jan 26, 2025
09803e5
Apply ruff/refub rule FURB167
DimitriPapadopoulos Jan 26, 2025
3232c59
Apply ruff/refurb rule FURB171
DimitriPapadopoulos Jan 26, 2025
6bcdb1c
Apply ruff/refurb rule FURB188
DimitriPapadopoulos Jan 18, 2025
d046048
Apply ruff rule RUF022
DimitriPapadopoulos Jan 26, 2025
5748b28
Apply ruff rule RUF027
DimitriPapadopoulos Jan 26, 2025
b41859a
Apply ruff rule RUF036
DimitriPapadopoulos Jan 26, 2025
f74d13c
Apply ruff rule RUF039
DimitriPapadopoulos Jan 26, 2025
75a979c
Start enforcing ruff rules
DimitriPapadopoulos Jan 26, 2025
594972b
Update CI
DimitriPapadopoulos Jan 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
OS: ${{ matrix.os }}
PYTHON: '3.9'
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@master
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Generate coverage report
Expand All @@ -23,7 +23,7 @@ jobs:
pip install -r requirements-test.txt
pytest --cov=./pyedflib/ --cov-report=xml --cov-config=.coveragerc
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
directory: .
env_vars: OS,PYTHON
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint
on:
pull_request:
branches:
- '*'
permissions:
contents: read
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
- name: Lint with Ruff
run: ruff check --output-format=github
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install packages
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Install deps
Expand All @@ -45,7 +45,7 @@ jobs:
- uses: actions/checkout@v4

# Used to host cibuildwheel
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Install cibuildwheel
Expand Down
2 changes: 0 additions & 2 deletions demo/readEDFFile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

import os

import numpy as np

import pyedflib
Expand Down
2 changes: 0 additions & 2 deletions demo/streamingEDFFile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

import time

import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
Expand Down
6 changes: 2 additions & 4 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import datetime
import re

import jinja2.filters
import numpy as np

import pyedflib

# FIXME: doctests need the str/repr formatting used in Numpy < 1.14.
try:
np.set_printoptions(legacy='1.13')
Expand Down Expand Up @@ -63,8 +63,6 @@
# built documents.
#
# The short X.Y version.
import pyedflib

version = re.sub(r'\.dev0+.*$', r'.dev', pyedflib.__version__)
release = pyedflib.__version__

Expand Down
2 changes: 0 additions & 2 deletions pyedflib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# flake8: noqa

# Copyright (c) 2019 - 2020 Simon Kern
# Copyright (c) 2015 - 2020 Holger Nahrstaedt
# Copyright (c) 2016-2017 The pyedflib Developers
Expand Down
104 changes: 71 additions & 33 deletions pyedflib/_extensions/_pyedflib.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
from typing import List, Dict, Union, Optional
import numpy as np
from datetime import datetime

__all__ = ['lib_version', 'CyEdfReader', 'set_patientcode', 'set_starttime_subsecond',
'write_annotation_latin1', 'write_annotation_utf8', 'set_technician', 'EdfAnnotation',
'get_annotation', 'read_int_samples', 'blockwrite_digital_samples', 'blockwrite_physical_samples',
'set_recording_additional', 'write_physical_samples', 'set_patientname', 'set_physical_minimum',
'read_physical_samples', 'close_file', 'set_physical_maximum', 'open_file_writeonly',
'set_patient_additional', 'set_digital_maximum', 'set_birthdate', 'set_digital_minimum',
'write_digital_samples', 'set_equipment', 'set_samples_per_record', 'set_admincode', 'set_label',
'tell', 'rewind', 'set_sex', 'set_gender', 'set_physical_dimension', 'set_transducer',
'set_prefilter', 'seek', 'set_startdatetime', 'set_datarecord_duration',
'set_number_of_annotation_signals', 'open_errors', 'FILETYPE_EDFPLUS',
'FILETYPE_EDF', 'FILETYPE_BDF', 'FILETYPE_BDFPLUS', 'write_errors', 'get_number_of_open_files',
'get_handle', 'is_file_used', 'blockwrite_digital_short_samples', 'write_digital_short_samples']
__all__ = [
'FILETYPE_BDF',
'FILETYPE_BDFPLUS',
'FILETYPE_EDF',
'FILETYPE_EDFPLUS',
'CyEdfReader',
'EdfAnnotation',
'blockwrite_digital_samples',
'blockwrite_digital_short_samples',
'blockwrite_physical_samples',
'close_file',
'get_annotation',
'get_handle',
'get_number_of_open_files',
'is_file_used',
'lib_version',
'open_errors',
'open_file_writeonly',
'read_int_samples',
'read_physical_samples',
'rewind',
'seek',
'set_admincode',
'set_birthdate',
'set_datarecord_duration',
'set_digital_maximum',
'set_digital_minimum',
'set_equipment',
'set_gender',
'set_label',
'set_number_of_annotation_signals',
'set_patient_additional',
'set_patientcode',
'set_patientname',
'set_physical_dimension',
'set_physical_maximum',
'set_physical_minimum',
'set_prefilter',
'set_recording_additional',
'set_samples_per_record',
'set_sex',
'set_startdatetime',
'set_starttime_subsecond',
'set_technician',
'set_transducer',
'tell',
'write_annotation_latin1',
'write_annotation_utf8',
'write_digital_samples',
'write_digital_short_samples',
'write_errors',
'write_physical_samples',
]

open_errors: Dict[int, str]
write_errors: Dict[int, str]
open_errors: dict[int, str]
write_errors: dict[int, str]

FILETYPE_EDF: int
FILETYPE_EDFPLUS: int
Expand All @@ -35,7 +74,7 @@ class CyEdfReader:
def check_open_ok(self, result: int) -> bool: ...
def make_buffer(self) -> np.ndarray: ...
def open(self, file_name: str, annotations_mode: int = ..., check_file_size: int = ...) -> bool: ...
def read_annotation(self) -> List[List[str]]: ...
def read_annotation(self) -> list[list[str]]: ...
def _close(self) -> None: ...
def read_digital_signal(self, signalnum: int, start: int, n: int, sigbuf: np.ndarray[np.int32_t]) -> None: ...
def readsignal(self, signalnum: int, start: int, n: int, sigbuf: np.ndarray[np.float64_t]) -> None: ...
Expand Down Expand Up @@ -118,19 +157,19 @@ class EdfAnnotation:
duration: int
annotation: str

def set_patientcode(handle: int, patientcode: Union[str, bytes]) -> int: ...
def write_annotation_latin1(handle: int, onset: int, duration: int, description: Union[str, bytes]) -> int: ...
def write_annotation_utf8(handle: int, onset: int, duration: int, description: Union[str, bytes]) -> int: ...
def set_technician(handle: int, technician: Union[str, bytes]) -> int: ...
def set_patientcode(handle: int, patientcode: str | bytes) -> int: ...
def write_annotation_latin1(handle: int, onset: int, duration: int, description: str | bytes) -> int: ...
def write_annotation_utf8(handle: int, onset: int, duration: int, description: str | bytes) -> int: ...
def set_technician(handle: int, technician: str | bytes) -> int: ...
def get_annotation(handle: int, n: int, edf_annotation: EdfAnnotation) -> int: ...
def read_int_samples(handle: int, edfsignal: int, n: int, buf: np.ndarray[np.int32_t]) -> int: ...
def blockwrite_digital_samples(handle: int, buf: np.ndarray[np.int32_t]) -> int: ...
def blockwrite_digital_short_samples(handle: int, buf: np.ndarray[np.int16_t]) -> int: ...
def blockwrite_physical_samples(handle: int, buf: np.ndarray[np.float64_t]) -> int: ...
def set_recording_additional(handle: int, recording_additional: Union[str, bytes]) -> int: ...
def set_recording_additional(handle: int, recording_additional: str | bytes) -> int: ...
def write_digital_short_samples(handle: int, buf: np.ndarray[np.int16_t]) -> int: ...
def write_physical_samples(handle: int, buf: np.ndarray[np.float64_t]) -> int: ...
def set_patientname(handle: int, name: Union[str,bytes]) -> int: ...
def set_patientname(handle: int, name: str | bytes) -> int: ...
def set_physical_minimum(handle: int, edfsignal: int, phys_min: float) -> int: ...
def read_physical_samples(handle: int, edfsignal: int, n: int, buf: np.ndarray[np.float64_t]) -> int: ...
def close_file(handle: int) -> int: ...
Expand All @@ -139,26 +178,25 @@ def get_handle(file_number: int) -> int: ...
def is_file_used(path: str) -> bool: ...
def set_physical_maximum(handle: int, edfsignal: int, phys_max: float) -> int: ...
def open_file_writeonly(path: str, filetype: int, number_of_signals: int) -> int: ...
def set_patient_additional(handle: int, patient_additional: Union[str, bytes]) -> int: ...
def set_patient_additional(handle: int, patient_additional: str | bytes) -> int: ...
def set_digital_maximum(handle: int, edfsignal: int, dig_max: int) -> int: ...
def set_birthdate(handle: int, birthdate_year: int, birthdate_month: int, birthdate_day: int) -> int: ...
def set_digital_minimum(handle: int, edfsignal: int, dig_min: int) -> int: ...
def write_digital_samples(handle: int, buf: np.ndarray[np.int32_t]) -> int: ...
def set_equipment(handle: int, equipment: Union[str, bytes]) -> int: ...
def set_equipment(handle: int, equipment: str | bytes) -> int: ...
def set_samples_per_record(handle: int, edfsignal: int, smp_per_record: int) -> int: ...
def set_admincode(handle: int, admincode: Union[str, bytes]) -> int: ...
def set_label(handle: int, edfsignal: int, label: Union[str, bytes]) -> int: ...
def set_admincode(handle: int, admincode: str | bytes) -> int: ...
def set_label(handle: int, edfsignal: int, label: str | bytes) -> int: ...
def tell(handle: int, edfsignal: int) -> int: ...
def rewind(handle: int, edfsignal: int) -> None: ...
def set_sex(handle: int, sex: Optional[int]) -> int: ...
def set_sex(handle: int, sex: int | None) -> int: ...
def set_gender(handle: int, gender: int) -> int: ...
def set_physical_dimension(handle: int, edfsignal: int, phys_dim: Union[str, bytes]) -> int: ...
def set_transducer(handle: int, edfsignal: int, transducer: Union[str, bytes]) -> int: ...
def set_prefilter(handle: int, edfsignal: int, prefilter: Union[str, bytes]) -> int: ...
def set_physical_dimension(handle: int, edfsignal: int, phys_dim: str | bytes) -> int: ...
def set_transducer(handle: int, edfsignal: int, transducer: str | bytes) -> int: ...
def set_prefilter(handle: int, edfsignal: int, prefilter: str | bytes) -> int: ...
def seek(handle: int, edfsignal: int, offset: int, whence: int) -> int: ...
def set_startdatetime(handle: int, startdate_year: int, startdate_month: int, startdate_day: int,
starttime_hour: int, starttime_minute: int, starttime_second: int) -> int: ...
def set_starttime_subsecond(handle: int, subsecond: int) -> int: ...
def set_datarecord_duration(handle: int, duration: Union[int, float]) -> int: ...
def set_datarecord_duration(handle: int, duration: int | float) -> int: ...
def set_number_of_annotation_signals(handle: int, annot_signals: int) -> int: ...

2 changes: 0 additions & 2 deletions pyedflib/data/_readers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

import numpy as np

import pyedflib


Expand Down
28 changes: 14 additions & 14 deletions pyedflib/edfreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from ._extensions._pyedflib import CyEdfReader

__all__ = [
"EdfReader",
"DO_NOT_READ_ANNOTATIONS",
"READ_ANNOTATIONS",
"READ_ALL_ANNOTATIONS",
"CHECK_FILE_SIZE",
"DO_NOT_CHECK_FILE_SIZE",
"DO_NOT_READ_ANNOTATIONS",
"READ_ALL_ANNOTATIONS",
"READ_ANNOTATIONS",
"REPAIR_FILE_SIZE_IF_WRONG",
"EdfReader",
]

DO_NOT_READ_ANNOTATIONS = 0
Expand Down Expand Up @@ -504,7 +504,7 @@ def getSampleFrequency(self, chn: int) -> float:
return self.samplefrequency(chn)
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -553,7 +553,7 @@ def getLabel(self, chn: int) -> str:
return self._convert_string(self.signal_label(chn).rstrip())
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand All @@ -580,7 +580,7 @@ def getPrefilter(self, chn: int) -> str:
return self._convert_string(self.prefilter(chn).rstrip())
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -608,7 +608,7 @@ def getPhysicalMaximum(self, chn: Optional[int] = None) -> Union[float, np.ndarr
return self.physical_max(chn)
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -641,7 +641,7 @@ def getPhysicalMinimum(self, chn: Optional[int] = None) -> Union[float, np.ndarr
return self.physical_min(chn)
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -674,7 +674,7 @@ def getDigitalMaximum(self, chn: Optional[int] = None) -> Union[int, np.ndarray]
return self.digital_max(chn)
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -707,7 +707,7 @@ def getDigitalMinimum(self, chn: Optional[int] = None) -> Union[int, np.ndarray]
return self.digital_min(chn)
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -739,7 +739,7 @@ def getTransducer(self, chn: int):
return self._convert_string(self.transducer(chn).rstrip())
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand All @@ -766,7 +766,7 @@ def getPhysicalDimension(self, chn: int) -> str:
return self._convert_string(self.physical_dimension(chn).rstrip())
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down Expand Up @@ -826,7 +826,7 @@ def readSignal(
return x
else:
raise IndexError(
"Trying to access channel {}, but only {} " "channels found".format(
"Trying to access channel {}, but only {} channels found".format(
chn, self.signals_in_file
)
)
Expand Down
Loading
Loading