sagemath/sage

lazy_import: Muffle diagnostic messages for "at_startup"

mkoeppe opened this issue · 22 comments

When loading a modularized part of Sage instead of sage.all, we should suppress the second of these two messages:

        if startup_guard and not self._at_startup:
            print(f"Resolving lazy import {self._name} during startup")
        elif self._at_startup and not startup_guard:
            print(f"Option ``at_startup=True`` for lazy import {self._name} not needed anymore")

Also, instead of print, we should use warnings.warn.

Previous discussion:

CC: @tscrim @jhpalmieri @nthiery

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 4a8f409

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/32619

New commits:

7e7f5fesage.doctest.forker: Use sage.misc.lazy_import.ensure_startup_finished

Author: Matthias Koeppe

Commit: 7e7f5fe

Changed commit from 7e7f5fe to 181e4a0

Branch pushed to git repo; I updated commit sha1. New commits:

181e4a0src/sage/misc/lazy_import.pyx: Use warnings.warn instead of print
comment:5

Green bot => positive review.

Reviewer: Travis Scrimshaw

Changed commit from 181e4a0 to bc2b707

Branch pushed to git repo; I updated commit sha1. New commits:

bc2b707sage.misc.lazy_import.finish_startup: Fixup

Branch pushed to git repo; I updated commit sha1. New commits:

9830e4esrc/sage/misc/lazy_import.pyx: Adjust doctest output to use of warnings.warn

Changed commit from bc2b707 to 9830e4e

Branch pushed to git repo; I updated commit sha1. New commits:

dadfa07src/sage/misc/lazy_import.pyx: Fix markup of doctest output

Changed commit from 9830e4e to dadfa07

comment:11

There still is one doctest failure in misc/lazy_import.pyx.

Branch pushed to git repo; I updated commit sha1. New commits:

98d2e9bsrc/sage/misc/lazy_import.pyx: In test_fake_startup, also reset finish_startup_called

Changed commit from dadfa07 to 98d2e9b

Branch pushed to git repo; I updated commit sha1. New commits:

4a8f409src/sage/misc/lazy_import.pyx: Warnings suppress duplicates, so use a different import for the repeated test

Changed commit from 98d2e9b to 4a8f409

comment:16

LGTM.

comment:17

Thanks!