Skip to content

Commit 2157109

Browse files
committed
Move to ruff (issue #1014)
1 parent 5af9425 commit 2157109

File tree

10 files changed

+362
-345
lines changed

10 files changed

+362
-345
lines changed

.github/workflows/ibllib_ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ jobs:
3535
- name: Install deps
3636
run: |
3737
python -m pip install --upgrade pip
38-
python -m pip install flake8 pytest flake8-docstrings
38+
python -m pip install flake8 ruff flake8-docstrings
3939
pip install -r requirements.txt
4040
pip install -e .
41-
- name: Flake8
41+
- name: Flake8 & ruff
4242
run: |
43-
python -m flake8
43+
python -m ruff check .
4444
python -m flake8 --select D --ignore E ibllib/qc/camera.py ibllib/qc/task_metrics.py
4545
- name: Brainbox tests
4646
run: |

brainbox/metrics/single_units.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def unit_stability(units_b, units=None, feat_names=['amps'], dist='norm', test='
105105
"""
106106

107107
# Get units.
108-
if not (units is None): # we're using a subset of all units
108+
if units is not None: # we're using a subset of all units
109109
unit_list = list(units_b[feat_names[0]].keys())
110110
# for each `feat` and unit in `unit_list`, remove unit from `units_b` if not in `units`
111111
for feat in feat_names:
112-
[units_b[feat].pop(unit) for unit in unit_list if not (int(unit) in units)]
112+
[units_b[feat].pop(unit) for unit in unit_list if int(unit) not in units]
113113
unit_list = list(units_b[feat_names[0]].keys()) # get new `unit_list` after removing units
114114

115115
# Initialize `p_vals` and `variances`.

brainbox/plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def feat_vars(units_b, units=None, feat_name='amps', dist='norm', test='ks', cma
7777
'''
7878

7979
# Get units.
80-
if not (units is None): # we're using a subset of all units
80+
if units is not None: # we're using a subset of all units
8181
unit_list = list(units_b['depths'].keys())
8282
# For each unit in `unit_list`, remove unit from `units_b` if not in `units`.
83-
[units_b['depths'].pop(unit) for unit in unit_list if not (int(unit) in units)]
83+
[units_b['depths'].pop(unit) for unit in unit_list if int(unit) not in units]
8484
unit_list = list(units_b['depths'].keys()) # get new `unit_list` after removing unit
8585

8686
# Calculate coefficients of variation for all units

ibllib/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
"""Library implementing the International Brain Laboratory data pipeline."""
22
import logging
33
import warnings
4+
import os
45

56
__version__ = '3.4.1'
67
warnings.filterwarnings('always', category=DeprecationWarning, module='ibllib')
78

89
# if this becomes a full-blown library we should let the logging configuration to the discretion of the dev
910
# who uses the library. However since it can also be provided as an app, the end-users should be provided
1011
# with a useful default logging in standard output without messing with the complex python logging system
11-
USE_LOGGING = True
12-
#%(asctime)s,%(msecs)d
13-
if USE_LOGGING:
12+
if os.environ.get('IBLLIB_USE_LOGGING', '1').casefold() in ('1', 'true', 'yes'):
1413
from iblutil.util import setup_logger
1514
setup_logger(name='ibllib', level=logging.INFO)
16-
else:
17-
# deactivate all log calls for use as a library
18-
logging.getLogger('ibllib').addHandler(logging.NullHandler())

ibllib/io/extractors/camera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,13 @@ def groom_pin_state(gpio, ttl, ts, tolerance=2., display=False, take='first', mi
683683
_logger.warning('Some onsets but not offsets (or vice versa) were not assigned; '
684684
'this may be a sign of faulty wiring or clock drift')
685685
# Find indices of GPIO upticks where only the downtick was marked for removal
686-
orphaned_onsets, = np.where(~to_remove.reshape(-1, 2)[:, 0] & orphaned)
686+
orphaned_onsets, = np.where(~to_remove.reshape(-1, 2)[:, 0] & orphaned)
687687
# The onsets_ array already has the other TTLs removed (same size as to_remove ==
688688
# False) so subtract the number of removed elements from index.
689689
for i, v in enumerate(orphaned_onsets):
690690
orphaned_onsets[i] -= to_remove.reshape(-1, 2)[:v, 0].sum()
691691
# Same for offsets...
692-
orphaned_offsets, = np.where(~to_remove.reshape(-1, 2)[:, 1] & orphaned)
692+
orphaned_offsets, = np.where(~to_remove.reshape(-1, 2)[:, 1] & orphaned)
693693
for i, v in enumerate(orphaned_offsets):
694694
orphaned_offsets[i] -= to_remove.reshape(-1, 2)[:v, 1].sum()
695695
# Remove orphaned ttl onsets and offsets

0 commit comments

Comments
 (0)