From bcbdf1402246770fc20d05dd7d9b821cdaa4a286 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Thu, 7 Mar 2024 09:17:30 -0500 Subject: [PATCH] Use `reregisterurl` to move datalad remotes to web --- README.md | 2 +- src/backups2datalad/adataset.py | 44 +++++++++++++++++++++++++++------ test/test_commands.py | 5 ---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5872e97..a8c1ad7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/backups2datalad/adataset.py b/src/backups2datalad/adataset.py index 73ab403..1bc17d6 100644 --- a/src/backups2datalad/adataset.py +++ b/src/backups2datalad/adataset.py @@ -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 @@ -161,14 +162,41 @@ async def ensure_dandi_provider(self, api_url: str) -> None: ) async def disable_dandi_provider(self) -> None: - # See - # 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 ( diff --git a/test/test_commands.py b/test/test_commands.py index 74c9e0b..a92dd76 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -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( @@ -396,4 +392,3 @@ async def test_backup_embargoed( u.startswith("https://dandi-api-staging-dandisets.s3.amazonaws.com") for u in web_urls ) - """