Skip to content

Commit

Permalink
Fix open and localize of mirrored targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Oct 25, 2024
1 parent aa07077 commit 5a40250
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion law/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _check_sort(self, value: tuple[T]) -> tuple[T]:
return value

key = self._sort if callable(self._sort) else None
return tuple(sorted(value, key=key)) # type: ignore[return-value]
return tuple(sorted(value, key=key)) # type: ignore[return-value, type-var]

def _check_len(self, value: tuple[Any]) -> None:
str_repr = lambda: ",".join(str(v) for v in value)
Expand Down
5 changes: 3 additions & 2 deletions law/target/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def move( # type: ignore[override]
...

@abstractmethod
@contextlib.contextmanager
def open(
self,
path: str | pathlib.Path,
Expand All @@ -216,7 +217,7 @@ def open(
perm: int | None = None,
dir_perm: int | None = None,
**kwargs,
) -> AbstractContextManager[IO]:
) -> Iterator[IO]:
...


Expand Down Expand Up @@ -441,7 +442,7 @@ def localize(
dir_perm: int | None = None,
tmp_dir: str | pathlib.Path | None = None,
**kwargs,
) -> Generator[FileSystemTarget, None, None]:
) -> Iterator[FileSystemTarget]:
...

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion law/target/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def move( # type: ignore[override]

return dst

def open(
def open( # type: ignore[override]
self,
path: str | pathlib.Path,
mode: str,
Expand Down
12 changes: 7 additions & 5 deletions law/target/mirrored.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
RemoteFileSystem, RemoteTarget, RemoteFileTarget, RemoteDirectoryTarget,
)
from law.util import patch_object
from law._types import Any, Type, Generator, AbstractContextManager, IO, Iterator
from law._types import Any, Type, Generator, Iterator, IO


local_root_check_lock = threading.Lock()
Expand Down Expand Up @@ -295,7 +295,7 @@ def move_from_local(self, *args, **kwargs) -> str:
return ret

@contextlib.contextmanager
def localize(self, mode: str = "r", **kwargs) -> Generator[FileSystemTarget, None, None]:
def localize(self, mode: str = "r", **kwargs) -> Iterator[FileSystemTarget]:
with (
self.local_target.localize(mode=mode, **kwargs)
if (mode == "r" or not self.local_read_only) and self._local_target_exists()
Expand Down Expand Up @@ -336,12 +336,14 @@ class MirroredFileTarget(FileSystemFileTarget, MirroredTarget):
def __init__(self, path: str | pathlib.Path, **kwargs) -> None:
super().__init__(path, _is_file=True, **kwargs)

def open(self, mode: str, **kwargs) -> AbstractContextManager[IO]:
ret = (
@contextlib.contextmanager
def open(self, mode: str, **kwargs) -> Iterator[IO]:
with (
self.local_target.open(mode, **kwargs)
if (mode == "r" or not self.local_read_only) and self._local_target_exists()
else self.remote_target.open(mode, **kwargs)
)
) as ret:
yield ret
if mode == "w" and self.local_read_only and self.local_sync:
self._wait_for_local(missing=False)
return ret
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ exclude = ["tests/*"]
[tool.mypy]

disable_error_code = ["no-redef", "valid-type", "method-assign"]
exclude = ["law/templates/*", "docs", "examples", "tests", "build"]
exclude = ["law/templates/*", "docs", "examples", "tests", "build", "setup.py"]
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mypy~=1.11.1;python_version>="3.8"
mypy~=1.13.0;python_version>="3.8"
flake8~=7.1.1;python_version>="3.8"
flake8~=5.0.0;python_version<"3.8"
flake8-commas~=2.1.0;python_version<"3.8"
Expand Down

0 comments on commit 5a40250

Please sign in to comment.