Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tientong98 committed Jan 17, 2025
1 parent 64b2097 commit 8f1b3c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 44 deletions.
1 change: 1 addition & 0 deletions cubids/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import importlib.resources
import yaml


def load_config(config_file):
"""Load a YAML file containing a configuration for param groups.
Expand Down
12 changes: 6 additions & 6 deletions cubids/cubids.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
self.cubids_code_dir = Path(self.path + "/code/CuBIDS").is_dir()
self.data_dict = {} # data dictionary for TSV outputs
self.use_datalad = use_datalad # True if flag set, False if flag unset
self.is_longitudinal = is_longitudinal # True if flag set, False if flag unset
self.is_longitudinal = is_longitudinal # True if flag set, False if flag unset
if self.use_datalad:
self.init_datalad()

Expand Down Expand Up @@ -479,7 +479,7 @@ def change_filename(self, filepath, entities, is_longitudinal=False):
filepath=filepath,
entities=entities,
out_dir=str(self.path),
is_longitudinal=self.is_longitudinal
is_longitudinal=self.is_longitudinal,
)

exts = Path(filepath).suffixes
Expand Down Expand Up @@ -606,7 +606,7 @@ def change_filename(self, filepath, entities, is_longitudinal=False):
# Coerce IntendedFor to a list.
data["IntendedFor"] = listify(data["IntendedFor"])
for item in data["IntendedFor"]:
if item == _get_participant_relative_path(filepath):
if item == _get_participant_relative_path(filepath):
# remove old filename
data["IntendedFor"].remove(item)
# add new filename
Expand Down Expand Up @@ -1419,12 +1419,12 @@ def _get_participant_relative_path(scan):
... "/path/to/dset/sub-01/ses-01/func/sub-01_ses-01_bold.nii.gz",
... )
'ses-01/func/sub-01_ses-01_bold.nii.gz'
>>> _get_participant_relative_path(
... "/path/to/dset/sub-01/func/sub-01_bold.nii.gz",
... )
'func/sub-01_bold.nii.gz'
>>> _get_participant_relative_path(
... "/path/to/dset/ses-01/func/ses-01_bold.nii.gz",
... )
Expand All @@ -1435,7 +1435,7 @@ def _get_participant_relative_path(scan):
# Find the first part that starts with "sub-"
for i, part in enumerate(parts):
if part.startswith("sub-"):
return "/".join(parts[i+1:])
return "/".join(parts[i + 1 :])
raise ValueError(f"Could not find subject in {scan}")


Expand Down
6 changes: 2 additions & 4 deletions cubids/metadata_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def group_by_acquisition_sets(files_tsv, output_prefix, acq_group_level, is_long
if is_longitudinal:
acq_id = (file_entities.get("subject"), file_entities.get("session"))
elif not is_longitudinal:
acq_id = (file_entities.get("subject"))
acq_id = file_entities.get("subject")
acq_groups[acq_id].append((row.EntitySet, row.ParamGroup))
elif is_longitudinal and acq_group_level == "session":
acq_id = (file_entities.get("subject"), None)
Expand Down Expand Up @@ -339,9 +339,7 @@ def group_by_acquisition_sets(files_tsv, output_prefix, acq_group_level, is_long
)
elif not is_longitudinal:
for subject in contents_to_subjects[content_id]:
grouped_sub_sess.append(
{"subject": "sub-" + subject, "AcqGroup": groupnum}
)
grouped_sub_sess.append({"subject": "sub-" + subject, "AcqGroup": groupnum})

# Write the mapping of subject/session to
acq_group_df = pd.DataFrame(grouped_sub_sess)
Expand Down
12 changes: 6 additions & 6 deletions cubids/tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,28 @@ def summary_data():
@pytest.mark.parametrize(
("name", "skeleton", "intended_for", "is_longitudinal", "expected"),
[
( # doesn't have acq-VAR
( # doesn't have acq-VAR
"relpath_long",
relpath_intendedfor_long,
"ses-01/dwi/sub-01_ses-01_acq-VAR_dir-AP_run-01_dwi.nii.gz",
True,
"pass",
),
( # doesn't have ses-01
( # doesn't have ses-01
"bidsuri_long",
bidsuri_intendedfor_long,
"bids::sub-01/ses-01/dwi/sub-01_ses-01_acq-VAR_dir-AP_run-01_dwi.nii.gz",
True,
True,
"pass",
),
( # doesn't have acq-VAR
( # doesn't have acq-VAR
"relpath_cs",
relpath_intendedfor_cs,
"dwi/sub-01_acq-VAR_dir-AP_run-01_dwi.nii.gz",
False,
"pass",
),
( # pass
( # pass
"bidsuri_cs",
bidsuri_intendedfor_cs,
"bids::sub-01/dwi/sub-01_acq-VAR_dir-AP_run-01_dwi.nii.gz",
Expand Down Expand Up @@ -358,4 +358,4 @@ def test_cubids_apply_intendedfor(
new_tsv_prefix=None,
container=None,
is_longitudinal=is_longitudinal,
)
)
34 changes: 6 additions & 28 deletions cubids/tests/test_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,12 @@ def test_session_apply(tmp_path):

data_root = get_data(tmp_path)

ses_cubids = CuBIDS(data_root / "inconsistent", acq_group_level="session",
use_datalad=True, is_longitudinal=True)
ses_cubids = CuBIDS(
data_root / "inconsistent",
acq_group_level="session",
use_datalad=True,
is_longitudinal=True,
)

ses_cubids.get_tsvs(str(tmp_path / "originals"))

Expand Down Expand Up @@ -1194,32 +1198,6 @@ def test_bids_version(tmp_path):
), f"Schema version {schema_version} is less than minimum {min_schema_version}"


<<<<<<< HEAD
def test_docker():
"""Verify that docker is installed and the user has permission to run docker images.
Returns
-------
int
-1 if Docker can't be found.
0 if Docker is found, but the user can't connect to the daemon.
1 if the test run is OK.
"""
try:
return_status = 1
ret = subprocess.run(["docker", "version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError as e:
from errno import ENOENT

if e.errno == ENOENT:
print("Cannot find Docker engine!")
return_status = 0
raise e
if ret.stderr.startswith(b"Cannot connect to the Docker daemon."):
print("Cannot connect to Docker daemon!")
return_status = 0
assert return_status

# def test_image(image='pennlinc/bond:latest'):
# """Check whether image is present on local system."""
# ret = subprocess.run(['docker', 'images', '-q', image],
Expand Down

0 comments on commit 8f1b3c4

Please sign in to comment.