Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fmt_message = 'package source is invalid'
class PkgUpToDate(ManagerError):
fmt_message = 'package is up to date'
class PkgStrategyUnsupported(ManagerError):
fmt_message = '{self.strategy.name!r} strategy is not valid for source'
def __init__(self, strategy: Strategies) -> None:
super().__init__()
self.strategy = strategy
class InternalError(ManagerResult, Exception):
fmt_message = 'instawow encountered an error'
def __init__(self, error: Exception) -> None:
super().__init__()
self.error = error
def __init__(self, new_pkg: Pkg) -> None:
super().__init__()
self.new_pkg = new_pkg
class PkgUpdated(ManagerResult):
fmt_message = 'updated {self.old_pkg.version} to {self.new_pkg.version}'
def __init__(self, old_pkg: Pkg, new_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
self.new_pkg = new_pkg
class PkgRemoved(ManagerResult):
fmt_message = 'removed'
def __init__(self, old_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
class ManagerError(ManagerResult, Exception):
pass
class PkgAlreadyInstalled(ManagerError):
fmt_message = 'package already installed'
class PkgConflictsWithInstalled(ManagerError):
except ManagerError as error:
return error
except Exception as error:
logger.exception('error!')
return InternalError(error)
class PkgInstalled(ManagerResult):
fmt_message = 'installed {self.new_pkg.version}'
def __init__(self, new_pkg: Pkg) -> None:
super().__init__()
self.new_pkg = new_pkg
class PkgUpdated(ManagerResult):
fmt_message = 'updated {self.old_pkg.version} to {self.new_pkg.version}'
def __init__(self, old_pkg: Pkg, new_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
self.new_pkg = new_pkg
class PkgRemoved(ManagerResult):
fmt_message = 'removed'
def __init__(self, old_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
def __init__(self, old_pkg: Pkg, new_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
self.new_pkg = new_pkg
class PkgRemoved(ManagerResult):
fmt_message = 'removed'
def __init__(self, old_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
class ManagerError(ManagerResult, Exception):
pass
class PkgAlreadyInstalled(ManagerError):
fmt_message = 'package already installed'
class PkgConflictsWithInstalled(ManagerError):
fmt_message = 'package folders conflict with installed package {self.conflicts[0]}'
def __init__(self, conflicts: Sequence[Pkg]) -> None:
from .resolvers import Defn
super().__init__()
self.conflicts = [Defn.from_pkg(c) for c in conflicts]
async def install(self, defns: Sequence[Defn], replace: bool) -> Dict[Defn, E.ManagerResult]:
prelim_results = await self.resolve(
[d for d in defns if not self.get_pkg(d)], with_deps=True
)
# Weed out installed deps - this isn't super efficient but avoids
# having to deal with local state in the resolver
results = {d: r for d, r in prelim_results.items() if not self.get_pkg(d)}
installables = {(d, r): download_archive(self, r) for d, r in results.items() if is_pkg(r)}
archives = await gather(installables.values())
coros = dict_chain(
defns,
partial(_error_out, E.PkgAlreadyInstalled()),
((d, partial(_error_out, r)) for d, r in results.items()),
(
(d, partial(self.install_one, p, a, replace))
for (d, p), a in zip(installables, archives)
async def _consume_seq(
self, coros_by_defn: Dict[Defn, Callable[..., Awaitable[Any]]]
) -> Dict[Defn, E.ManagerResult]:
return {d: await E.ManagerResult.acapture(c()) for d, c in coros_by_defn.items()}
def message(self) -> str:
return self.fmt_message.format(self=self)
@staticmethod
async def acapture(awaitable: Awaitable[ManagerResult]) -> ManagerResult:
"Capture errors in coroutines."
try:
return await awaitable
except ManagerError as error:
return error
except Exception as error:
logger.exception('error!')
return InternalError(error)
class PkgInstalled(ManagerResult):
fmt_message = 'installed {self.new_pkg.version}'
def __init__(self, new_pkg: Pkg) -> None:
super().__init__()
self.new_pkg = new_pkg
class PkgUpdated(ManagerResult):
fmt_message = 'updated {self.old_pkg.version} to {self.new_pkg.version}'
def __init__(self, old_pkg: Pkg, new_pkg: Pkg) -> None:
super().__init__()
self.old_pkg = old_pkg
self.new_pkg = new_pkg