Skip to content

Commit

Permalink
idb
Browse files Browse the repository at this point in the history
Reviewed By: jermenkoo

Differential Revision: D64167293

fbshipit-source-id: 508e7ae387c92b49ab5753f221d0a76760a8f865
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Oct 11, 2024
1 parent 1b8aa4e commit f2e4cea
Show file tree
Hide file tree
Showing 50 changed files with 481 additions and 499 deletions.
5 changes: 3 additions & 2 deletions idb/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import os
from abc import ABCMeta, abstractmethod
from argparse import ArgumentParser, Namespace
from typing import AsyncGenerator, Optional
from collections.abc import AsyncGenerator
from typing import Optional

from idb.common import plugin
from idb.common.command import Command
Expand Down Expand Up @@ -123,7 +124,7 @@ def add_parser_arguments(self, parser: ArgumentParser) -> None:
super().add_parser_arguments(parser)

async def _run_impl(self, args: Namespace) -> None:
address: Optional[Address] = None
address: Address | None = None
try:
async with _get_client(args=args, logger=self.logger) as client:
address = client.address
Expand Down
2 changes: 1 addition & 1 deletion idb/cli/commands/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def add_parser_arguments(self, parser: ArgumentParser) -> None:
super().add_parser_arguments(parser)

async def run_with_client(self, args: Namespace, client: Client) -> None:
artifact: Optional[InstalledArtifact] = None
artifact: InstalledArtifact | None = None
compression = (
Compression[args.compression] if args.compression is not None else None
)
Expand Down
2 changes: 1 addition & 1 deletion idb/cli/commands/approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from idb.common.types import Client, Permission


_ARG_TO_ENUM: Dict[str, Permission] = {
_ARG_TO_ENUM: dict[str, Permission] = {
key.lower(): value for (key, value) in Permission.__members__.items()
}

Expand Down
2 changes: 1 addition & 1 deletion idb/cli/commands/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def _run_impl(self, args: Namespace) -> None:
self.logger.info("Exiting")

def _reply_with_port(
self, reply_fd: Optional[int], prefer_ipv6: bool, ports: Dict[str, int]
self, reply_fd: int | None, prefer_ipv6: bool, ports: dict[str, int]
) -> None:
if not reply_fd:
return
Expand Down
10 changes: 5 additions & 5 deletions idb/cli/commands/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def _add_container_types_to_group(
group: _MutuallyExclusiveGroup, containers: List[Tuple[FileContainerType, str]]
group: _MutuallyExclusiveGroup, containers: list[tuple[FileContainerType, str]]
) -> None:
for container_type, help_text in containers:
argument_name = container_type.value.replace("_", "-")
Expand Down Expand Up @@ -121,7 +121,7 @@ def name(self) -> str:
return "list"

@property
def aliases(self) -> List[str]:
def aliases(self) -> list[str]:
return ["ls"]

def add_parser_arguments(self, parser: ArgumentParser) -> None:
Expand Down Expand Up @@ -200,7 +200,7 @@ def name(self) -> str:
return "move"

@property
def aliases(self) -> List[str]:
def aliases(self) -> list[str]:
return ["mv"]

def add_parser_arguments(self, parser: ArgumentParser) -> None:
Expand Down Expand Up @@ -233,7 +233,7 @@ def name(self) -> str:
return "remove"

@property
def aliases(self) -> List[str]:
def aliases(self) -> list[str]:
return ["rm"]

def add_parser_arguments(self, parser: ArgumentParser) -> None:
Expand Down Expand Up @@ -324,7 +324,7 @@ def name(self) -> str:
return "read"

@property
def aliases(self) -> List[str]:
def aliases(self) -> list[str]:
return ["show"]

def add_parser_arguments(self, parser: ArgumentParser) -> None:
Expand Down
4 changes: 2 additions & 2 deletions idb/cli/commands/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async def run_with_client(self, args: Namespace, client: Client) -> None:
print("")

def normalise_log_arguments(
self, log_arguments: Optional[List[str]]
) -> Optional[List[str]]:
self, log_arguments: list[str] | None
) -> list[str] | None:
if log_arguments is None:
return None

Expand Down
2 changes: 1 addition & 1 deletion idb/cli/commands/revoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from idb.common.types import Client, Permission


