From 8f1b3c4cd966f287cd1f843d1a09bdfdbfe12fc3 Mon Sep 17 00:00:00 2001 From: Tien Tong Date: Fri, 17 Jan 2025 13:08:32 -0500 Subject: [PATCH] fix lint issues --- cubids/config.py | 1 + cubids/cubids.py | 12 ++++++------ cubids/metadata_merge.py | 6 ++---- cubids/tests/test_apply.py | 12 ++++++------ cubids/tests/test_bond.py | 34 ++++++---------------------------- 5 files changed, 21 insertions(+), 44 deletions(-) diff --git a/cubids/config.py b/cubids/config.py index a863d4eab..6c9b67887 100644 --- a/cubids/config.py +++ b/cubids/config.py @@ -4,6 +4,7 @@ import importlib.resources import yaml + def load_config(config_file): """Load a YAML file containing a configuration for param groups. diff --git a/cubids/cubids.py b/cubids/cubids.py index 3329444ff..3dd554ef5 100644 --- a/cubids/cubids.py +++ b/cubids/cubids.py @@ -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() @@ -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 @@ -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 @@ -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", ... ) @@ -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}") diff --git a/cubids/metadata_merge.py b/cubids/metadata_merge.py index 0779db090..3dc02bbf0 100644 --- a/cubids/metadata_merge.py +++ b/cubids/metadata_merge.py @@ -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) @@ -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) diff --git a/cubids/tests/test_apply.py b/cubids/tests/test_apply.py index ebe67818b..a44ebf451 100644 --- a/cubids/tests/test_apply.py +++ b/cubids/tests/test_apply.py @@ -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", @@ -358,4 +358,4 @@ def test_cubids_apply_intendedfor( new_tsv_prefix=None, container=None, is_longitudinal=is_longitudinal, - ) \ No newline at end of file + ) diff --git a/cubids/tests/test_bond.py b/cubids/tests/test_bond.py index fdcde2eee..bc57593c0 100644 --- a/cubids/tests/test_bond.py +++ b/cubids/tests/test_bond.py @@ -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")) @@ -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],