use pathlib.Path for directories and files
Some checks failed
Ruff / ruff (push) Waiting to run
Pytest / pytest (3.12) (push) Successful in 1m15s
Pytest / pytest (3.13) (push) Has been cancelled
Mypy / mypy (push) Successful in 1m13s
Pytest / pytest (3.14) (push) Has been cancelled

This commit is contained in:
Justus Kuhlmann 2026-03-23 16:15:55 +01:00
commit 8162758cec
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
13 changed files with 137 additions and 125 deletions

View file

@ -8,9 +8,10 @@ from .find import _project_lookup_by_id
from .tools import list2str, str2list, get_db_file
from .tracker import get, save, unlock, clone, drop
from typing import Union, Optional
from pathlib import Path
def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Union[list[str], None]=None, aliases: Union[list[str], None]=None, code: Union[str, None]=None) -> None:
def create_project(path: Path, uuid: str, owner: Union[str, None]=None, tags: Union[list[str], None]=None, aliases: Union[list[str], None]=None, code: Union[str, None]=None) -> None:
"""
Create a new project entry in the database.
@ -48,7 +49,7 @@ def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Uni
return
def update_project_data(path: str, uuid: str, prop: str, value: Union[str, None] = None) -> None:
def update_project_data(path: Path, uuid: str, prop: str, value: Union[str, None] = None) -> None:
"""
Update/Edit a project entry in the database.
Thin wrapper around sql3 call.
@ -74,9 +75,9 @@ def update_project_data(path: str, uuid: str, prop: str, value: Union[str, None]
return
def update_aliases(path: str, uuid: str, aliases: list[str]) -> None:
def update_aliases(path: Path, uuid: str, aliases: list[str]) -> None:
db_file = get_db_file(path)
db = os.path.join(path, db_file)
db = path / db_file
get(path, db_file)
known_data = _project_lookup_by_id(db, uuid)[0]
known_aliases = known_data[1]
@ -102,7 +103,7 @@ def update_aliases(path: str, uuid: str, aliases: list[str]) -> None:
return
def import_project(path: str, url: str, owner: Union[str, None]=None, tags: Optional[list[str]]=None, aliases: Optional[list[str]]=None, code: Optional[str]=None, isDataset: bool=True) -> str:
def import_project(path: Path, url: str, owner: Union[str, None]=None, tags: Optional[list[str]]=None, aliases: Optional[list[str]]=None, code: Optional[str]=None, isDataset: bool=True) -> str:
"""
Import a datalad dataset into the backlogger.
@ -134,14 +135,14 @@ def import_project(path: str, url: str, owner: Union[str, None]=None, tags: Opti
uuid = str(conf.get("datalad.dataset.id"))
if not uuid:
raise ValueError("The dataset does not have a uuid!")
if not os.path.exists(path + "/projects/" + uuid):
if not os.path.exists(path / "projects" / uuid):
db_file = get_db_file(path)
get(path, db_file)
unlock(path, db_file)
create_project(path, uuid, owner, tags, aliases, code)
move_submodule(path, 'projects/tmp', 'projects/' + uuid)
os.mkdir(path + '/import_scripts/' + uuid)
save(path, message="Import project from " + url, files=['projects/' + uuid, db_file])
move_submodule(path, Path('projects/tmp'), Path('projects') / uuid)
os.mkdir(path / 'import_scripts' / uuid)
save(path, message="Import project from " + url, files=[Path(f'projects/{uuid}'), db_file])
else:
dl.drop(tmp_path, reckless='kill')
shutil.rmtree(tmp_path)
@ -156,7 +157,7 @@ def import_project(path: str, url: str, owner: Union[str, None]=None, tags: Opti
return uuid
def drop_project_data(path: str, uuid: str, path_in_project: str = "") -> None:
def drop_project_data(path: Path, uuid: str, path_in_project: str = "") -> None:
"""
Drop (parts of) a project to free up diskspace
@ -169,6 +170,5 @@ def drop_project_data(path: str, uuid: str, path_in_project: str = "") -> None:
path_pn_project: str, optional
If set, only the given path within the project is dropped.
"""
drop(path + "/projects/" + uuid + "/" + path_in_project)
drop(path / "projects" / uuid / path_in_project)
return