use pathlib.Path for directories and files
This commit is contained in:
parent
110ddaf3a1
commit
8162758cec
13 changed files with 137 additions and 125 deletions
|
|
@ -4,9 +4,10 @@ import datalad.api as dl
|
|||
from typing import Optional
|
||||
import shutil
|
||||
from .tools import get_db_file
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_tracker(path: str) -> str:
|
||||
def get_tracker(path: Path) -> str:
|
||||
"""
|
||||
Get the tracker used in the dataset located at path.
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ def get_tracker(path: str) -> str:
|
|||
return tracker
|
||||
|
||||
|
||||
def get(path: str, file: str) -> None:
|
||||
def get(path: Path, file: Path) -> None:
|
||||
"""
|
||||
Wrapper function to get a file from the dataset located at path with the specified tracker.
|
||||
|
||||
|
|
@ -56,7 +57,7 @@ def get(path: str, file: str) -> None:
|
|||
return
|
||||
|
||||
|
||||
def save(path: str, message: str, files: Optional[list[str]]=None) -> None:
|
||||
def save(path: Path, message: str, files: Optional[list[Path]]=None) -> None:
|
||||
"""
|
||||
Wrapper function to save a file to the dataset located at path with the specified tracker.
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ def save(path: str, message: str, files: Optional[list[str]]=None) -> None:
|
|||
tracker = get_tracker(path)
|
||||
if tracker == 'datalad':
|
||||
if files is not None:
|
||||
files = [os.path.join(path, f) for f in files]
|
||||
files = [path / f for f in files]
|
||||
dl.save(files, message=message, dataset=path)
|
||||
elif tracker == 'None':
|
||||
Warning("Tracker 'None' does not implement save.")
|
||||
|
|
@ -81,7 +82,7 @@ def save(path: str, message: str, files: Optional[list[str]]=None) -> None:
|
|||
raise ValueError(f"Tracker {tracker} is not supported.")
|
||||
|
||||
|
||||
def init(path: str, tracker: str='datalad') -> None:
|
||||
def init(path: Path, tracker: str='datalad') -> None:
|
||||
"""
|
||||
Initialize a dataset at the specified path with the specified tracker.
|
||||
|
||||
|
|
@ -101,7 +102,7 @@ def init(path: str, tracker: str='datalad') -> None:
|
|||
return
|
||||
|
||||
|
||||
def unlock(path: str, file: str) -> None:
|
||||
def unlock(path: Path, file: Path) -> None:
|
||||
"""
|
||||
Wrapper function to unlock a file in the dataset located at path with the specified tracker.
|
||||
|
||||
|
|
@ -123,7 +124,7 @@ def unlock(path: str, file: str) -> None:
|
|||
return
|
||||
|
||||
|
||||
def clone(path: str, source: str, target: str) -> None:
|
||||
def clone(path: Path, source: str, target: str) -> None:
|
||||
"""
|
||||
Wrapper function to clone a dataset from source to target with the specified tracker.
|
||||
Parameters
|
||||
|
|
@ -147,7 +148,7 @@ def clone(path: str, source: str, target: str) -> None:
|
|||
return
|
||||
|
||||
|
||||
def drop(path: str, reckless: Optional[str]=None) -> None:
|
||||
def drop(path: Path, reckless: Optional[str]=None) -> None:
|
||||
"""
|
||||
Wrapper function to drop data from a dataset located at path with the specified tracker.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue