Skip to content

Add small function to update RIA url #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ jobs:

steps:
- name: Setup environment
uses: khanlab/actions/.github/actions/action-setup_task-installPyProject@v0.3.2
uses: khanlab/actions/.github/actions/action-setup_task-installPyProject@v0.3.3
with:
python-version: ${{ matrix.python-version }}
install-library: true

- name: Start Redis
uses: supercharge/redis-github-action@1.1.0
Expand Down
31 changes: 27 additions & 4 deletions autobidsportal/datalad.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ def get_alias(study_id: int, dataset_type: DatasetType) -> str:
return f"study-{study_id}_{text}"


def update_ria_url(ria_url: str) -> str:
"""Update RIA url if necessary.

Parameters
----------
ria_url
Existing RIA url to check

Returns
-------
str
New ria url
"""
if ria_url == current_app.config["DATALAD_RIA_URL"]:
return ria_url
return current_app.config["DATALAD_RIA_URL"] # pyright: ignore


def ensure_dataset_exists(
study_id: int,
dataset_type: DatasetType,
Expand All @@ -116,6 +134,8 @@ def ensure_dataset_exists(
# Get study by ID
study = Study.query.get(study_id)

study.custom_ria_url = update_ria_url(study.custom_ria_url)

# Grab dataset
dataset = DataladDataset.query.filter_by(
study_id=study_id,
Expand Down Expand Up @@ -144,7 +164,10 @@ def ensure_dataset_exists(

# Add dataset to db
db.session.add(dataset) # pyright: ignore
db.session.commit() # pyright: ignore
else:
dataset.custom_ria_url = study.custom_ria_url

db.session.commit() # pyright: ignore

return dataset

Expand Down Expand Up @@ -194,7 +217,7 @@ def clone_ria_dataset(path: str, alias: str, ria_url: str | None = None):
datalad_api.clone( # pyright: ignore
"".join(
[
ria_url
update_ria_url(ria_url)
if ria_url is not None
else current_app.config["DATALAD_RIA_URL"],
"#~",
Expand Down Expand Up @@ -228,7 +251,7 @@ def delete_tar_file(study_id: int, tar_file: str):
) as download_dir, RiaDataset(
download_dir,
dataset.ria_alias,
ria_url=dataset.custom_ria_url,
ria_url=update_ria_url(dataset.custom_ria_url),
) as path_dataset:
to_delete = str(path_dataset / tar_file)
current_app.logger.info("Removing %s", to_delete)
Expand Down Expand Up @@ -269,7 +292,7 @@ def rename_tar_file(
) as download_dir, RiaDataset(
download_dir,
dataset.ria_alias,
ria_url=dataset.custom_ria_url,
ria_url=update_ria_url(dataset.custom_ria_url),
) as path_dataset:
to_rename = path_dataset / tar_file
new_name = path_dataset / Path(new_name).name
Expand Down