Skip to content

Commit

Permalink
apply linter suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-monch committed Oct 21, 2024
1 parent 1a8f361 commit e591531
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 237 deletions.
13 changes: 0 additions & 13 deletions TODO.txt

This file was deleted.

2 changes: 1 addition & 1 deletion datalad_remake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from datalad_remake._version import __version__


__all__ = [
'__version__',
'command_suite',
]


Expand Down
44 changes: 22 additions & 22 deletions datalad_remake/annexremotes/remake_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,34 @@
import subprocess
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Iterable,
)
from urllib.parse import (
unquote,
urlparse,
)

from annexremote import Master
from datalad.customremotes import RemoteError
from datalad_next.annexremotes import (
SpecialRemote,
super_main
)
from datalad_next.annexremotes import SpecialRemote, super_main
from datalad_next.datasets import Dataset
from datalad_next.runners import call_git_success

from .. import (
from datalad_remake import (
specification_dir,
url_scheme,
)

from ..commands.make_cmd import (
from datalad_remake.commands.make_cmd import (
execute,
get_file_dataset,
provide_context,
)
from ..utils.glob import resolve_patterns
from datalad_remake.utils.glob import resolve_patterns

if TYPE_CHECKING:
from collections.abc import Iterable

from annexremote import Master

lgr = logging.getLogger('datalad.remake.annexremotes.remake')

Expand All @@ -51,19 +50,19 @@ def close(self) -> None:
pass

def _check_url(self, url: str) -> bool:
return url.startswith(f'URL--{url_scheme}:') or url.startswith(f'{url_scheme}:')
return url.startswith((f'URL--{url_scheme}:', f'{url_scheme}:'))

def prepare(self):
self.annex.debug(f'PREPARE')
self.annex.debug('PREPARE')

def initremote(self):
self.annex.debug(f'INITREMOTE')
self.annex.debug('INITREMOTE')

def remove(self, key: str):
self.annex.debug(f'REMOVE {key!r}')

def transfer_store(self, key: str, local_file: str):
self.annex.debug(f'TRANSFER STORE')
self.annex.debug(f'TRANSFER STORE {key!r}, {local_file!r}')

def claimurl(self, url: str) -> bool:
self.annex.debug(f'CLAIMURL {url!r}')
Expand All @@ -74,7 +73,7 @@ def checkurl(self, url: str) -> bool:
return self._check_url(url)

def getcost(self) -> int:
self.annex.debug(f'GETCOST')
self.annex.debug('GETCOST')
return 100

def get_url_encoded_info(self, url: str) -> list[str]:
Expand All @@ -94,10 +93,10 @@ def get_compute_info(self,
def get_assigned_value(assignment: str) -> str:
return assignment.split('=', 1)[1]

root_version, spec_name, this = list(
map(
lambda expr: unquote(get_assigned_value(expr)),
self.get_url_encoded_info(self.get_url_for_key(key))))
root_version, spec_name, this = (
unquote(get_assigned_value(expr))
for expr in self.get_url_encoded_info(self.get_url_for_key(key))
)

dataset = self._find_dataset(root_version)
spec_path = dataset.pathobj / specification_dir / spec_name
Expand Down Expand Up @@ -149,15 +148,16 @@ def _find_dataset(self,
current_dir = start_dir
while current_dir != Path('/'):
result = subprocess.run(
['git', 'cat-file', '-t', commit],
['git', 'cat-file', '-t', commit], # noqa: S607
stdout=subprocess.PIPE,
cwd=current_dir)
cwd=current_dir, check=False)
if result.returncode == 0 and result.stdout.strip() == b'commit':
return Dataset(current_dir)
current_dir = current_dir.parent
raise RemoteError(
msg = (
f'Could not find dataset with commit {commit!r}, starting from '
f'{start_dir}')
raise RemoteError(msg)

def _collect(self,
worktree: Path,
Expand Down
24 changes: 9 additions & 15 deletions datalad_remake/annexremotes/tests/test_hierarchies.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from collections.abc import Iterable
from pathlib import Path
from typing import Iterable

import pytest

from datalad.distribution.get import Get as datalad_get
from datalad.distribution.get import Get as datalad_Get
from datalad_next.datasets import Dataset
from datalad_next.tests.fixtures import datalad_cfg

from datalad_remake.commands.tests.create_datasets import (
create_simple_computation_dataset,
)


test_method = """
inputs = ['first', 'second', 'third']
use_shell = 'true'
Expand Down Expand Up @@ -50,13 +47,10 @@
]


test_file_content = [
(file, content)
for file, content in
zip(
output_pattern_static,
['content: first\n', 'content: second\n', 'content: third\n'] * 4)
]
test_file_content = list(zip(
output_pattern_static,
['content: first\n', 'content: second\n', 'content: third\n'] * 4, strict=False)
)


def _drop_files(dataset: Dataset,
Expand All @@ -74,7 +68,7 @@ def _check_content(dataset,


@pytest.mark.parametrize('output_pattern', [output_pattern_static, output_pattern_glob])
def test_end_to_end(tmp_path, datalad_cfg, monkeypatch, output_pattern):
def test_end_to_end(tmp_path, monkeypatch, output_pattern):

root_dataset = create_simple_computation_dataset(
tmp_path, 'd2', 3, test_method)
Expand Down Expand Up @@ -104,7 +98,7 @@ def test_end_to_end(tmp_path, datalad_cfg, monkeypatch, output_pattern):
# Go to the subdataset `d2_subds0/d2_subds1` and fetch the content of `a1.txt`
# from a datalad-remake remote.
monkeypatch.chdir(root_dataset.pathobj / 'd2_subds0' / 'd2_subds1')
datalad_get()('a1.txt')
datalad_Get()('a1.txt')

# check that all known files that were computed are added to the annex
_check_content(root_dataset, test_file_content)
Expand All @@ -113,6 +107,6 @@ def test_end_to_end(tmp_path, datalad_cfg, monkeypatch, output_pattern):

# check get in subdatasets
monkeypatch.chdir(root_dataset.pathobj)
datalad_get()('d2_subds0/d2_subds1/a1.txt')
datalad_Get()('d2_subds0/d2_subds1/a1.txt')

_check_content(root_dataset, test_file_content)
28 changes: 14 additions & 14 deletions datalad_remake/annexremotes/tests/test_remake_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from annexremote import Master

from ..remake_remote import RemakeRemote
from ... import specification_dir
from ...commands.make_cmd import build_json
from datalad_remake.commands.tests.create_datasets import create_ds_hierarchy

from ... import specification_dir
from ...commands.make_cmd import build_json
from ..remake_remote import RemakeRemote

template = """
inputs = ['content']
Expand Down Expand Up @@ -73,13 +73,13 @@ def test_compute_remote_main(tmp_path, monkeypatch):
(template_path / 'echo').write_text(template)
dataset.save()

key = tuple(
key = next(
filter(
lambda line: line.startswith(b'key: '),
subprocess.run(
['git', 'annex', 'info', 'a.txt'],
['git', 'annex', 'info', 'a.txt'], # noqa: S607
stdout=subprocess.PIPE,
check=True).stdout.splitlines()))[0].split(b': ')[1]
check=True).stdout.splitlines())).split(b': ')[1]

(dataset.pathobj / specification_dir).mkdir(parents=True)
(dataset.pathobj / specification_dir / '000001111122222').write_text(
Expand All @@ -89,30 +89,30 @@ def test_compute_remote_main(tmp_path, monkeypatch):
['a.txt'],
{'content': 'some_string'}))

input = MockedInput()
input_ = MockedInput()

# We send all messages into the queue upfront because we do the test in a
# single thread and do not get back control once `master.listen` is called
# below.
input.send('PREPARE\n')
input.send(f'TRANSFER RETRIEVE {key} {str(tmp_path / "remade.txt")}\n')
input_.send('PREPARE\n')
input_.send(f'TRANSFER RETRIEVE {key} {tmp_path / "remade.txt"!s}\n')
url = (
'datalad-make:///?'
f'root_version={dataset.repo.get_hexsha()}'
'&specification=000001111122222'
'&this=a.txt'
)
input.send(f'VALUE {url}\n')
input.send('VALUE\n')
input.send('VALUE .git\n')
input.send('')
input_.send(f'VALUE {url}\n')
input_.send('VALUE\n')
input_.send('VALUE .git\n')
input_.send('')

output = MockedOutput()

master = Master(output=output)
remote = RemakeRemote(master)
master.LinkRemote(remote)
master.Listen(input=input)
master.Listen(input=input_)

# At this point the datalad-remake remote should have executed the
# computation and written the result.
Expand Down
Loading

0 comments on commit e591531

Please sign in to comment.