_ARG_TO_ENUM: Dict[str, Permission] = {
_ARG_TO_ENUM: dict[str, Permission] = {
key.lower(): value for (key, value) in Permission.__members__.items()
}

Expand Down
3 changes: 2 additions & 1 deletion idb/cli/commands/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import sys
from argparse import ArgumentParser, Namespace
from collections.abc import Iterator
from contextlib import contextmanager
from typing import IO, Iterator
from typing import IO

from idb.cli import ClientCommand
from idb.common.types import Client
Expand Down
2 changes: 1 addition & 1 deletion idb/cli/commands/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ShellCommand(ClientCommand):
def __init__(self, parser: ArgumentParser) -> None:
super().__init__()
self.parser = parser
self.root_command: Optional[CommandGroup] = None
self.root_command: CommandGroup | None = None

@property
def description(self) -> str:
Expand Down
5 changes: 3 additions & 2 deletions idb/cli/commands/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import json
from argparse import ArgumentParser, Namespace, SUPPRESS
from typing import Mapping, Union
from collections.abc import Mapping
from typing import Union

import idb.common.plugin as plugin
from idb.cli import ClientCommand, CompanionCommand, ManagementCommand
Expand Down Expand Up @@ -37,7 +38,7 @@ class DisconnectCommandException(Exception):
pass


def get_destination(args: Namespace) -> Union[TCPAddress, str]:
def get_destination(args: Namespace) -> TCPAddress | str:
if is_udid(args.companion):
return args.companion
elif args.port and args.companion:
Expand Down
4 changes: 2 additions & 2 deletions idb/cli/commands/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from idb.common.types import Client, VideoFormat


_FORMAT_CHOICE_MAP: Dict[str, VideoFormat] = {
_FORMAT_CHOICE_MAP: dict[str, VideoFormat] = {
str(format.value.lower()): format for format in VideoFormat
}

Expand All @@ -30,7 +30,7 @@ def name(self) -> str:
return "video"

@property
def aliases(self) -> List[str]:
def aliases(self) -> list[str]:
return ["record-video"]

def add_parser_arguments(self, parser: ArgumentParser) -> None:
Expand Down
12 changes: 6 additions & 6 deletions idb/cli/commands/xctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async def install_bundles(self, args: Namespace, client: Client) -> None:

async def install_dsym_test_bundle(
self, args: Namespace, client: Client, test_bundle_location: str
) -> Optional[str]:
) -> str | None:
dsym_name = None
dsym_path_location = args.install_dsym_test_bundle
if args.install_dsym_test_bundle == NO_SPECIFIED_PATH:
Expand All @@ -320,10 +320,10 @@ async def install_dsym_test_bundle(
dsym_name = install_response.name
return dsym_name

def get_tests_to_run(self, args: Namespace) -> Optional[Set[str]]:
def get_tests_to_run(self, args: Namespace) -> set[str] | None:
return None

def get_tests_to_skip(self, args: Namespace) -> Optional[Set[str]]:
def get_tests_to_skip(self, args: Namespace) -> set[str] | None:
return None


Expand Down Expand Up @@ -366,10 +366,10 @@ async def install_bundles(self, args: Namespace, client: Client) -> None:
async for app in client.install(args.app_bundle_id):
args.app_bundle_id = app.name

def get_tests_to_run(self, args: Namespace) -> Optional[Set[str]]:
def get_tests_to_run(self, args: Namespace) -> set[str] | None:
return set(args.tests_to_run) if args.tests_to_run else None

def get_tests_to_skip(self, args: Namespace) -> Optional[Set[str]]:
def get_tests_to_skip(self, args: Namespace) -> set[str] | None:
return set(args.tests_to_skip) if args.tests_to_skip else None


Expand Down Expand Up @@ -414,7 +414,7 @@ def add_parser_arguments(self, parser: ArgumentParser) -> None:
Format: className/methodName",
)

def get_tests_to_run(self, args: Namespace) -> Optional[Set[str]]:
def get_tests_to_run(self, args: Namespace) -> set[str] | None:
if args.test_to_run:
return set(args.test_to_run)
if args.tests_to_run:
Expand Down
10 changes: 5 additions & 5 deletions idb/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
logger: logging.Logger = logging.getLogger()


def get_default_companion_path() -> Optional[str]:
def get_default_companion_path() -> str | None:
if sys.platform != "darwin":
return None
return shutil.which("idb_companion") or "/usr/local/bin/idb_companion"
Expand All @@ -126,7 +126,7 @@ def get_default_companion_path() -> Optional[str]:
SysExitArg = Union[int, str, None]


async def gen_main(cmd_input: Optional[List[str]] = None) -> SysExitArg:
async def gen_main(cmd_input: list[str] | None = None) -> SysExitArg:
# Make sure all files are created with global rw permissions
os.umask(0o000)
# Setup parser
Expand Down Expand Up @@ -180,7 +180,7 @@ async def gen_main(cmd_input: Optional[List[str]] = None) -> SysExitArg:
help="If flagged will not modify local state when a companion is known to be unresponsive",
)
shell_command = ShellCommand(parser=parser)
commands: List[Command] = [
commands: list[Command] = [
AppInstallCommand(),
AppUninstallCommand(),
AppListCommand(),
Expand Down Expand Up @@ -340,7 +340,7 @@ async def gen_main(cmd_input: Optional[List[str]] = None) -> SysExitArg:
await drain_coroutines(pending)


async def drain_coroutines(pending: Set[asyncio.Task]) -> None:
async def drain_coroutines(pending: set[asyncio.Task]) -> None:
if not pending:
return
logger.debug(f"Shutting down {len(pending)} coroutines")
Expand All @@ -355,7 +355,7 @@ async def drain_coroutines(pending: Set[asyncio.Task]) -> None:
pass


def main(cmd_input: Optional[List[str]] = None) -> SysExitArg:
def main(cmd_input: list[str] | None = None) -> SysExitArg:
loop = asyncio.get_event_loop()
try:
return loop.run_until_complete(gen_main(cmd_input))
Expand Down
4 changes: 2 additions & 2 deletions idb/cli/tests/parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


T = TypeVar("T")
COMPANION_PATH: Optional[str] = (
COMPANION_PATH: str | None = (
"/usr/local/bin/idb_companion" if sys.platform == "darwin" else None
)

Expand All @@ -37,7 +37,7 @@ class AsyncGeneratorMock(AsyncMock):
def __call__(self) -> None:
super()

def __init__(self, iter_list: Tuple[T, ...] = ()) -> None:
def __init__(self, iter_list: tuple[T, ...] = ()) -> None:
super().__init__()
self.iter_list = iter_list
self.iter_pos: int = -1
Expand Down
12 changes: 5 additions & 7 deletions idb/common/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def __call__(
self,
parser: argparse.ArgumentParser,
namespace: argparse.Namespace,
values: List[str],
option_string: Optional[str] = None,
values: list[str],
option_string: str | None = None,
) -> None:
assert len(values) == 1
try:
Expand All @@ -36,13 +36,11 @@ def __call__(
setattr(namespace, self.dest, d)


def have_file_with_extension(file_prefix: str, extensions: List[str]) -> bool:
return any(
(os.path.exists(f"{file_prefix}.{extension}") for extension in extensions)
)
def have_file_with_extension(file_prefix: str, extensions: list[str]) -> bool:
return any(os.path.exists(f"{file_prefix}.{extension}") for extension in extensions)


def find_next_file_prefix(basename: str, extensions: Optional[List[str]] = None) -> str:
def find_next_file_prefix(basename: str, extensions: list[str] | None = None) -> str:
extensions = extensions or []
number = 1
while True:
Expand Down
14 changes: 7 additions & 7 deletions idb/common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Command(metaclass=ABCMeta):
@property
def aliases(self) -> List[str]:
def aliases(self) -> list[str]:
return []

@property
Expand All @@ -40,16 +40,16 @@ def resolve_command_from_args(self, args: Namespace) -> "Command":

class CompositeCommand(Command, metaclass=ABCMeta):
def __init__(self) -> None:
self.parser: Optional[ArgumentParser] = None
self._subcommands_by_name: Dict[str, Command] = {}
self.parser: ArgumentParser | None = None
self._subcommands_by_name: dict[str, Command] = {}

@property
@abstractmethod
def subcommands(self) -> List[Command]:
def subcommands(self) -> list[Command]:
pass

@property
def subcommands_by_name(self) -> Dict[str, Command]:
def subcommands_by_name(self) -> dict[str, Command]:
def add_unique_cmd(key: str, value: Command) -> None:
assert (
key not in self._subcommands_by_name
Expand Down Expand Up @@ -89,7 +89,7 @@ async def run(self, args: Namespace) -> None:


class CommandGroup(CompositeCommand):
def __init__(self, name: str, description: str, commands: List[Command]) -> None:
def __init__(self, name: str, description: str, commands: list[Command]) -> None:
super().__init__()
self.commands = commands
self._name = name
Expand All @@ -104,5 +104,5 @@ def description(self) -> str:
return self._description

@property
def subcommands(self) -> List[Command]:
def subcommands(self) -> list[Command]:
return self.commands
Loading

0 comments on commit f2e4cea

Please sign in to comment.