Skip to content

Commit

Permalink
mypy type checking fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cgevans committed Dec 17, 2024
1 parent a4f33b3 commit 542b134
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/qslib/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def sync_from_machine(
)
log.debug(f"checking {f['path']} mtime {f['mtime']} to {sdspath}")
if os.path.exists(sdspath) and os.path.getmtime(sdspath) >= float(
f["mtime"]
f["mtime"].timestamp()
):
log.debug(f"{sdspath} has {os.path.getmtime(sdspath)}")
continue
Expand Down Expand Up @@ -878,7 +878,7 @@ def sync_from_machine(
b.write(machine.read_file(f["path"]))
else:
raise NotImplementedError
os.utime(sdspath, (f["atime"], f["mtime"]))
os.utime(sdspath, (f["atime"].timestamp(), f["mtime"].timestamp()))

# The message log is tricky. Ideally we'd use rsync or wc+tail. TODO
self._update_from_files()
Expand Down
30 changes: 25 additions & 5 deletions src/qslib/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,17 @@ def list_files(
leaf: str = "FILE",
verbose: Literal[False] = False,
recursive: bool = False,
) -> list[str] | list[FileListInfo]: ...

) -> list[str]: ...

@overload
def list_files(
self,
path: str,
*,
leaf: str = "FILE",
verbose: bool = False,
recursive: bool = False,
) -> list[str] | list[FileListInfo]: ...

@_ensure_connection(AccessLevel.Observer)
def list_files(
Expand Down Expand Up @@ -394,8 +402,19 @@ def write_file(self, path: str, data: str | bytes) -> None:
+ b"\n</quote.base64>"
)

@overload
def list_runs_in_storage(self, glob: str = "*", *, verbose: Literal[True]) -> list[FileListInfo]: ...

@overload
def list_runs_in_storage(self, glob: str = "*", *, verbose: Literal[False] = False) -> list[str]: ...

@overload
def list_runs_in_storage(self, glob: str = "*", *, verbose: bool = False) -> list[str] | list[FileListInfo]: ...

@_ensure_connection(AccessLevel.Observer)
def list_runs_in_storage(self, glob: str = "*", verbose: bool = False) -> list[str]:
def list_runs_in_storage(
self, glob: str = "*", *, verbose: bool = False
) -> list[str] | list[FileListInfo]:
"""List runs in machine storage.
Returns
Expand All @@ -407,12 +426,13 @@ def list_runs_in_storage(self, glob: str = "*", verbose: bool = False) -> list[s
"""
if not glob.endswith("eds"):
glob = f"{glob}eds"
a = self.list_files(f"public_run_complete:{glob}", verbose=verbose)
if not verbose:
return [
re.sub("^public_run_complete:", "", s)[:-4] for s in a
re.sub("^public_run_complete:", "", s)[:-4]
for s in self.list_files(f"public_run_complete:{glob}", verbose=False)
]
else:
a = self.list_files(f"public_run_complete:{glob}", verbose=True)
for e in a:
e["path"] = re.sub("^public_run_complete:", "", e["path"])[:-4]
return a
Expand Down
2 changes: 1 addition & 1 deletion src/qslib/plate_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

if TYPE_CHECKING:
from kithairon import PickList, Labware
from typing import Self
from typing_extensions import Self

from .qsconnection_async import QSConnectionAsync

Expand Down
10 changes: 6 additions & 4 deletions src/qslib/qsconnection_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
from .qs_is_protocol import CommandError, Error, NoMatch, QS_IS_Protocol
from .scpi_commands import AccessLevel, ArgList, SCPICommand

class FileListInfo(TypedDict):
class FileListInfo(TypedDict, total=False):
"""Information about a file when verbose=True"""
path: str
type: str
size: int
mtime: datetime
atime: datetime
ctime: datetime
state: str
collected: bool

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -180,8 +182,8 @@ async def list_files(
)
if rm is None:
ag = ArgList.from_string(x)
d: dict[str, str | float | int] = {}
d["path"] = ag.args[0]
d: dict[str, Any] = {}
d["path"] = cast(str, ag.args[0])
d |= ag.opts
else:
d = {}
Expand All @@ -196,7 +198,7 @@ async def list_files(
cast(str, d["path"]), leaf=leaf, verbose=True, recursive=True
)
else:
ret.append(d)
ret.append(cast(FileListInfo, d))
return ret

async def compile_eds(self, run_name: str) -> None:
Expand Down

0 comments on commit 542b134

Please sign in to comment.