From 98e3536e97ff0ca34fe8e24e75decb0d4699dc67 Mon Sep 17 00:00:00 2001 From: Nina Miolane Date: Wed, 27 Apr 2022 17:43:49 -0700 Subject: [PATCH] Address flake8 issues --- ioSPI/datasets.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ioSPI/datasets.py b/ioSPI/datasets.py index 78ced8b..edd502c 100644 --- a/ioSPI/datasets.py +++ b/ioSPI/datasets.py @@ -1,7 +1,6 @@ """Module to house methods related to datasets (micrographs, meta-data, etc.).""" import os - import typing from pathlib import Path @@ -9,8 +8,8 @@ class Project: - """Class to list and download dataset from a project on OSF.io - + """Class to list, download and upload data from OSF. + Parameters ---------- username : str @@ -22,35 +21,38 @@ class Project: project_id : str, default = "7g42j" Identifier of the project, found on the OSF project page. E.g. 7g42j for project at https://osf.io/7g42j/ - + See Also -------- OSF API documentation : https://developer.osf.io/ """ + def __init__(self, username: str, token: str, project_id: str = "7g42j") -> None: self.project_id = project_id - + config_path = os.path.join(".osfcli.config") - with open(config_path, 'w') as out_file: + with open(config_path, "w") as out_file: out_file.write("[osf]\n") out_file.write(f"username = {username}\n") out_file.write(f"project = {project_id}\n") out_file.write(f"token = {token}\n") print("OSF config written to .osfcli.config!") - + def ls(self): - "List all files for the project" + """List all files in the project.""" print(f"Listing files from OSF project: {self.project_id}...") os.system("osf ls") - + def download(self, remote_path, local_path): """Download file from osf and save it locally. - + Parameters ---------- remote_path : str Remote path of the file on OSF. - E.g. osfstorage/randomrot1D_nodisorder/4v6x_randomrot_copy6_defocus3.0_yes_noise.txt + E.g. osfstorage/ + randomrot1D_nodisorder/ + 4v6x_randomrot_copy6_defocus3.0_yes_noise.txt local_path : str Local path where the file will be saved. E.g. 4v6x_randomrot_copy6_defocus3.0_yes_noise.txt @@ -58,19 +60,21 @@ def download(self, remote_path, local_path): print(f"Downloading {remote_path} to {local_path}...") os.system(f"osf fetch {remote_path} {local_path}") print("Done!") - + def upload(self, remote_path, local_path): """Upload file to osf. - + Notes ----- You should have requested permission to upload to the project first. - + Parameters ---------- remote_path : str Remote path of the file on OSF. - E.g. osfstorage/randomrot1D_nodisorder/4v6x_randomrot_copy6_defocus3.0_yes_noise.txt + E.g. osfstorage/ + randomrot1D_nodisorder/ + 4v6x_randomrot_copy6_defocus3.0_yes_noise.txt local_path : str Local path where the file will be saved. E.g. 4v6x_randomrot_copy6_defocus3.0_yes_noise.txt