Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Oct 15, 2024
1 parent 2a4b3a4 commit 6df377a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 12 additions & 4 deletions src/dipdup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
from dipdup._version import check_version
from dipdup.install import EPILOG
from dipdup.install import WELCOME_ASCII
from dipdup.report import REPORTS_PATH
from dipdup.report import cleanup_reports
from dipdup.report import get_reports
from dipdup.report import save_report
from dipdup.sys import set_up_process

if TYPE_CHECKING:
Expand Down Expand Up @@ -172,13 +168,17 @@ def wrapper(ctx: click.Context, *args: Any, **kwargs: Any) -> None:
except (KeyboardInterrupt, asyncio.CancelledError):
pass
except Exception as e:
from dipdup.report import save_report

package = ctx.obj.config.package if ctx.obj else 'unknown'
report_id = save_report(package, e)
_print_help_atexit(e, report_id)
raise e

# NOTE: If indexing was interrupted by signal, save report with just performance metrics.
if fn.__name__ == 'run' and not env.TEST:
from dipdup.report import save_report

package = ctx.obj.config.package
save_report(package, None)

Expand Down Expand Up @@ -969,6 +969,8 @@ async def self_env(ctx: click.Context) -> None:
@_cli_wrapper
async def report(ctx: click.Context) -> None:
"""Manage crash and performance reports."""
from dipdup.report import cleanup_reports

cleanup_reports()


Expand All @@ -979,6 +981,7 @@ async def report_ls(ctx: click.Context) -> None:
"""List reports."""
from tabulate import tabulate

from dipdup.report import get_reports
from dipdup.yaml import yaml_loader

header = ['id', 'date', 'package', 'reason']
Expand All @@ -1003,6 +1006,9 @@ async def report_ls(ctx: click.Context) -> None:
@_cli_wrapper
async def report_show(ctx: click.Context, id: str) -> None:
"""Show report."""
from dipdup.report import REPORTS_PATH
from dipdup.report import get_reports

if id == 'latest':
reports = get_reports()
if not reports:
Expand All @@ -1024,6 +1030,8 @@ async def report_show(ctx: click.Context, id: str) -> None:
@_cli_wrapper
async def report_rm(ctx: click.Context, id: str | None, all: bool) -> None:
"""Remove report(s)."""
from dipdup.report import REPORTS_PATH

if all and id:
echo('Please specify either name or --all')
return
Expand Down
5 changes: 2 additions & 3 deletions src/dipdup/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from pathlib import Path
from typing import Any

import orjson
from pydantic_core import to_jsonable_python

from dipdup import env

_futures: deque[asyncio.Future[None]] = deque()
Expand All @@ -21,6 +18,8 @@ def set_up_logging() -> None:
formatter: logging.Formatter

if env.JSON_LOG:
import orjson
from pydantic_core import to_jsonable_python
from pythonjsonlogger import jsonlogger

formatter = jsonlogger.JsonFormatter( # type: ignore[no-untyped-call]
Expand Down

0 comments on commit 6df377a

Please sign in to comment.