Skip to content

Commit a97f43f

Browse files
Copilottsalo
andcommitted
Fix linter errors (ruff)
- Remove trailing whitespace from blank lines - Split long lines to comply with 99 character limit - Format code with ruff formatter for consistency Co-authored-by: tsalo <8228902+tsalo@users.noreply.github.com>
1 parent cf2ed44 commit a97f43f

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

xcp_d/ingression/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,25 @@ def write_scans_tsv(copy_dictionary, subject_dir_bids, subses_ents, out_dir=None
9090
scans_df = pd.DataFrame(list(scans_dict.items()), columns=['filename', 'source_file'])
9191
scans_tsv = os.path.join(subject_dir_bids, f'{subses_ents}_scans.tsv')
9292
scans_df.to_csv(scans_tsv, sep='\t', index=False)
93-
93+
9494
# Also copy the scans.tsv to sourcedata/bids_conversion if out_dir is provided
9595
if out_dir is not None:
9696
# Parse subses_ents to extract subject and optional session
9797
# Format can be: "sub-01" or "sub-01_ses-01"
9898
parts = subses_ents.split('_')
9999
sub_part = parts[0] # e.g., "sub-01"
100-
100+
101101
# Build the sourcedata path with subject/session structure
102102
if len(parts) > 1 and parts[1].startswith('ses-'):
103103
# Has session: bids_conversion/sub-01/ses-01/
104104
ses_part = parts[1] # e.g., "ses-01"
105-
sourcedata_dir = os.path.join(out_dir, 'sourcedata', 'bids_conversion', sub_part, ses_part)
105+
sourcedata_dir = os.path.join(
106+
out_dir, 'sourcedata', 'bids_conversion', sub_part, ses_part
107+
)
106108
else:
107109
# No session: bids_conversion/sub-01/
108110
sourcedata_dir = os.path.join(out_dir, 'sourcedata', 'bids_conversion', sub_part)
109-
111+
110112
os.makedirs(sourcedata_dir, exist_ok=True)
111113
sourcedata_scans_tsv = os.path.join(sourcedata_dir, f'{subses_ents}_scans.tsv')
112114
scans_df.to_csv(sourcedata_scans_tsv, sep='\t', index=False)

xcp_d/tests/test_ingression_utils.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,17 @@ def test_write_scans_tsv_with_out_dir(tmp_path):
409409
'/source/file2.nii.gz': [str(subject_dir / 'func' / 'sub-01_bold.nii.gz')],
410410
}
411411
ingress_utils.write_scans_tsv(copy_dict, str(subject_dir), 'sub-01', out_dir=str(out_dir))
412-
412+
413413
# Check that scans.tsv exists in subject directory
414414
subject_scans_tsv = subject_dir / 'sub-01_scans.tsv'
415415
assert subject_scans_tsv.exists()
416-
416+
417417
# Check that scans.tsv is also copied to sourcedata/bids_conversion/sub-01/
418-
sourcedata_scans_tsv = out_dir / 'sourcedata' / 'bids_conversion' / 'sub-01' / 'sub-01_scans.tsv'
418+
sourcedata_scans_tsv = (
419+
out_dir / 'sourcedata' / 'bids_conversion' / 'sub-01' / 'sub-01_scans.tsv'
420+
)
419421
assert sourcedata_scans_tsv.exists()
420-
422+
421423
# Verify both files have the same content
422424
df_subject = pd.read_csv(subject_scans_tsv, sep='\t')
423425
df_sourcedata = pd.read_csv(sourcedata_scans_tsv, sep='\t')
@@ -434,16 +436,25 @@ def test_write_scans_tsv_with_session(tmp_path):
434436
copy_dict = {
435437
'/source/bold.nii.gz': [str(subject_dir / 'func' / 'sub-01_ses-01_bold.nii.gz')],
436438
}
437-
ingress_utils.write_scans_tsv(copy_dict, str(subject_dir), 'sub-01_ses-01', out_dir=str(out_dir))
438-
439+
ingress_utils.write_scans_tsv(
440+
copy_dict, str(subject_dir), 'sub-01_ses-01', out_dir=str(out_dir)
441+
)
442+
439443
# Check both locations
440444
subject_scans_tsv = subject_dir / 'sub-01_ses-01_scans.tsv'
441445
assert subject_scans_tsv.exists()
442-
446+
443447
# Check sourcedata/bids_conversion/sub-01/ses-01/
444-
sourcedata_scans_tsv = out_dir / 'sourcedata' / 'bids_conversion' / 'sub-01' / 'ses-01' / 'sub-01_ses-01_scans.tsv'
448+
sourcedata_scans_tsv = (
449+
out_dir
450+
/ 'sourcedata'
451+
/ 'bids_conversion'
452+
/ 'sub-01'
453+
/ 'ses-01'
454+
/ 'sub-01_ses-01_scans.tsv'
455+
)
445456
assert sourcedata_scans_tsv.exists()
446-
457+
447458
df = pd.read_csv(sourcedata_scans_tsv, sep='\t')
448459
assert len(df) == 1
449460
assert 'sub-01_ses-01_bold.nii.gz' in df['filename'].values[0]

0 commit comments

Comments
 (0)