From 9842d4c7b707e9e9c98f7cad672cb0ef92535634 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:40:15 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- datashuttle/command_line_interface.py | 2 -- datashuttle/configs/canonical_configs.py | 1 - datashuttle/configs/load_configs.py | 2 -- datashuttle/datashuttle.py | 1 - datashuttle/utils/data_transfer.py | 6 ------ datashuttle/utils/decorators.py | 1 - datashuttle/utils/folders.py | 7 ------- datashuttle/utils/formatting.py | 4 ---- datashuttle/utils/rclone.py | 3 --- datashuttle/utils/ssh.py | 2 -- datashuttle/utils/utils.py | 2 -- tests/test_utils.py | 8 +------- tests/tests_integration/test_command_line_interface.py | 6 ------ tests/tests_integration/test_configs.py | 4 ---- tests/tests_integration/test_filesystem_transfer.py | 2 -- tests/tests_integration/test_formatting.py | 1 - tests/tests_integration/test_logging.py | 3 --- tests/tests_integration/test_make_folders.py | 1 - tests/tests_integration/test_ssh_file_transfer.py | 3 --- tests/tests_unit/test_unit.py | 1 - 20 files changed, 1 insertion(+), 59 deletions(-) diff --git a/datashuttle/command_line_interface.py b/datashuttle/command_line_interface.py index aab59b244..1adc85c31 100644 --- a/datashuttle/command_line_interface.py +++ b/datashuttle/command_line_interface.py @@ -412,7 +412,6 @@ def show_next_ses_number(project: DataShuttle, args: Any) -> None: def check_name_formatting(project: DataShuttle, args: Any) -> None: - kwargs = make_kwargs(args) run_command( @@ -427,7 +426,6 @@ def check_name_formatting(project: DataShuttle, args: Any) -> None: def supply_config_file(project: DataShuttle, args: Any) -> None: - kwargs = make_kwargs(args) run_command( diff --git a/datashuttle/configs/canonical_configs.py b/datashuttle/configs/canonical_configs.py index cc2c4f956..dd5e387ee 100644 --- a/datashuttle/configs/canonical_configs.py +++ b/datashuttle/configs/canonical_configs.py @@ -205,7 +205,6 @@ def check_config_types(config_dict: Configs) -> None: fail = False for key in config_dict.keys(): - expected_type = required_types[key] if get_origin(expected_type) is Literal: diff --git a/datashuttle/configs/load_configs.py b/datashuttle/configs/load_configs.py index 7c8373902..9b1ad53c7 100644 --- a/datashuttle/configs/load_configs.py +++ b/datashuttle/configs/load_configs.py @@ -50,7 +50,6 @@ def make_config_file_attempt_load( new_cfg.load_from_file() except BaseException: - new_cfg = None utils.log_and_raise_error( @@ -144,7 +143,6 @@ def handle_bool(key: str, value: ConfigValueTypes) -> ConfigValueTypes: here. This assumes bool are always passed as flags. """ if key in canonical_configs.get_flags(): - if value in ["None", "none", None]: value = False diff --git a/datashuttle/datashuttle.py b/datashuttle/datashuttle.py index b4f687e60..62378852e 100644 --- a/datashuttle/datashuttle.py +++ b/datashuttle/datashuttle.py @@ -75,7 +75,6 @@ class DataShuttle: """ def __init__(self, project_name: str, print_startup_message: bool = True): - if " " in project_name: utils.log_and_raise_error( "'project_name' must not include spaces." diff --git a/datashuttle/utils/data_transfer.py b/datashuttle/utils/data_transfer.py index 497dc1040..9fdc2d5d3 100644 --- a/datashuttle/utils/data_transfer.py +++ b/datashuttle/utils/data_transfer.py @@ -17,7 +17,6 @@ def __init__( dry_run: bool, log: bool, ): - self.cfg = cfg self.upload_or_download = upload_or_download self.local_or_central = ( @@ -34,7 +33,6 @@ def __init__( include_list = self.build_a_list_of_all_files_and_folders_to_transfer() if any(include_list): - output = rclone.transfer_data( cfg, upload_or_download, @@ -62,7 +60,6 @@ def build_a_list_of_all_files_and_folders_to_transfer(self) -> List[str]: extra_filenames: List[str] = [] for sub in processed_sub_names: - # subjects at top level folder --------------------------------------- if sub == "all_non_sub": @@ -82,7 +79,6 @@ def build_a_list_of_all_files_and_folders_to_transfer(self) -> List[str]: processed_ses_names = self.get_processed_names(self.ses_names, sub) for ses in processed_ses_names: - if ses == "all_non_ses": self.update_list_with_non_ses_sub_level_folders( extra_folder_names, extra_filenames, sub @@ -177,7 +173,6 @@ def update_list_with_non_ses_sub_level_folders( def update_list_with_non_dtype_ses_level_folders( self, extra_folder_names, extra_filenames, sub, ses ): - ( ses_level_folders, ses_level_filenames, @@ -228,7 +223,6 @@ def update_list_with_dtype_paths( level = "ses" if ses else "sub" for data_type_key, data_type_folder in data_type_items: # type: ignore - if data_type_folder.level == level: if ses: filepath = Path(sub) / ses / data_type_folder.name diff --git a/datashuttle/utils/decorators.py b/datashuttle/utils/decorators.py index a1b94cfff..ea0db1f20 100644 --- a/datashuttle/utils/decorators.py +++ b/datashuttle/utils/decorators.py @@ -35,7 +35,6 @@ def check_configs_set(func): @wraps(func) def wrapper(*args, **kwargs): - if args[0].cfg is None: log_and_raise_error( "Must set configs with make_config_file() " diff --git a/datashuttle/utils/folders.py b/datashuttle/utils/folders.py index fd0fe53ab..f3993a82d 100644 --- a/datashuttle/utils/folders.py +++ b/datashuttle/utils/folders.py @@ -52,7 +52,6 @@ def make_folder_trees( formatting.check_data_type_is_valid(cfg, data_type, error_on_fail=True) for sub in sub_names: - sub_path = cfg.make_path( "local", sub, @@ -64,7 +63,6 @@ def make_folder_trees( make_data_type_folders(cfg, data_type, sub_path, "sub") for ses in ses_names: - ses_path = cfg.make_path( "local", [sub, ses], @@ -108,7 +106,6 @@ def make_data_type_folders( data_type_items = cfg.get_data_type_items(data_type) for data_type_key, data_type_folder in data_type_items: # type: ignore - if data_type_folder.used and data_type_folder.level == level: data_type_path = sub_or_ses_level_path / data_type_folder.name @@ -137,7 +134,6 @@ def make_folders(paths: Union[Path, List[Path]], log: bool = True) -> None: paths = [paths] for path_ in paths: - if not path_.is_dir(): path_.mkdir(parents=True) if log: @@ -223,7 +219,6 @@ def check_no_duplicate_sub_ses_key_values( "ses", return_as_int=True, ): - if new_ses in existing_ses_values: utils.log_and_raise_error( f"Cannot make folders. " @@ -446,14 +441,12 @@ def search_for_folders( # TODO: change name search_prefix : file / folder name to search (e.g. "sub-*") """ if local_or_central == "central" and cfg["connection_method"] == "ssh": - all_folder_names, all_filenames = ssh.search_ssh_central_for_folders( search_path, search_prefix, cfg, ) else: - if not search_path.exists(): utils.log_and_message(f"No file found at {search_path.as_posix()}") return [], [] diff --git a/datashuttle/utils/formatting.py b/datashuttle/utils/formatting.py index c9fce8669..8c32ac481 100644 --- a/datashuttle/utils/formatting.py +++ b/datashuttle/utils/formatting.py @@ -112,9 +112,7 @@ def update_names_with_range_to_flag( new_names = [] for i, name in enumerate(names): - if tags("to") in name: - check_name_is_formatted_correctly(name, prefix) prefix_tag = re.search(f"{prefix}-[0-9]+{tags('to')}[0-9]+", name)[0] # type: ignore @@ -224,7 +222,6 @@ def update_names_with_datetime(names: List[str]) -> None: format_time = f"time-{time_}" for i, name in enumerate(names): - if tags("datetime") in name: # must come first name = add_underscore_before_after_if_not_there( name, tags("datetime") @@ -320,7 +317,6 @@ def check_data_type_is_valid( def check_dashes_and_underscore_alternate_correctly(all_names): """ """ for name in all_names: - if name in RESERVED_KEYWORDS: continue diff --git a/datashuttle/utils/rclone.py b/datashuttle/utils/rclone.py index 74a66b0ef..3c53bc34d 100644 --- a/datashuttle/utils/rclone.py +++ b/datashuttle/utils/rclone.py @@ -64,7 +64,6 @@ def setup_central_as_rclone_target( call_rclone(f"config create {rclone_config_name} local", pipe_std=True) elif connection_method == "ssh": - call_rclone( f"config create " f"{rclone_config_name} " @@ -124,7 +123,6 @@ def transfer_data( ) # TODO: fix this is not a list if upload_or_download == "upload": - output = call_rclone( f"{rclone_args('copy')} " f'"{local_filepath}" "{cfg.get_rclone_config_name()}:{central_filepath}" {extra_arguments}', @@ -132,7 +130,6 @@ def transfer_data( ) elif upload_or_download == "download": - output = call_rclone( f"{rclone_args('copy')} " f'"{cfg.get_rclone_config_name()}:{central_filepath}" "{local_filepath}" {extra_arguments}', diff --git a/datashuttle/utils/ssh.py b/datashuttle/utils/ssh.py index 76022a636..06f2ab253 100644 --- a/datashuttle/utils/ssh.py +++ b/datashuttle/utils/ssh.py @@ -113,7 +113,6 @@ def add_public_key_to_central_authorized_keys( """ client: paramiko.SSHClient with paramiko.SSHClient() as client: - connect_client(client, cfg, password=password) client.exec_command("mkdir -p ~/.ssh/") @@ -227,7 +226,6 @@ def get_list_of_folder_names_over_sftp( all_filenames = [] try: for file_or_folder in sftp.listdir_attr(search_path.as_posix()): - if fnmatch.fnmatch(file_or_folder.filename, search_prefix): if stat.S_ISDIR(file_or_folder.st_mode): all_folder_names.append(file_or_folder.filename) diff --git a/datashuttle/utils/utils.py b/datashuttle/utils/utils.py index e35021ea8..ed51111b4 100644 --- a/datashuttle/utils/utils.py +++ b/datashuttle/utils/utils.py @@ -158,7 +158,6 @@ def get_values_from_bids_formatted_name( """ all_values = [] for name in all_names: - if key not in name: raise_error(f"The key {key} is not found in {name}") @@ -209,7 +208,6 @@ def unpack_nested_list(main_list): def integers_are_consecutive(list_of_ints: List[int]) -> bool: - diff_between_ints = diff(list_of_ints) return all([diff == 1 for diff in diff_between_ints]) diff --git a/tests/test_utils.py b/tests/test_utils.py index ff5b5298a..db3382b37 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -284,17 +284,14 @@ def check_folder_tree_is_correct( as this doesn't explicitly test this. """ for sub in subs: - path_to_sub_folder = join(base_folder, sub) check_and_cd_folder(path_to_sub_folder) for ses in sessions: - path_to_ses_folder = join(base_folder, sub, ses) check_and_cd_folder(path_to_ses_folder) for key, folder in project.cfg.data_type_folders.items(): - assert key in folder_used.keys(), ( "Key not found in folder_used. " "Update folder used and hard-coded tests: " @@ -304,7 +301,6 @@ def check_folder_tree_is_correct( if check_folder_is_used( base_folder, folder, folder_used, key, sub, ses ): - if folder.level == "sub": data_type_path = join(path_to_sub_folder, folder.name) elif folder.level == "ses": @@ -369,7 +365,6 @@ def check_data_type_sub_ses_uploaded_correctly( # Check ses are all uploaded + histology if transferred if ses_to_upload: - for sub in subs_to_upload: ses_names = glob_basenames( join( @@ -477,7 +472,6 @@ def check_project_configs( Paths are stored as pathlib in the cfg but str in the .yaml """ for arg_name, value in kwargs[0].items(): - if arg_name in project.cfg.keys_str_on_file_but_path_in_class: assert type(project.cfg[arg_name]) in [ pathlib.PosixPath, @@ -502,6 +496,7 @@ def check_config_file(config_path, *kwargs): # Test Helpers # ----------------------------------------------------------------------------- + # TODO: rename this 'top level folder path' def get_top_level_folder_path( project, local_or_central="local", folder_name="rawdata" @@ -534,7 +529,6 @@ def handle_upload_or_download( local machine to central, but using the download function). """ if upload_or_download == "download": - central_path = swap_local_and_central_paths( project, swap_last_folder_only ) diff --git a/tests/tests_integration/test_command_line_interface.py b/tests/tests_integration/test_command_line_interface.py index 665b68b00..2b9fecd4a 100644 --- a/tests/tests_integration/test_command_line_interface.py +++ b/tests/tests_integration/test_command_line_interface.py @@ -172,7 +172,6 @@ def test_make_config_file_non_default_variables(self, tmp_path): @pytest.mark.parametrize("sep", ["-", "_"]) def test_make_sub_folders_variable(self, sep): - stdout, _ = test_utils.run_cli( f" make{sep}sub{sep}folders " f"--data_type all " @@ -335,7 +334,6 @@ def test_update_config(self, clean_project_name, sep, tmp_path): test_utils.move_some_keys_to_end_of_dict(not_set_configs) for key, value in not_set_configs.items(): - format_value = ( test_utils.add_quotes(value) if "path" in key else value ) @@ -624,9 +622,7 @@ def convert_kwargs_to_cli(self, kwargs, sep="-"): kwargs_list = [] for key, value in kwargs.items(): - if key not in positionals: - if "path" in key: value = test_utils.add_quotes(value) else: @@ -646,13 +642,11 @@ def convert_kwargs_to_cli(self, kwargs, sep="-"): return prepend_positionals + kwargs_list def check_kwargs(self, required_options, kwargs_): - for key in required_options.keys(): assert kwargs_.pop(key) == required_options[key] assert kwargs_ == {} def check_upload_download_args(self, args_, kwargs_, dry_run_is): - assert kwargs_["data_type"] == ["all"] assert kwargs_["sub_names"] == ["one"] assert kwargs_["ses_names"] == ["two"] diff --git a/tests/tests_integration/test_configs.py b/tests/tests_integration/test_configs.py index c9d245cdd..2ce351280 100644 --- a/tests/tests_integration/test_configs.py +++ b/tests/tests_integration/test_configs.py @@ -213,7 +213,6 @@ def test_update_config(self, project, tmp_path): # ------------------------------------------------------------- def test_supplied_config_file_bad_path(self, setup_project): - # Test path supplied that doesn't exist non_existant_path = setup_project._datashuttle_path / "fake.file" @@ -248,7 +247,6 @@ def test_supplied_config_file_missing_key(self, setup_project, tmp_path): test_utils.dump_config(missing_key_configs, bad_configs_path) with pytest.raises(BaseException) as e: - setup_project.supply_config_file(bad_configs_path, warn=False) assert ( @@ -281,7 +279,6 @@ def test_supplied_config_file_bad_types(self, setup_project, tmp_path): bad_configs_path = setup_project._datashuttle_path / "bad_config.yaml" for key in setup_project.cfg.keys(): - if key in setup_project.cfg.keys_str_on_file_but_path_in_class: continue @@ -320,7 +317,6 @@ def test_supplied_config_file_bad_types(self, setup_project, tmp_path): def test_supplied_config_file_changes_wrong_order( self, setup_project, tmp_path ): - bad_order_configs_path = ( setup_project._datashuttle_path / "new_configs.yaml" ) diff --git a/tests/tests_integration/test_filesystem_transfer.py b/tests/tests_integration/test_filesystem_transfer.py index d6e684f2b..d13d04fc0 100644 --- a/tests/tests_integration/test_filesystem_transfer.py +++ b/tests/tests_integration/test_filesystem_transfer.py @@ -313,9 +313,7 @@ def test_transfer_with_keyword_parameters( project.cfg["local_path"], project.cfg["central_path"], ]: - for sub in ["sub-001", "sub-02", "sub-03"]: - sessions_in_path = test_utils.glob_basenames( (base_local / "rawdata" / sub / "ses*").as_posix() ) diff --git a/tests/tests_integration/test_formatting.py b/tests/tests_integration/test_formatting.py index ccb08cc62..3a340aed3 100644 --- a/tests/tests_integration/test_formatting.py +++ b/tests/tests_integration/test_formatting.py @@ -97,7 +97,6 @@ def test_format_names_prefix(self): ] def test_warning_non_consecutive_numbers(self, project): - project.make_sub_folders( ["sub-01", "sub-2", "sub-04"], ["ses-05", "ses-10"] ) diff --git a/tests/tests_integration/test_logging.py b/tests/tests_integration/test_logging.py index eb142e88b..61532823a 100644 --- a/tests/tests_integration/test_logging.py +++ b/tests/tests_integration/test_logging.py @@ -62,7 +62,6 @@ def setup_project(self, tmp_path): # ---------------------------------------------------------------------------------------------------------- def read_log_file(self, logging_path): - log_filepath = glob.glob(str(logging_path / "*.log")) assert len(log_filepath) == 1, ( @@ -102,7 +101,6 @@ def test_logs_make_config_file(self, clean_project_name, tmp_path): assert "Update successful. New config file:" in log def test_logs_update_config(self, setup_project): - setup_project.update_config("central_host_id", "test_id") log = self.read_log_file(setup_project.cfg.logging_path) @@ -137,7 +135,6 @@ def test_logs_supply_config(self, setup_project, tmp_path): ) def test_make_sub_folders(self, setup_project): - subs = ["sub-11", f"sub-002{tags('to')}004"] ses = ["ses-123", "ses-101"] diff --git a/tests/tests_integration/test_make_folders.py b/tests/tests_integration/test_make_folders.py index c0cd3ff29..e3c37a268 100644 --- a/tests/tests_integration/test_make_folders.py +++ b/tests/tests_integration/test_make_folders.py @@ -435,7 +435,6 @@ def test_get_next_ses_number(self, project): assert old_num == 5 def test_invalid_sub_and_ses_name(self, project): - with pytest.raises(BaseException) as e: project.make_sub_folders("sub_100") diff --git a/tests/tests_integration/test_ssh_file_transfer.py b/tests/tests_integration/test_ssh_file_transfer.py index 38b5f7314..11bf17de4 100644 --- a/tests/tests_integration/test_ssh_file_transfer.py +++ b/tests/tests_integration/test_ssh_file_transfer.py @@ -295,7 +295,6 @@ def make_pathtable_search_filter(self, sub_names, ses_names, data_type): extra_arguments = [] for sub in sub_names: - if sub == "all_non_sub": extra_arguments += ["is_non_sub == True"] else: @@ -305,13 +304,11 @@ def make_pathtable_search_filter(self, sub_names, ses_names, data_type): ] for ses in ses_names: - if ses == "all_non_ses": extra_arguments += [ f"(parent_sub == '{sub}' & is_non_ses == True)" ] else: - for dtype in data_type: if dtype == "all_ses_level_non_data_type": extra_arguments += [ diff --git a/tests/tests_unit/test_unit.py b/tests/tests_unit/test_unit.py index 735651812..25f5288e3 100644 --- a/tests/tests_unit/test_unit.py +++ b/tests/tests_unit/test_unit.py @@ -51,7 +51,6 @@ def test_datetime_string_replacement(self, key, underscore_position): ], ) def test_spaces_in_format_names(self, prefix_and_names): - prefix, names = prefix_and_names with pytest.raises(BaseException) as e: formatting.format_names(names, prefix)