From 9c152880e60f1bf8eaa53059a3daba396721c305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Li=C3=A9tar?= Date: Mon, 16 Dec 2024 13:27:58 +0000 Subject: [PATCH] Format --- src/pyorderly/outpack/location_push.py | 2 +- src/pyorderly/outpack/util.py | 30 ++++++++++++-------------- tests/helpers/__init__.py | 6 ++++-- tests/helpers/outpack_server.py | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/pyorderly/outpack/location_push.py b/src/pyorderly/outpack/location_push.py index d08e07d..7eb2f06 100644 --- a/src/pyorderly/outpack/location_push.py +++ b/src/pyorderly/outpack/location_push.py @@ -1,12 +1,12 @@ from dataclasses import dataclass from typing import List, Union -from pyorderly.outpack.util import as_list from pyorderly.outpack.location import _location_driver, location_resolve_valid from pyorderly.outpack.location_driver import LocationDriver from pyorderly.outpack.location_pull import _find_all_dependencies from pyorderly.outpack.root import OutpackRoot, find_file_by_hash, root_open from pyorderly.outpack.static import LOCATION_LOCAL +from pyorderly.outpack.util import as_list @dataclass diff --git a/src/pyorderly/outpack/util.py b/src/pyorderly/outpack/util.py index 42d10ea..ef8d0ae 100644 --- a/src/pyorderly/outpack/util.py +++ b/src/pyorderly/outpack/util.py @@ -5,7 +5,7 @@ from contextlib import contextmanager from itertools import filterfalse, tee from pathlib import Path, PurePath -from typing import Dict, List, Optional, Union, overload +from typing import Dict, List, Optional, TypeVar, Union def find_file_descend(filename, path): @@ -60,7 +60,9 @@ def transient_working_directory(path): os.chdir(origin) -def assert_file_exists(path: Union[str, List[str]], *, workdir=None, name="File"): +def assert_file_exists( + path: Union[str, List[str]], *, workdir=None, name="File" +): with transient_working_directory(workdir): if isinstance(path, list): missing = [str(p) for p in path if not os.path.exists(p)] @@ -193,19 +195,10 @@ def openable_temporary_file(*, mode: str = "w+b", dir: Optional[str] = None): pass -@overload -def as_posix_path(paths: str) -> str: ... +Paths = TypeVar("Paths", str, List[str], Dict[str, str]) -@overload -def as_posix_path(paths: List[str]) -> List[str]: ... - - -@overload -def as_posix_path(paths: Dict[str, str]) -> Dict[str, str]: ... - - -def as_posix_path(paths): +def as_posix_path(paths: Paths) -> Paths: """ Convert a native path into a posix path. @@ -219,7 +212,12 @@ def as_posix_path(paths): else: return PurePath(paths).as_posix() -T = TypeVar('T') + +T = TypeVar("T") + + def as_list(x: Union[T, List[T]]) -> List[T]: - if isinstance(x, list): return x - else: return [x] + if isinstance(x, list): + return x + else: + return [x] diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py index 476d650..550942c 100644 --- a/tests/helpers/__init__.py +++ b/tests/helpers/__init__.py @@ -14,7 +14,7 @@ from pyorderly.outpack.location import outpack_location_add_path from pyorderly.outpack.metadata import MetadataCore, PacketDepends from pyorderly.outpack.packet import Packet, insert_packet -from pyorderly.outpack.root import root_open, OutpackRoot +from pyorderly.outpack.root import OutpackRoot, root_open from pyorderly.outpack.schema import outpack_schema_version from pyorderly.outpack.util import openable_temporary_file from pyorderly.run import orderly_run @@ -44,7 +44,9 @@ def create_packet(root, name, *, packet_id=None, parameters=None): insert_packet(root, Path(src), metadata) -def create_random_packet(root, name="data", *, parameters=None, packet_id=None) -> str: +def create_random_packet( + root, name="data", *, parameters=None, packet_id=None +) -> str: d = [f"{random.random()}\n" for _ in range(10)] with create_packet( diff --git a/tests/helpers/outpack_server.py b/tests/helpers/outpack_server.py index d1710ba..6c30eb1 100644 --- a/tests/helpers/outpack_server.py +++ b/tests/helpers/outpack_server.py @@ -8,8 +8,8 @@ import pytest import requests -from pyorderly.outpack.root import OutpackRoot from pyorderly.outpack.init import outpack_init +from pyorderly.outpack.root import OutpackRoot def _wait_ready(p, url, args, timeout=2):