update from origin

This commit is contained in:
Ayush Saini 2023-09-30 17:21:33 +05:30
parent 8beb334d64
commit bf2f252ee5
91 changed files with 1839 additions and 1281 deletions

View file

@ -36,7 +36,9 @@ class HostConfig:
mosh_shell: str = 'sh'
workspaces_root: str = '/home/${USER}/cloudshell_workspaces'
sync_perms: bool = True
precommand: str | None = None
precommand: str | None = None # KILL THIS
precommand_noninteractive: str | None = None
precommand_interactive: str | None = None
managed: bool = False
idle_minutes: int = 5
can_sudo_reboot: bool = False

View file

@ -7,7 +7,9 @@ from typing import TYPE_CHECKING
import errno
if TYPE_CHECKING:
pass
from typing import Any
from efro.terminal import ClrBase
class CleanError(Exception):
@ -25,18 +27,29 @@ class CleanError(Exception):
more descriptive exception types.
"""
def pretty_print(self, flush: bool = True, prefix: str = 'Error') -> None:
def pretty_print(
self,
flush: bool = True,
prefix: str = 'Error',
file: Any = None,
clr: type[ClrBase] | None = None,
) -> None:
"""Print the error to stdout, using red colored output if available.
If the error has an empty message, prints nothing (not even a newline).
"""
from efro.terminal import Clr
if clr is None:
clr = Clr
if prefix:
prefix = f'{prefix}: '
errstr = str(self)
if errstr:
print(f'{Clr.SRED}{prefix}{errstr}{Clr.RST}', flush=flush)
print(
f'{clr.SRED}{prefix}{errstr}{clr.RST}', flush=flush, file=file
)
class CommunicationError(Exception):

View file

@ -39,6 +39,12 @@ class _EmptyObj:
pass
# A dead weak-ref should be immutable, right? So we can create exactly
# one and return it for all cases that need an empty weak-ref.
_g_empty_weak_ref = weakref.ref(_EmptyObj())
assert _g_empty_weak_ref() is None
# TODO: kill this and just use efro.call.tpartial
if TYPE_CHECKING:
Call = Call
@ -148,8 +154,11 @@ def empty_weakref(objtype: type[T]) -> weakref.ref[T]:
# At runtime, all weakrefs are the same; our type arg is just
# for the static type checker.
del objtype # Unused.
# Just create an object and let it die. Is there a cleaner way to do this?
return weakref.ref(_EmptyObj()) # type: ignore
# return weakref.ref(_EmptyObj()) # type: ignore
return _g_empty_weak_ref # type: ignore
def data_size_str(bytecount: int) -> str: