Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 14, 2023
1 parent 0d97dcb commit 9842d4c
Show file tree
Hide file tree
Showing 20 changed files with 1 addition and 59 deletions.
2 changes: 0 additions & 2 deletions datashuttle/command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion datashuttle/configs/canonical_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions datashuttle/configs/load_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion datashuttle/datashuttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
6 changes: 0 additions & 6 deletions datashuttle/utils/data_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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,
Expand Down Expand Up @@ -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":
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion datashuttle/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() "
Expand Down
7 changes: 0 additions & 7 deletions datashuttle/utils/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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. "
Expand Down Expand Up @@ -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 [], []
Expand Down
4 changes: 0 additions & 4 deletions datashuttle/utils/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions datashuttle/utils/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} "
Expand Down Expand Up @@ -124,15 +123,13 @@ 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}',
pipe_std=True,
)

elif upload_or_download == "download":

output = call_rclone(
f"{rclone_args('copy')} "
f'"{cfg.get_rclone_config_name()}:{central_filepath}" "{local_filepath}" {extra_arguments}',
Expand Down
2 changes: 0 additions & 2 deletions datashuttle/utils/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions datashuttle/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -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])

Expand Down
8 changes: 1 addition & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand All @@ -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":
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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"
Expand Down Expand Up @@ -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
)
Expand Down
6 changes: 0 additions & 6 deletions tests/tests_integration/test_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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:
Expand All @@ -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"]
Expand Down
4 changes: 0 additions & 4 deletions tests/tests_integration/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
)
Expand Down
2 changes: 0 additions & 2 deletions tests/tests_integration/test_filesystem_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
1 change: 0 additions & 1 deletion tests/tests_integration/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Expand Down
Loading

0 comments on commit 9842d4c

Please sign in to comment.