Skip to content

Commit

Permalink
Use reregisterurl to move datalad remotes to web
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed May 22, 2024
1 parent 0feac63 commit 61a4498
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Before running `backups2datalad`, the following setup must be performed:
required.

- [git-annex](https://git-annex.branchable.com) must be installed. At least
version 10.20230126 is required, though you should endeavor to obtain the
version 10.20240430 is required, though you should endeavor to obtain the
latest version.

- An API token needs to be obtained for the DANDI instance that is being
Expand Down
44 changes: 36 additions & 8 deletions src/backups2datalad/adataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import Any, ClassVar

import anyio
from anyio.to_thread import run_sync
from dandi.consts import EmbargoStatus
from datalad.api import Dataset
from datalad.runner.exception import CommandError
Expand Down Expand Up @@ -161,14 +162,41 @@ async def ensure_dandi_provider(self, api_url: str) -> None:
)

async def disable_dandi_provider(self) -> None:
# See <https://github.com/dandi/backups2datalad/pull/21#issuecomment-1919164777>
# TODO: Once this is implemented, uncomment the commented-out portion
# of `test_backup_embargoed` in `test_commands.py`.
raise NotImplementedError(
"Waiting on Joey's input; see https://git-annex.branchable.com/"
"forum/how_to___34__move__34___URL_between_remotes__63__/"
)
await self.call_git("remote", "remove", "datalad") # type: ignore[unreachable]
# `anyio.run_process()` doesn't support files or streams as stdin to
# subprocesses, so we have to do this the synchronous way.

def reregister_keys() -> None:
with subprocess.Popen(
[
"git",
*GIT_OPTIONS,
"annex",
"find",
"--include=*",
"--format=${key}\\n",
],
cwd=self.pathobj,
stdout=subprocess.PIPE,
) as p:
try:
subprocess.run(
[
"git",
*GIT_OPTIONS,
"annex",
"reregisterurl",
"--batch",
"--move-from=datalad",
],
cwd=self.pathobj,
stdin=p.stdin,
check=True,
)
finally:
p.terminate()

await run_sync(reregister_keys)
await self.call_git("remote", "remove", "datalad")

async def is_dirty(self) -> bool:
return (
Expand Down
5 changes: 0 additions & 5 deletions test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ async def test_backup_embargoed(
assert p.is_file()
assert p.read_text() == contents

# TODO: Awaiting resolution of
# https://github.com/dandi/backups2datalad/pull/21#issuecomment-1919164777;
# see `NotImplementedError` in `AsyncDataset.disable_dandi_provider()`
"""
await embargoed_dandiset.dandiset.unembargo()

r = await CliRunner().invoke(
Expand Down Expand Up @@ -396,4 +392,3 @@ async def test_backup_embargoed(
u.startswith("https://dandi-api-staging-dandisets.s3.amazonaws.com")
for u in web_urls
)
"""

0 comments on commit 61a4498

Please sign in to comment.